summaryrefslogtreecommitdiff
path: root/internal/config/read.go
diff options
context:
space:
mode:
authorPaul Bütow <pbuetow@mimecast.com>2020-01-20 18:41:05 +0000
committerPaul Bütow <pbuetow@mimecast.com>2020-01-21 14:35:23 +0000
commitc128865c4c7411c29a59fca9a3a2f95537686d7b (patch)
tree193bccc70d942c8b70cc93fae2670263701e43aa /internal/config/read.go
parent3755a9911ecb05886577095f2b8cc8b9e4066a3a (diff)
Move commands to cmd/ and move internal dependencies to internal/
Diffstat (limited to 'internal/config/read.go')
-rw-r--r--internal/config/read.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/config/read.go b/internal/config/read.go
new file mode 100644
index 0000000..a4e605b
--- /dev/null
+++ b/internal/config/read.go
@@ -0,0 +1,37 @@
+package config
+
+import (
+ "os"
+)
+
+// Read the DTail configuration.
+func Read(configFile string, sshPort int) {
+ initializer := configInitializer{
+ Common: newDefaultCommonConfig(),
+ Server: newDefaultServerConfig(),
+ Client: newDefaultClientConfig(),
+ }
+
+ if configFile == "" {
+ configFile = "./cfg/dtail.json"
+ }
+
+ if _, err := os.Stat(configFile); !os.IsNotExist(err) {
+ initializer.parseConfig(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
+
+ if Server.MapreduceLogFormat == "" {
+ Server.MapreduceLogFormat = "default"
+ }
+
+ // If non-standard port specified, overwrite config
+ if sshPort != 2222 {
+ Common.SSHPort = sshPort
+ }
+}