added livez
This commit is contained in:
parent
1656b91e3b
commit
690613cab8
2 changed files with 15 additions and 10 deletions
|
|
@ -18,8 +18,6 @@ type ContextData struct {
|
|||
}
|
||||
|
||||
func NewContext(w http.ResponseWriter, r *http.Request, data *ContextData, log logr.Logger) *Context {
|
||||
h := w.Header()
|
||||
h.Set("Content-Type", "application/json")
|
||||
return &Context{
|
||||
code: http.StatusOK,
|
||||
r: r,
|
||||
|
|
@ -110,13 +108,9 @@ func (c *Context) ReadBody() (b []byte, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (c *Context) Body(b []byte) {
|
||||
c.w.Write(b)
|
||||
c.log()
|
||||
}
|
||||
|
||||
// JSON is a json response
|
||||
func (c *Context) JSON(v any) {
|
||||
c.SetHeader("Content-Type", "application/json")
|
||||
err := json.NewEncoder(c.w).Encode(v)
|
||||
if err != nil {
|
||||
c.Err(ErrISE)
|
||||
|
|
@ -139,7 +133,9 @@ func (c *Context) Err(err Error) {
|
|||
// HTTPErr is a http.Error wrapper
|
||||
func (c *Context) HTTPErr(err string, code int) {
|
||||
c.code = code
|
||||
http.Error(c.w, err, code)
|
||||
c.SetHeader("Content-Type", "application/json")
|
||||
c.w.WriteHeader(code)
|
||||
c.w.Write([]byte(err))
|
||||
c.log()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue