MCPcopy Create free account
hub / github.com/Mirouterui/mirouter-ui / handleRouterAPI

Function handleRouterAPI

main.go:143–162  ·  view source on GitHub ↗
(routernum int, apipath string)

Source from the content-addressed store, hash-verified

141}
142
143func handleRouterAPI(routernum int, apipath string) (map[string]interface{}, error) {
144 ip := dev[routernum].IP
145 url := fmt.Sprintf("http://%s/cgi-bin/luci/;stok=%s/api/%s", ip, tokens[routernum], apipath)
146 resp, err := http.Get(url)
147 if err != nil {
148 return nil, fmt.Errorf("xiaomi router API call failed, please check configuration or router status")
149 }
150 defer resp.Body.Close()
151 body, _ := io.ReadAll(resp.Body)
152 var result map[string]interface{}
153 json.Unmarshal(body, &result)
154
155 if isLocals[routernum] && apipath == "/misystem/status" {
156 cpuPercent := GetCpuPercent()
157 if cpu, ok := result["cpu"].(map[string]interface{}); ok {
158 cpu["load"] = cpuPercent
159 }
160 }
161 return result, nil
162}
163
164func main() {
165 // starttime := int(time.Now().Unix())

Callers 1

mainFunction · 0.85

Calls 1

GetCpuPercentFunction · 0.70

Tested by

no test coverage detected