- Added upstream objects
- Renamed host templates to nginx templates - Generate upstream templates - Better nginx error reporting when reloading - Use tparse for golang test reporting
This commit is contained in:
backend
embed
internal
acme
api
config
entity
certificate
certificateauthority
dnsprovider
host
nginxtemplate
setting
stream
upstream
upstreamserver
user
nginx
status
util
validator
scripts
docker/rootfs/etc/nginx
frontend/src
scripts/ci
@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@ -45,13 +46,16 @@ func GetHost() func(http.ResponseWriter, *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
hostObject, err := host.GetByID(hostID)
|
||||
if err != nil {
|
||||
h.ResultErrorJSON(w, r, http.StatusBadRequest, err.Error(), nil)
|
||||
} else {
|
||||
item, err := host.GetByID(hostID)
|
||||
switch err {
|
||||
case sql.ErrNoRows:
|
||||
h.ResultErrorJSON(w, r, http.StatusNotFound, "Not found", nil)
|
||||
case nil:
|
||||
// nolint: errcheck,gosec
|
||||
hostObject.Expand(getExpandFromContext(r))
|
||||
h.ResultResponseJSON(w, r, http.StatusOK, hostObject)
|
||||
item.Expand(getExpandFromContext(r))
|
||||
h.ResultResponseJSON(w, r, http.StatusOK, item)
|
||||
default:
|
||||
h.ResultErrorJSON(w, r, http.StatusBadRequest, err.Error(), nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -111,6 +115,11 @@ func UpdateHost() func(http.ResponseWriter, *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = validator.ValidateHost(hostObject); err != nil {
|
||||
h.ResultErrorJSON(w, r, http.StatusBadRequest, err.Error(), nil)
|
||||
return
|
||||
}
|
||||
|
||||
if err = hostObject.Save(false); err != nil {
|
||||
h.ResultErrorJSON(w, r, http.StatusBadRequest, err.Error(), nil)
|
||||
return
|
||||
@ -137,11 +146,14 @@ func DeleteHost() func(http.ResponseWriter, *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
host, err := host.GetByID(hostID)
|
||||
if err != nil {
|
||||
item, err := host.GetByID(hostID)
|
||||
switch err {
|
||||
case sql.ErrNoRows:
|
||||
h.ResultErrorJSON(w, r, http.StatusNotFound, "Not found", nil)
|
||||
case nil:
|
||||
h.ResultResponseJSON(w, r, http.StatusOK, item.Delete())
|
||||
default:
|
||||
h.ResultErrorJSON(w, r, http.StatusBadRequest, err.Error(), nil)
|
||||
} else {
|
||||
h.ResultResponseJSON(w, r, http.StatusOK, host.Delete())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user