func getRouterList(w rest.ResponseWriter, r *rest.Request) { type RouterInfo struct { Rid string `json:"rid"` Rname string `json:"rname"` } type ResponseRouterList struct { Status int `json:"status"` Descr string `json:"descr"` List []RouterInfo `json:"list"` } resp := ResponseRouterList{} resp.Status = STATUS_OTHER_ERR r.ParseForm() uid := r.FormValue("uid") if uid == "" { resp.Status = STATUS_INVALID_PARAM resp.Descr = "missing 'uid'" w.WriteJson(resp) return } devices, err := devcenter.GetDevices(uid, devcenter.DEV_ROUTER) if err != nil { log.Errorf("GetDevices failed: %s", err.Error()) resp.Descr = err.Error() w.WriteJson(resp) return } for _, dev := range devices { router := RouterInfo{ Rid: dev.Id, Rname: dev.Title, } resp.List = append(resp.List, router) } resp.Status = 0 resp.Descr = "OK" w.WriteJson(resp) }
func checkAuthzUid(uid string, devid string) bool { // TODO: remove this is for test if uid == "000000000" { return true } devices, err := devcenter.GetDevices(uid, devcenter.DEV_ROUTER) if err != nil { log.Errorf("GetDevices failed: %s", err.Error()) return false } for _, dev := range devices { if devid == dev.Id { return true } } return false }