From d48611054ee60c18d1ba4e510fed844465fef17b Mon Sep 17 00:00:00 2001 From: Patrick Peng Sun Date: Thu, 13 Jul 2017 01:25:56 +1000 Subject: [PATCH] path config seperated to stand alone file. --- common_test.go | 2 +- config.go | 3 +++ configPath.go | 41 +++++++++++++++++++++++++++++++++++++++++ main.go | 19 ++++++------------- path_config.json | 5 +++++ 5 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 configPath.go create mode 100644 path_config.json diff --git a/common_test.go b/common_test.go index de9dc6c..6516af6 100644 --- a/common_test.go +++ b/common_test.go @@ -35,7 +35,7 @@ func SetupConfig() { IntraAPIConfig = ConfigIntraAPI{ "cAT/ckkfjajvczxiaufodqdfakpozcczfas341fda.vfasdk/8934125", } - GlobalPath = PathsConfig{"/tmp", "spa/"} + GlobalPath = PathsConfig{"/tmp", "spa/", "http://192.168.1.39:65500/"} KFUsers.kfRenewList() } diff --git a/config.go b/config.go index 4f7e65f..0c1a666 100644 --- a/config.go +++ b/config.go @@ -66,3 +66,6 @@ func getAesEncryptKey() [32]byte { copy(k[:], key) return k } + + + diff --git a/configPath.go b/configPath.go new file mode 100644 index 0000000..9d2cf56 --- /dev/null +++ b/configPath.go @@ -0,0 +1,41 @@ +package main + +import ( + "encoding/json" + "errors" + "io/ioutil" + "log" +) + +//PathsConfig all system available pathes +type PathsConfig struct { + Angular2App string `json:"angular2_app"` + SinglePageEdit string `json:"singlePageEdit"` + ThisSiteURL string `json:"thisSiteURL"` +} + +//GlobalPath all global pathes configurations +var GlobalPath = PathsConfig{} + +func (m *PathsConfig) readConfig() error { + log.Printf("read Path config from %s\r\n", "path_config.json") + body, err := ioutil.ReadFile("path_config.json") + if err != nil { + log.Fatal("Cannot read config from path_config.json") + return err + } + err = json.Unmarshal(body, m) + if m.SinglePageEdit == "" { + return errors.New("Single Page Edit Resources not available") + } + + if m.Angular2App == "" { + return errors.New("Angular2APP path not available") + } + + if m.ThisSiteURL == "" { + return errors.New("site url not available") + } + + return err +} diff --git a/main.go b/main.go index feb420f..94b6317 100644 --- a/main.go +++ b/main.go @@ -13,19 +13,6 @@ import ( "time" ) -//PathsConfig all system available pathes -type PathsConfig struct { - Angular2App string `json:"angular2_app"` - SinglePageEdit string `json:"singlePageEdit"` -} - -//GlobalPath all global pathes configurations -// TODO: setup GlobalPath Config, from reading file -var GlobalPath = PathsConfig{ - "dist/", - "spa/", -} - //KFUsers info cache about current customer service var KFUsers kfCache @@ -49,6 +36,12 @@ func main() { log.Fatal("unable to read intra-api-config, program quit") } + err = GlobalPath.readConfig() + if err != nil { + log.Println(err) + log.Fatal("unable to read globalPath, program quit") + } + initAllProc() setupRootFileServer() startSessionManager(2048) diff --git a/path_config.json b/path_config.json new file mode 100644 index 0000000..63a9f5a --- /dev/null +++ b/path_config.json @@ -0,0 +1,5 @@ +{ + "angular2_app" : "dist/", + "singlePageEdit" : "spa/", + "thisSiteURL" :"http://192.168.1.39:65500/" +} \ No newline at end of file