summaryrefslogtreecommitdiff
path: root/internal/config/setup.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-09-19 13:22:59 +0300
committerPaul Buetow <paul@buetow.org>2021-10-02 12:26:29 +0300
commitfe3e68afd99d8ea246be52893730f987e138ec24 (patch)
tree726e0914730912e0a3b223f7b37facc05ba31140 /internal/config/setup.go
parentabeac87aec44249bf67f1b0eca471a31086265ca (diff)
move args to config package
logger package rewrite as dlog
Diffstat (limited to 'internal/config/setup.go')
-rw-r--r--internal/config/setup.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/config/setup.go b/internal/config/setup.go
new file mode 100644
index 0000000..3c4bcc4
--- /dev/null
+++ b/internal/config/setup.go
@@ -0,0 +1,35 @@
+package config
+
+import (
+ "os"
+)
+
+const NoConfigFile string = "Don't read a config file - use defaults only"
+
+// Setup the DTail configuration.
+func Setup(args *Args, additionalArgs []string) {
+ initializer := configInitializer{
+ Common: newDefaultCommonConfig(),
+ Server: newDefaultServerConfig(),
+ Client: newDefaultClientConfig(),
+ }
+
+ if args.ConfigFile == "" {
+ // TODO: Search more paths for config file (e.g. in /etc and in ~/.config/...
+ args.ConfigFile = "./cfg/dtail.json"
+ }
+
+ if args.ConfigFile != NoConfigFile {
+ if _, err := os.Stat(args.ConfigFile); !os.IsNotExist(err) {
+ initializer.parseConfig(args.ConfigFile)
+ }
+ }
+
+ // Assign pointers to global variables, so that we can access the
+ // configuration from any place of the program.
+ Common = initializer.Common
+ Server = initializer.Server
+ Client = initializer.Client
+
+ args.transform(additionalArgs)
+}