mirror of
https://github.com/Luzifer/ots.git
synced 2024-10-01 01:06:09 -04:00
Handle json requests to create API
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
37a933907f
commit
b51293fe3d
18
api.go
18
api.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
@ -23,7 +24,22 @@ func (a apiServer) Register(r *mux.Router) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a apiServer) handleCreate(res http.ResponseWriter, r *http.Request) {
|
func (a apiServer) handleCreate(res http.ResponseWriter, r *http.Request) {
|
||||||
secret := r.FormValue("secret")
|
var secret string
|
||||||
|
|
||||||
|
if strings.HasPrefix(r.Header.Get("Content-Type"), "application/json") {
|
||||||
|
tmp := map[string]string{}
|
||||||
|
if err := json.NewDecoder(r.Body).Decode(&tmp); err != nil {
|
||||||
|
a.jsonResponse(res, http.StatusBadRequest, map[string]interface{}{
|
||||||
|
"success": false,
|
||||||
|
"error": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
secret = tmp["secret"]
|
||||||
|
} else {
|
||||||
|
secret = r.FormValue("secret")
|
||||||
|
}
|
||||||
|
|
||||||
if secret == "" {
|
if secret == "" {
|
||||||
a.jsonResponse(res, http.StatusBadRequest, map[string]interface{}{
|
a.jsonResponse(res, http.StatusBadRequest, map[string]interface{}{
|
||||||
"success": false,
|
"success": false,
|
||||||
|
Loading…
Reference in New Issue
Block a user