| import ( | import ( | ||||
| "encoding/base64" | "encoding/base64" | ||||
| "encoding/json" | "encoding/json" | ||||
| "errors" | |||||
| "io/ioutil" | "io/ioutil" | ||||
| "log" | "log" | ||||
| ) | ) | ||||
| //AppSecret is how we identify ourselves. | //AppSecret is how we identify ourselves. | ||||
| AppSecret string `json:"AppSecret"` | AppSecret string `json:"AppSecret"` | ||||
| //AuthTokenSaveTo | |||||
| AuthTokenSaveTo string `json:"AuthTokenSaveTo"` | |||||
| } | } | ||||
| //APIConfig contains secrets that cannot store in source file | //APIConfig contains secrets that cannot store in source file | ||||
| log.Printf("read config from %s\r\n", "server_config.json") | log.Printf("read 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") | |||||
| return err | 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 | //convert AesEncryptKey into Binary 32bytes |