Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
upliveapp committed Mar 30, 2019
1 parent 380d113 commit 36577d2
Showing 1 changed file with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.github.xincao9.jswitcher.api.service.SwitcherService;
import com.github.xincao9.jswitcher.api.vo.Switcher;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -66,10 +68,24 @@ public class SwitcherController {
*/
@GetMapping("keys")
public ResponseEntity<List<Map<String, Object>>> keys() {
try {
return ResponseEntity.ok(getKeys());
} catch (Throwable e) {
LOGGER.error(e.getMessage());
}
return ResponseEntity.status(500).build();
}

/**
* 获取开关列表
*
* @return 开关列表
*/
private List<Map<String, Object>> getKeys () {
try {
List<Endpoint> endpoints = discoveryService.query(SwitcherService.class.getTypeName());
if (endpoints == null || endpoints.isEmpty()) {
return ResponseEntity.status(400).build();
return Collections.EMPTY_LIST;
}
List<Map<String, Object>> keys = new ArrayList();
AtomicInteger no = new AtomicInteger(0);
Expand All @@ -86,7 +102,35 @@ public ResponseEntity<List<Map<String, Object>>> keys() {
keys.add(v0);
});
}
return ResponseEntity.ok(keys);
return keys;
} catch (Throwable e) {
LOGGER.error(e.getMessage());
}
return Collections.EMPTY_LIST;
}

/**
* 开关列表
*
* @return 开关
*/
@GetMapping("tree")
public ResponseEntity<Map<String, Map<String, List<Map<String, Object>>>>> tree() {
try {
List<Map<String, Object>> keys = getKeys();
Map<String, Map<String, List<Map<String, Object>>>> tree = new HashMap();
for (Map<String, Object> key : keys) {
String application = String.valueOf(key.get("application"));
if (!tree.containsKey(application)) {
tree.put(application, new HashMap());
}
String name = String.valueOf(key.get("key"));
if (!tree.get(application).containsKey(name)) {
tree.get(application).put(name, new ArrayList());
}
tree.get(application).get(name).add(key);
}
return ResponseEntity.ok(tree);
} catch (Throwable e) {
LOGGER.error(e.getMessage());
}
Expand Down

0 comments on commit 36577d2

Please sign in to comment.