Extend peer http endpoint (#94)

* feature: add peer GET and DELETE API methods

* refactor: extract peer business logic to a separate file

* refactor: extract peer business logic to a separate file

* feature: add peer update HTTP endpoint

* chore: fill peer new fields

* merge with main

* refactor: HTTP methods according to standards

* chore: setup keys POST endpoint without ID
This commit is contained in:
Mikhail Bragin
2021-08-23 21:43:05 +02:00
committed by GitHub
parent 6869b48905
commit 95845c88fe
8 changed files with 382 additions and 174 deletions

View File

@ -17,6 +17,17 @@ func extractAccountIdFromRequestContext(r *http.Request) string {
return claims["sub"].(string)
}
//writeJSONObject simply writes object to the HTTP reponse in JSON format
func writeJSONObject(w http.ResponseWriter, obj interface{}) {
w.WriteHeader(200)
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
err := json.NewEncoder(w).Encode(obj)
if err != nil {
http.Error(w, "failed handling request", http.StatusInternalServerError)
return
}
}
//Duration is used strictly for JSON requests/responses due to duration marshalling issues
type Duration struct {
time.Duration