package main import ( "encoding/json" "io/ioutil" "log" "time" ) const ROLE_CLIENT = "client" const ROLE_HOST = "host" var ( Logger *log.Logger configPath string LastUserId = 1000 parsecService *ParsecService TimeLocation *time.Location = time.FixedZone("CST", 8*3600) ) type ConfigData struct { LastUserId int `json:"lastUserId"` Users []*UserInfo `json:"users"` Peers []*PeerInfo `json:"peers"` Sessions []*SessionInfo `json:"sessions"` } func SaveConfig() { config := &ConfigData{ Users: parsecService.Users, Peers: parsecService.Peers, Sessions: parsecService.Sessions, LastUserId: LastUserId, } marshal, _ := json.Marshal(config) ioutil.WriteFile(configPath, marshal, 0777) } func ReadConfig() { b, _ := exists(configPath) if b { configData, _ := ioutil.ReadFile(configPath) var config *ConfigData json.Unmarshal(configData, &config) parsecService.LoadConfig(config) LastUserId = config.LastUserId } }