Notes/request_response.go

29 lines
507 B
Go
Raw Normal View History

2023-06-15 07:24:23 +02:00
package main
import (
// Standard
"encoding/json"
2023-06-15 14:12:35 +02:00
"net/http"
2023-06-15 07:24:23 +02:00
)
type Request struct {
ID string
}
2023-06-15 14:12:35 +02:00
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)
}