feat: add backend

This commit is contained in:
Ludvig Lundgren 2021-08-11 15:26:17 +02:00
parent bc418ff248
commit a838d994a6
68 changed files with 9561 additions and 0 deletions

26
internal/http/encoder.go Normal file
View file

@ -0,0 +1,26 @@
package http
import (
"context"
"encoding/json"
"net/http"
)
type encoder struct {
}
func (e encoder) StatusResponse(ctx context.Context, w http.ResponseWriter, response interface{}, status int) {
if response != nil {
w.Header().Set("Content-Type", "application/json; charset=utf=8")
w.WriteHeader(status)
if err := json.NewEncoder(w).Encode(response); err != nil {
// log err
}
} else {
w.WriteHeader(status)
}
}
func (e encoder) StatusNotFound(ctx context.Context, w http.ResponseWriter) {
w.WriteHeader(http.StatusNotFound)
}