// ProcessConfigFile processes a configuration file. // FIXME(dlc): Hacky func ProcessConfigFile(configFile string) (*Options, error) { opts := &Options{} if configFile == "" { return opts, nil } data, err := ioutil.ReadFile(configFile) if err != nil { return nil, fmt.Errorf("error opening config file: %v", err) } m, err := conf.Parse(string(data)) if err != nil { return nil, err } for k, v := range m { switch strings.ToLower(k) { case "port": opts.Port = int(v.(int64)) case "host", "net": opts.Host = v.(string) case "debug": opts.Debug = v.(bool) case "trace": opts.Trace = v.(bool) case "logtime": opts.Logtime = v.(bool) case "authorization": am := v.(map[string]interface{}) auth := parseAuthorization(am) opts.Username = auth.user opts.Password = auth.pass opts.AuthTimeout = auth.timeout case "http_port", "monitor_port": opts.HTTPPort = int(v.(int64)) case "cluster": cm := v.(map[string]interface{}) if err := parseCluster(cm, opts); err != nil { return nil, err } case "logfile", "log_file": opts.LogFile = v.(string) case "syslog": opts.Syslog = v.(bool) case "remote_syslog": opts.RemoteSyslog = v.(string) case "pidfile", "pid_file": opts.PidFile = v.(string) case "prof_port": opts.ProfPort = int(v.(int64)) } } return opts, nil }
// ProcessConfigFile processes a configuration file. // FIXME(dlc): Hacky func ProcessConfigFile(configFile string) (*Options, error) { opts := &Options{} if configFile == "" { return opts, nil } data, err := ioutil.ReadFile(configFile) if err != nil { return nil, fmt.Errorf("error opening config file: %v", err) } m, err := conf.Parse(string(data)) if err != nil { return nil, err } for k, v := range m { switch strings.ToLower(k) { case "port": opts.Port = int(v.(int64)) case "host", "net": opts.Host = v.(string) case "debug": opts.Debug = v.(bool) case "trace": opts.Trace = v.(bool) case "logtime": opts.Logtime = v.(bool) case "authorization": am := v.(map[string]interface{}) auth := parseAuthorization(am) opts.Username = auth.user opts.Password = auth.pass opts.AuthTimeout = auth.timeout case "http_port", "monitor_port": opts.HTTPPort = int(v.(int64)) case "https_port": opts.HTTPSPort = int(v.(int64)) case "cluster": cm := v.(map[string]interface{}) if err := parseCluster(cm, opts); err != nil { return nil, err } case "logfile", "log_file": opts.LogFile = v.(string) case "syslog": opts.Syslog = v.(bool) case "remote_syslog": opts.RemoteSyslog = v.(string) case "pidfile", "pid_file": opts.PidFile = v.(string) case "prof_port": opts.ProfPort = int(v.(int64)) case "max_control_line": opts.MaxControlLine = int(v.(int64)) case "max_payload": opts.MaxPayload = int(v.(int64)) case "max_pending_size", "max_pending": opts.MaxPending = int(v.(int64)) case "max_connections", "max_conn": opts.MaxConn = int(v.(int64)) case "ping_interval": opts.PingInterval = time.Duration(int(v.(int64))) case "ping_max": opts.MaxPingsOut = int(v.(int64)) case "tls": tlsm := v.(map[string]interface{}) tc, err := parseTLS(tlsm) if err != nil { return nil, err } if opts.TLSConfig, err = GenTLSConfig(tc); err != nil { return nil, err } opts.TLSTimeout = tc.Timeout } } return opts, nil }