diff options
author | KatolaZ <katolaz@freaknet.org> | 2017-07-13 07:55:44 +0100 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2017-07-13 07:55:44 +0100 |
commit | 00c61083d7139f19b8d99dfc7ac6d7e22c4f9a78 (patch) | |
tree | 942623175a650be1c98694e0f2e05640df49d9df /config.go | |
parent | b2b083e0597d3277f5dc075f4b17c89de51a77d0 (diff) |
master and worker initialisation (draft)
Diffstat (limited to 'config.go')
-rw-r--r-- | config.go | 23 |
1 files changed, 15 insertions, 8 deletions
@@ -20,9 +20,11 @@ func ReadGlobalConfig(fname string) *SCORSHmaster { log.Fatal("Error while reading file: ", err) } + var cfg *SCORSHmaster - cfg = new(SCORSHmaster) + cfg = new(SCORSHmaster) + // Unmarshal the YAML configuration file into a SCORSHcfg structure err = yaml.Unmarshal(data, cfg) if err != nil { @@ -30,27 +32,29 @@ func ReadGlobalConfig(fname string) *SCORSHmaster { } fmt.Printf("%s", cfg) - + // If the user has not set a spooldir, crash loudly if cfg.Spooldir == "" { log.Fatal("No spooldir defined in ", fname, ". Exiting\n") } // Check if the user has set a custom logprefix - if cfg.LogPrefix != "" { - log.SetPrefix(cfg.LogPrefix) - } // Check if the user wants to redirect the logs to a file if cfg.Logfile != "" { - f, err := os.Open(cfg.Logfile) + log.Printf("Opening log file: %s\n", cfg.Logfile) + f, err := os.OpenFile(cfg.Logfile, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0600) if err != nil { log.SetOutput(io.Writer(f)) } else { - log.Printf("Error opening logfile: \n", err) + log.Fatal("Error opening logfile: ", cfg.Logfile, err) } } + if cfg.LogPrefix != "" { + log.SetPrefix(cfg.LogPrefix) + } + // If we got so far, then there is some sort of config in cfg log.Printf("Successfully read config from %s\n", fname) @@ -58,7 +62,10 @@ func ReadGlobalConfig(fname string) *SCORSHmaster { } -func (cfg *SCORSHmaster_cfg) String() string { + + + +func (cfg *SCORSHmaster) String() string { var buff bytes.Buffer |