Adding error checks to REST calls
This commit is contained in:
parent
c263560401
commit
cfa232741d
1 changed files with 50 additions and 26 deletions
68
web.go
68
web.go
|
@ -83,55 +83,79 @@ func GetHealthHandler(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func GetBackendsHandler(rw http.ResponseWriter, r *http.Request) {
|
func GetBackendsHandler(rw http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
templatesRenderer.JSON(rw, http.StatusOK, currentConfigurations[vars["provider"]].Backends)
|
providerId := vars["provider"]
|
||||||
|
if provider, ok := currentConfigurations[providerId]; ok {
|
||||||
|
templatesRenderer.JSON(rw, http.StatusOK, provider.Backends)
|
||||||
|
} else {
|
||||||
|
http.NotFound(rw, r)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBackendHandler(rw http.ResponseWriter, r *http.Request) {
|
func GetBackendHandler(rw http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
id := vars["backend"]
|
providerId := vars["provider"]
|
||||||
if backend, ok := currentConfigurations[vars["provider"]].Backends[id]; ok {
|
backendId := vars["backend"]
|
||||||
|
if provider, ok := currentConfigurations[providerId]; ok {
|
||||||
|
if backend, ok := provider.Backends[backendId]; ok {
|
||||||
templatesRenderer.JSON(rw, http.StatusOK, backend)
|
templatesRenderer.JSON(rw, http.StatusOK, backend)
|
||||||
} else {
|
return
|
||||||
http.NotFound(rw, r)
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
http.NotFound(rw, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetFrontendsHandler(rw http.ResponseWriter, r *http.Request) {
|
func GetFrontendsHandler(rw http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
templatesRenderer.JSON(rw, http.StatusOK, currentConfigurations[vars["provider"]].Frontends)
|
providerId := vars["provider"]
|
||||||
|
if provider, ok := currentConfigurations[providerId]; ok {
|
||||||
|
templatesRenderer.JSON(rw, http.StatusOK, provider.Frontends)
|
||||||
|
} else {
|
||||||
|
http.NotFound(rw, r)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetFrontendHandler(rw http.ResponseWriter, r *http.Request) {
|
func GetFrontendHandler(rw http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
id := vars["frontend"]
|
providerId := vars["provider"]
|
||||||
if frontend, ok := currentConfigurations[vars["provider"]].Frontends[id]; ok {
|
frontendId := vars["frontend"]
|
||||||
|
if provider, ok := currentConfigurations[providerId]; ok {
|
||||||
|
if frontend, ok := provider.Frontends[frontendId]; ok {
|
||||||
templatesRenderer.JSON(rw, http.StatusOK, frontend)
|
templatesRenderer.JSON(rw, http.StatusOK, frontend)
|
||||||
} else {
|
return
|
||||||
http.NotFound(rw, r)
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
http.NotFound(rw, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetServersHandler(rw http.ResponseWriter, r *http.Request) {
|
func GetServersHandler(rw http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
backend := vars["backend"]
|
providerId := vars["provider"]
|
||||||
if backend, ok := currentConfigurations[vars["provider"]].Backends[backend]; ok {
|
backendId := vars["backend"]
|
||||||
|
if provider, ok := currentConfigurations[providerId]; ok {
|
||||||
|
if backend, ok := provider.Backends[backendId]; ok {
|
||||||
templatesRenderer.JSON(rw, http.StatusOK, backend.Servers)
|
templatesRenderer.JSON(rw, http.StatusOK, backend.Servers)
|
||||||
} else {
|
return
|
||||||
http.NotFound(rw, r)
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
http.NotFound(rw, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetServerHandler(rw http.ResponseWriter, r *http.Request) {
|
func GetServerHandler(rw http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
backend := vars["backend"]
|
providerId := vars["provider"]
|
||||||
server := vars["server"]
|
backendId := vars["backend"]
|
||||||
if backend, ok := currentConfigurations[vars["provider"]].Backends[backend]; ok {
|
serverId := vars["server"]
|
||||||
if server, ok := backend.Servers[server]; ok {
|
fmt.Printf("%v %v %v\n", providerId, backendId, serverId)
|
||||||
|
if provider, ok := currentConfigurations[providerId]; ok {
|
||||||
|
fmt.Printf("provider OK\n")
|
||||||
|
if backend, ok := provider.Backends[backendId]; ok {
|
||||||
|
fmt.Printf("backend OK\n")
|
||||||
|
if server, ok := backend.Servers[serverId]; ok {
|
||||||
|
fmt.Printf("server OK\n")
|
||||||
templatesRenderer.JSON(rw, http.StatusOK, server)
|
templatesRenderer.JSON(rw, http.StatusOK, server)
|
||||||
} else {
|
return
|
||||||
http.NotFound(rw, r)
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
http.NotFound(rw, r)
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
http.NotFound(rw, r)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue