diff --git a/config.go b/config.go index 5078701..c5114ba 100644 --- a/config.go +++ b/config.go @@ -3,6 +3,7 @@ package main import ( "encoding/base64" "encoding/json" + "errors" "io/ioutil" "log" ) @@ -20,6 +21,9 @@ type WechatAPIConfig struct { //AppSecret is how we identify ourselves. AppSecret string `json:"AppSecret"` + + //AuthTokenSaveTo + AuthTokenSaveTo string `json:"AuthTokenSaveTo"` } //APIConfig contains secrets that cannot store in source file @@ -30,9 +34,26 @@ func readConfig() error { log.Printf("read config from %s\r\n", "server_config.json") body, err := ioutil.ReadFile("server_config.json") if err != nil { + log.Fatal("Cannot read config from server_config.json") return err } - return json.Unmarshal(body, &APIConfig) + err = json.Unmarshal(body, &APIConfig) + if APIConfig.AppSecret == "" { + return errors.New("AppSecret not available") + } + if APIConfig.Appid == "" { + return errors.New("AppId not available") + } + if APIConfig.AuthTokenSaveTo == "" { + return errors.New("where to save accesstoken is unknown") + } + if APIConfig.EncodingAESKey == "" { + return errors.New("unknown AesEncryptionKey") + } + if APIConfig.Token == "" { + return errors.New("hidden shared secret token is empty") + } + return err } //convert AesEncryptKey into Binary 32bytes