24 lines
431 B
Go
24 lines
431 B
Go
|
package other
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
func HttpErr(w http.ResponseWriter, errId int, message string, code int) error {
|
||
|
type errStruct struct {
|
||
|
Id int `json:"id"`
|
||
|
Message string `json:"message"`
|
||
|
}
|
||
|
|
||
|
data, err := json.Marshal(errStruct{errId, message})
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
w.WriteHeader(code)
|
||
|
w.Header().Add("Content-Type", "application/json")
|
||
|
fmt.Fprint(w, data)
|
||
|
return nil
|
||
|
}
|