Fixing CEO's bugs

This commit is contained in:
Ken Robertson
2013-04-22 13:52:45 -07:00
parent c6dcc8e945
commit 2bdb873426
3 changed files with 13 additions and 9 deletions

View File

@@ -45,15 +45,19 @@ func main() {
opts.Trace, opts.Debug = true, true
}
var fileOpts *Options
var fileOpts *server.Options
var err error
// Parse config if given
if configFile != "" {
fileOpts = server.processConfigFile(configFile)
fileOpts, err = server.ProcessConfigFile(configFile)
if err != nil {
panic(err)
}
}
// Create the server with appropriate options.
s := server.New(server.mergeOptions(fileOpts, &opts))
s := server.New(server.MergeOptions(fileOpts, &opts))
// Start up the http server if needed.
if opts.HttpPort != 0 {

View File

@@ -32,7 +32,7 @@ type Options struct {
}
// FIXME(dlc): Hacky
func processConfigFile(configFile string) (*Options, error) {
func ProcessConfigFile(configFile string) (*Options, error) {
opts := &Options{}
if configFile == "" {
@@ -86,7 +86,7 @@ func processConfigFile(configFile string) (*Options, error) {
}
// Will merge two options giving preference to the flagOpts if the item is present.
func mergeOptions(fileOpts, flagOpts *Options) *Options {
func MergeOptions(fileOpts, flagOpts *Options) *Options {
if fileOpts == nil {
return flagOpts
}

View File

@@ -41,7 +41,7 @@ func TestConfigFile(t *testing.T) {
Logtime: false,
}
opts, err := processConfigFile("./configs/test.conf")
opts, err := ProcessConfigFile("./configs/test.conf")
if err != nil {
t.Fatalf("Received an error reading config file: %v\n", err)
}
@@ -62,7 +62,7 @@ func TestMergeOverrides(t *testing.T) {
Trace: true,
Logtime: false,
}
fopts, err := processConfigFile("./configs/test.conf")
fopts, err := ProcessConfigFile("./configs/test.conf")
if err != nil {
t.Fatalf("Received an error reading config file: %v\n", err)
}
@@ -73,8 +73,8 @@ func TestMergeOverrides(t *testing.T) {
Password: "spooky",
Debug: true,
}
merged := mergeOptions(fopts, opts)
merged := MergeOptions(fopts, opts)
if !reflect.DeepEqual(golden, merged) {
t.Fatal("Options are incorrect from config file")
}
}
}