Marshal /update response too

This commit is contained in:
tcely 2019-03-04 06:31:52 -05:00 committed by GitHub
parent 43de7ba39c
commit d2bc627429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

14
api.go
View File

@ -71,6 +71,12 @@ func webRegisterPost(w http.ResponseWriter, r *http.Request, _ httprouter.Params
w.Write(reg)
}
// UpdateResponse is a struct for update response JSON
type UpdateResponse struct {
TextValue string `json:"txt"`
Fulldomain string `json:"fulldomain"`
}
func webUpdatePost(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
var updStatus int
var upd []byte
@ -99,7 +105,13 @@ func webUpdatePost(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
} else {
log.WithFields(log.Fields{"subdomain": a.Subdomain, "txt": a.Value}).Debug("TXT updated")
updStatus = http.StatusOK
upd = []byte("{\"txt\": \"" + a.Value + "\", \"fulldomain\": \"" + a.Subdomain + "." + Config.General.Domain + "\"}")
updStruct := UpdateResponse{a.Value, a.Subdomain + "." + Config.General.Domain}
upd, err = json.Marshal(updStruct)
if err != nil {
updStatus = http.StatusInternalServerError
upd = jsonError("json_error")
log.WithFields(log.Fields{"error": "json"}).Debug("Could not marshal JSON")
}
}
}
w.Header().Set("Content-Type", "application/json")