mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
26 lines
553 B
Go
26 lines
553 B
Go
package http
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
type encoder struct {
|
|
}
|
|
|
|
func (e encoder) StatusResponse(ctx context.Context, w http.ResponseWriter, response interface{}, status int) {
|
|
if response != nil {
|
|
w.Header().Set("Content-Type", "application/json; charset=utf=8")
|
|
w.WriteHeader(status)
|
|
if err := json.NewEncoder(w).Encode(response); err != nil {
|
|
// log err
|
|
}
|
|
} else {
|
|
w.WriteHeader(status)
|
|
}
|
|
}
|
|
|
|
func (e encoder) StatusNotFound(ctx context.Context, w http.ResponseWriter) {
|
|
w.WriteHeader(http.StatusNotFound)
|
|
}
|