| 32 | } |
| 33 | |
| 34 | func LoadServerConfig(filename string, cfg *Connect.ServerConfig) bool { |
| 35 | |
| 36 | Server_file_locker.Lock() |
| 37 | data, err := io.ReadFile(filename) //read config file |
| 38 | Server_file_locker.Unlock() |
| 39 | if err != nil { |
| 40 | log.Printf("read json file error,%s\n", err.Error()) |
| 41 | return false |
| 42 | } |
| 43 | // Unmarshal对于结构体偏向于精确匹配,也接收不精确匹配 |
| 44 | err = json.Unmarshal(data, &cfg) |
| 45 | // 太扯了 不加双引号解不出数组 |
| 46 | // fmt.Printf("DEBUG : data %s : %s : %s : %s\n",data, cfg.SnapshotFileName, cfg.RaftstateFileName,cfg.PersistenceStrategy) |
| 47 | if err != nil { |
| 48 | log.Println("unmarshal json file error") |
| 49 | return false |
| 50 | } |
| 51 | return true |
| 52 | } |