Refactor setting writer Location header
Signed-off-by: Jared Scheib <jared.scheib@gmail.com>pull/2099/head
parent
40fac47b28
commit
04a9af37f3
|
@ -104,7 +104,7 @@ func (s *Service) NewDashboard(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
res := newDashboardResponse(dashboard)
|
||||
w.Header().Add("Location", res.Links.Self)
|
||||
location(w, res.Links.Self)
|
||||
encodeJSON(w, http.StatusCreated, res, s.Logger)
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package server
|
||||
|
||||
import "net/http"
|
||||
|
||||
func location(w http.ResponseWriter, self string) {
|
||||
w.Header().Add("Location", self)
|
||||
}
|
|
@ -94,7 +94,7 @@ func (s *Service) NewKapacitor(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
res := newKapacitor(srv)
|
||||
w.Header().Add("Location", res.Links.Self)
|
||||
location(w, res.Links.Self)
|
||||
encodeJSON(w, http.StatusCreated, res, s.Logger)
|
||||
}
|
||||
|
||||
|
@ -324,7 +324,7 @@ func (s *Service) KapacitorRulesPost(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
res := newAlertResponse(task, srv.SrcID, srv.ID)
|
||||
w.Header().Add("Location", res.Links.Self)
|
||||
location(w, res.Links.Self)
|
||||
encodeJSON(w, http.StatusCreated, res, s.Logger)
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ func (s *Service) NewLayout(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
res := newLayoutResponse(layout)
|
||||
w.Header().Add("Location", res.Link.Href)
|
||||
location(w, res.Link.Href)
|
||||
encodeJSON(w, http.StatusCreated, res, s.Logger)
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ func (s *Service) NewRole(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
rr := newRoleResponse(srcID, res)
|
||||
w.Header().Add("Location", rr.Links.Self)
|
||||
location(w, rr.Links.Self)
|
||||
encodeJSON(w, http.StatusCreated, rr, s.Logger)
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ func (s *Service) UpdateRole(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
rr := newRoleResponse(srcID, role)
|
||||
w.Header().Add("Location", rr.Links.Self)
|
||||
location(w, rr.Links.Self)
|
||||
encodeJSON(w, http.StatusOK, rr, s.Logger)
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ func (s *Service) NewSource(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
res := newSourceResponse(src)
|
||||
w.Header().Add("Location", res.Links.Self)
|
||||
location(w, res.Links.Self)
|
||||
encodeJSON(w, http.StatusCreated, res, s.Logger)
|
||||
}
|
||||
|
||||
|
@ -405,7 +405,7 @@ func (s *Service) NewSourceUser(w http.ResponseWriter, r *http.Request) {
|
|||
if _, hasRoles := s.hasRoles(ctx, ts); hasRoles {
|
||||
su.WithRoles(srcID, res.Roles)
|
||||
}
|
||||
w.Header().Add("Location", su.Links.Self)
|
||||
location(w, su.Links.Self)
|
||||
encodeJSON(w, http.StatusCreated, su, s.Logger)
|
||||
}
|
||||
|
||||
|
@ -524,7 +524,7 @@ func (s *Service) UpdateSourceUser(w http.ResponseWriter, r *http.Request) {
|
|||
if _, hasRoles := s.hasRoles(ctx, ts); hasRoles {
|
||||
res.WithRoles(srcID, u.Roles)
|
||||
}
|
||||
w.Header().Add("Location", res.Links.Self)
|
||||
location(w, res.Links.Self)
|
||||
encodeJSON(w, http.StatusOK, res, s.Logger)
|
||||
}
|
||||
|
||||
|
|
|
@ -197,7 +197,3 @@ func (s *Service) Users(w http.ResponseWriter, r *http.Request) {
|
|||
res := newUsersResponse(users)
|
||||
encodeJSON(w, http.StatusOK, res, s.Logger)
|
||||
}
|
||||
|
||||
func location(w http.ResponseWriter, self string) {
|
||||
w.Header().Add("Location", self)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue