From 8d07c1eb3ecd9b125b222fedbe644a77c53f43e5 Mon Sep 17 00:00:00 2001 From: Dreamacro <305009791@qq.com> Date: Tue, 18 Feb 2020 13:48:15 +0800 Subject: [PATCH] Chore: initial config with `port` --- config/initial.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/config/initial.go b/config/initial.go index e151e74c..09b2e4f3 100644 --- a/config/initial.go +++ b/config/initial.go @@ -38,15 +38,19 @@ func Init(dir string) error { // initial config.yaml if _, err := os.Stat(C.Path.Config()); os.IsNotExist(err) { - log.Infoln("Can't find config, create an empty file") - os.OpenFile(C.Path.Config(), os.O_CREATE|os.O_WRONLY, 0644) + log.Infoln("Can't find config, create a initial config file") + f, err := os.OpenFile(C.Path.Config(), os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + return fmt.Errorf("Can't create file %s: %s", C.Path.Config(), err.Error()) + } + f.Write([]byte(`port: 7890`)) + f.Close() } // initial mmdb if _, err := os.Stat(C.Path.MMDB()); os.IsNotExist(err) { log.Infoln("Can't find MMDB, start download") - err := downloadMMDB(C.Path.MMDB()) - if err != nil { + if err := downloadMMDB(C.Path.MMDB()); err != nil { return fmt.Errorf("Can't download MMDB: %s", err.Error()) } }