Skip to content

Commit

Permalink
Fix issue read config file error.
Browse files Browse the repository at this point in the history
  • Loading branch information
xuri committed Jan 7, 2017
1 parent a147f07 commit 9899f22
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ install:
- go get github.com/BurntSushi/toml
- go get github.com/rakyll/statik
- go get github.com/rakyll/statik/fs
- go get github.com/kr/beanstalk
- go get -d -t -v ./... && go build -v ./...

before_script:
Expand Down
2 changes: 1 addition & 1 deletion structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
selfConf SelfConf
Stderr io.Writer = os.Stderr // Stderr is the io.Writer to which executed commands write standard error.
Stdout io.Writer = os.Stdout // Stdout is the io.Writer to which executed commands write standard output.
ConfigFile = `.` + string(os.PathSeparator) + `aurora.toml`
ConfigFile = `aurora.toml`
statisticsData = StatisticsData{new(sync.RWMutex), statisticsDataServer}
statisticsDataServer = make(map[string]map[string]map[string]*list.List)
notify = make(chan bool, 1)
Expand Down
12 changes: 6 additions & 6 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ import (
// readConf read external config file when program startup.
func readConf() error {
buf := new(bytes.Buffer)
selfDir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return err
}
if _, err := os.Stat(ConfigFile); os.IsNotExist(err) {
err := ioutil.WriteFile(selfDir+string(os.PathSeparator)+ConfigFile, []byte(ConfigFileTemplate), 0644)
err := ioutil.WriteFile(ConfigFile, []byte(ConfigFileTemplate), 0644)
if err != nil {
return err
}
Expand Down Expand Up @@ -152,7 +148,11 @@ func parseFlags() {
helpPtr := flag.Bool("h", false, "Output this help and exit.")
flag.Parse()
if *configPtr == "" {
ConfigFile = `.` + string(os.PathSeparator) + `aurora.toml`
selfDir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
os.Exit(0)
}
ConfigFile = selfDir + string(os.PathSeparator) + `aurora.toml`
} else {
ConfigFile = *configPtr
}
Expand Down

0 comments on commit 9899f22

Please sign in to comment.