(d map[string]interface{})
| 251 | } |
| 252 | |
| 253 | func (t *cmdAdmin) handleConfigConvert(d map[string]interface{}) { |
| 254 | defer func() { |
| 255 | if x := recover(); x != nil { |
| 256 | log.Panicf("convert config failed: %+v", x) |
| 257 | } |
| 258 | }() |
| 259 | |
| 260 | cfg1 := t.loadJsonConfigV1(utils.ArgumentMust(d, "--config-convert")) |
| 261 | cfg2 := &ConfigV3{} |
| 262 | |
| 263 | if slots := cfg1["slots"]; slots != nil { |
| 264 | temp := make(map[int]*models.SlotMapping) |
| 265 | for _, v := range slots.(map[string]interface{}) { |
| 266 | t.convertSlotsV1(temp, v) |
| 267 | } |
| 268 | for i := 0; i < models.MaxSlotNum; i++ { |
| 269 | if temp[i] == nil { |
| 270 | continue |
| 271 | } |
| 272 | cfg2.Slots = append(cfg2.Slots, temp[i]) |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | if servers := cfg1["servers"]; servers != nil { |
| 277 | group := make(map[int]*models.Group) |
| 278 | for _, g := range servers.(map[string]interface{}) { |
| 279 | for _, v := range g.(map[string]interface{}) { |
| 280 | t.convertGroupV1(group, v) |
| 281 | } |
| 282 | } |
| 283 | cfg2.Group = models.SortGroup(group) |
| 284 | } |
| 285 | |
| 286 | b, err := json.MarshalIndent(cfg2, "", " ") |
| 287 | if err != nil { |
| 288 | log.PanicErrorf(err, "json marshal failed") |
| 289 | } |
| 290 | fmt.Println(string(b)) |
| 291 | } |
| 292 | |
| 293 | func (t *cmdAdmin) loadJsonConfigV3(file string) *ConfigV3 { |
| 294 | b, err := ioutil.ReadFile(file) |
no test coverage detected