Notes/request_response.go
Magnus Åhall b8a673fb0a Session
2023-06-15 14:12:35 +02:00

29 lines
507 B
Go

package main
import (
// Standard
"encoding/json"
"net/http"
)
type Request struct {
ID string
}
func responseError(w http.ResponseWriter, err error) {
res := map[string]interface{}{
"ok": false,
"error": err.Error(),
}
resJSON, _ := json.Marshal(res)
w.Header().Add("Content-Type", "application/json")
w.Write(resJSON)
}
func responseData(w http.ResponseWriter, data interface{}) {
resJSON, _ := json.Marshal(data)
w.Header().Add("Content-Type", "application/json")
w.Write(resJSON)
}