package errorhandlers import ( "encoding/json" "fmt" "net/http" "os" "gitea.futuresens.co.uk/futuresens/cmstypes" log "github.com/sirupsen/logrus" ) const serviceName = "hardlink" // writeError is a helper to send a JSON error and HTTP status in one go. func WriteError(w http.ResponseWriter, status int, msg string) { theResponse := cmstypes.StatusRec{ Code: status, Message: msg, } w.Header().Set("Content-Type", "application/json") w.WriteHeader(status) json.NewEncoder(w).Encode(theResponse) } func FatalError(err error) { fmt.Println(err.Error()) log.Errorf(err.Error()) fmt.Println(". Press Enter to exit...") fmt.Scanln() os.Exit(1) }