You've already forked filebrowser
mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-11-26 14:25:26 +08:00
[ci skip] updates on restructuring stuff
This commit is contained in:
@@ -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