Restructure all http related files

Moving all http related functions and helpers into a new http submodule
This commit is contained in:
Melody Becker 2025-03-04 13:56:57 +01:00
parent 0a0c185c06
commit 18bf623114
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
4 changed files with 4 additions and 4 deletions

16
http/httpErr.go Normal file
View file

@ -0,0 +1,16 @@
package http
import (
"fmt"
"net/http"
)
// Return an error over an http connection.
// The error will have the given return code `code`
// and a json encoded body with the field "id" set to `errId`
// and a field "message" set to the `message`
func HttpErr(w http.ResponseWriter, errId int, message string, code int) {
w.WriteHeader(code)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, "{\"id\": %d, \"message\": \"%s\"}", errId, message)
}