Commit 25a5bc0b by Iwasaki Yudai

Fix default config file loading

1 parent 8e90497c
Showing with 8 additions and 6 deletions
...@@ -106,7 +106,7 @@ func ApplyConfigFile(options *Options, configFilePath string) error { ...@@ -106,7 +106,7 @@ func ApplyConfigFile(options *Options, configFilePath string) error {
} }
func applyConfigFile(options *Options, filePath string) error { func applyConfigFile(options *Options, filePath string) error {
filePath = expandHomeDir(filePath) filePath = ExpandHomeDir(filePath)
if _, err := os.Stat(filePath); os.IsNotExist(err) { if _, err := os.Stat(filePath); os.IsNotExist(err) {
return err return err
} }
...@@ -138,7 +138,7 @@ func applyConfigFile(options *Options, filePath string) error { ...@@ -138,7 +138,7 @@ func applyConfigFile(options *Options, filePath string) error {
return nil return nil
} }
func expandHomeDir(path string) string { func ExpandHomeDir(path string) string {
if path[0:2] == "~/" { if path[0:2] == "~/" {
return os.Getenv("HOME") + path[1:] return os.Getenv("HOME") + path[1:]
} else { } else {
...@@ -234,8 +234,8 @@ func (app *App) Run() error { ...@@ -234,8 +234,8 @@ func (app *App) Run() error {
) )
if app.options.EnableTLS { if app.options.EnableTLS {
err = app.server.ListenAndServeTLS( err = app.server.ListenAndServeTLS(
expandHomeDir(app.options.TLSCrtFile), ExpandHomeDir(app.options.TLSCrtFile),
expandHomeDir(app.options.TLSKeyFile), ExpandHomeDir(app.options.TLSKeyFile),
) )
} else { } else {
err = app.server.ListenAndServe() err = app.server.ListenAndServe()
......
...@@ -69,7 +69,7 @@ func main() { ...@@ -69,7 +69,7 @@ func main() {
options := app.DefaultOptions options := app.DefaultOptions
configFile := c.String("config") configFile := c.String("config")
_, err := os.Stat(configFile) _, err := os.Stat(app.ExpandHomeDir(configFile))
if configFile != "~/.gotty" || !os.IsNotExist(err) { if configFile != "~/.gotty" || !os.IsNotExist(err) {
if err := app.ApplyConfigFile(&options, configFile); err != nil { if err := app.ApplyConfigFile(&options, configFile); err != nil {
exit(err, 2) exit(err, 2)
...@@ -101,7 +101,9 @@ func main() { ...@@ -101,7 +101,9 @@ func main() {
} }
func exit(err error, code int) { func exit(err error, code int) {
fmt.Println(err) if err != nil {
fmt.Println(err)
}
os.Exit(code) os.Exit(code)
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!