| //APIConfig contains secrets that cannot store in source file | //APIConfig contains secrets that cannot store in source file | ||||
| var APIConfig WechatAPIConfig | var APIConfig WechatAPIConfig | ||||
| type EspoCRMAPIConfig struct { | |||||
| //where the EspoCRM is installed | |||||
| BaseURL string `json:"BaseURL"` | |||||
| //access UserName | |||||
| UserName string `json:"UserName"` | |||||
| //access Password | |||||
| UserPass string `json:"password"` | |||||
| } | |||||
| //CRMConfig contains secrets that cannot store in source file | |||||
| // | |||||
| var CRMConfig EspoCRMAPIConfig | |||||
| func readConfig() error { | func readConfig() error { | ||||
| log.Printf("read config from %s\r\n", "server_config.json") | |||||
| log.Printf("read Wechat API config from %s\r\n", "server_config.json") | |||||
| body, err := ioutil.ReadFile("server_config.json") | body, err := ioutil.ReadFile("server_config.json") | ||||
| if err != nil { | if err != nil { | ||||
| log.Fatal("Cannot read config from server_config.json") | log.Fatal("Cannot read config from server_config.json") |
| package main | |||||
| import ( | |||||
| "encoding/json" | |||||
| "errors" | |||||
| "io/ioutil" | |||||
| "log" | |||||
| ) | |||||
| //EspoCRMAPIConfig CRM configuration for API accessing | |||||
| type EspoCRMAPIConfig struct { | |||||
| //where the EspoCRM is installed | |||||
| BaseURL string `json:"BaseURL"` | |||||
| //access UserName | |||||
| UserName string `json:"UserName"` | |||||
| //access Password | |||||
| UserPass string `json:"UserPass"` | |||||
| } | |||||
| //CRMConfig contains secrets that cannot store in source file | |||||
| // | |||||
| var CRMConfig EspoCRMAPIConfig | |||||
| func readCRMConfig() error { | |||||
| log.Printf("read CRM config from %s\r\n", "crm_config.json") | |||||
| body, err := ioutil.ReadFile("crm_config.json") | |||||
| if err != nil { | |||||
| log.Fatal("Cannot read config from crm_config.json") | |||||
| return err | |||||
| } | |||||
| err = json.Unmarshal(body, &CRMConfig) | |||||
| if CRMConfig.BaseURL == "" { | |||||
| return errors.New("CRM BaseURL not available not available") | |||||
| } | |||||
| if CRMConfig.UserName == "" { | |||||
| return errors.New("CRM UserName not available not available") | |||||
| } | |||||
| if CRMConfig.UserPass == "" { | |||||
| return errors.New("CRM UserPass not available not available") | |||||
| } | |||||
| return err | |||||
| } |
| { | |||||
| "BaseURL": "https://crm.hitxy.org.au/", | |||||
| "UserName": "wechat", | |||||
| "UserPass": "crmwechat.api" | |||||
| } |
| ) | ) | ||||
| func main() { | func main() { | ||||
| if readConfig() != nil { | |||||
| log.Fatal("unable to read config, program quit") | |||||
| err := readConfig() //wechat API config | |||||
| if err != nil { | |||||
| log.Println(err) | |||||
| log.Fatal("unable to read server_config.json, program quit") | |||||
| return | return | ||||
| } | } | ||||
| err = readCRMConfig() | |||||
| if err != nil { | |||||
| log.Println(err) | |||||
| log.Fatal("unable to read crm_config.json, program quit") | |||||
| } | |||||
| //fs := http.FileServer(http.Dir("/mnt/data/workspace/angular.ts/ng2-admin/dist")) | //fs := http.FileServer(http.Dir("/mnt/data/workspace/angular.ts/ng2-admin/dist")) | ||||
| fs := http.FileServer(http.Dir("/mnt/data/workspace/angular.ts/wechat/ng2-admin/dist")) | fs := http.FileServer(http.Dir("/mnt/data/workspace/angular.ts/wechat/ng2-admin/dist")) | ||||