mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-16 23:20:12 +01:00
feat(api): implement new api handler
This commit is contained in:
parent
72e437f173
commit
47091761a5
17 changed files with 571 additions and 294 deletions
41
pkg/api/prelude/response.go
Normal file
41
pkg/api/prelude/response.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package prelude
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Body any
|
||||
Status int
|
||||
Raw bool
|
||||
}
|
||||
|
||||
func (r *Response) Bytes() ([]byte, error) {
|
||||
if bytes, raw := r.Body.([]byte); raw {
|
||||
return bytes, nil
|
||||
}
|
||||
|
||||
if str, raw := r.Body.(string); raw {
|
||||
return []byte(str), nil
|
||||
}
|
||||
|
||||
return json.MarshalIndent(r.Body, "", " ")
|
||||
}
|
||||
|
||||
var localLog = log.WithField("notify", "no")
|
||||
|
||||
func OK(body any) Response {
|
||||
return Response{
|
||||
Status: http.StatusOK,
|
||||
Body: body,
|
||||
}
|
||||
}
|
||||
|
||||
func Error(err errorResponse) Response {
|
||||
return Response{
|
||||
Status: err.Status,
|
||||
Body: err,
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue