init: first steps
This commit is contained in:
19
pkg/http/response.go
Normal file
19
pkg/http/response.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func JSON(w http.ResponseWriter, i any, httpCode int) error {
|
||||
response, err := json.Marshal(i)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(httpCode)
|
||||
_, err = w.Write(response)
|
||||
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user