[ci skip] updates on restructuring stuff
This commit is contained in:
1 parent
b97ef80596
commit
e33c79224f
9 files changed
+127
-84
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
@@ -236,3 +237,28 @@ func SplitCapitalize(name string) string {
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
type jsonMSG struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func RespondJSON(w http.ResponseWriter, message string, code int, err error) (int, error) {
|
||||
msg := &jsonMSG{
|
||||
Message: message,
|
||||
}
|
||||
|
||||
m, err := json.Marshal(msg)
|
||||
|
||||
if err != nil {
|
||||
return 500, err
|
||||
}
|
||||
|
||||
if code == 500 && err == nil {
|
||||
err = errors.New(message)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(code)
|
||||
w.Write(m)
|
||||
return 0, err
|
||||
}
|
||||
Reference in new issue
Block a user