fix linter errors

This commit is contained in:
Hayden 2022-10-28 17:29:51 -08:00
parent 57305996eb
commit 666269a190
9 changed files with 11 additions and 31 deletions

View file

@ -42,8 +42,6 @@ func (ctrl *V1Controller) HandleAuthLogin() server.HandlerFunc {
err := r.ParseForm()
if err != nil {
return server.Respond(w, http.StatusBadRequest, server.Wrap(err))
log.Error().Err(err).Msg("failed to parse form")
return nil
}
loginForm.Username = r.PostFormValue("username")
@ -53,12 +51,9 @@ func (ctrl *V1Controller) HandleAuthLogin() server.HandlerFunc {
if err != nil {
log.Err(err).Msg("failed to decode login form")
return server.Respond(w, http.StatusBadRequest, server.Wrap(err))
return nil
}
default:
return server.Respond(w, http.StatusBadRequest, errors.New("invalid content type"))
return nil
}
if loginForm.Username == "" || loginForm.Password == "" {

View file

@ -139,6 +139,7 @@ func (ctrl *V1Controller) handleItemsGeneral() server.HandlerFunc {
ctx := services.NewContext(r.Context())
ID, err := ctrl.routeID(w, r)
if err != nil {
return err
}
switch r.Method {

View file

@ -73,6 +73,7 @@ func (ctrl *V1Controller) HandleItemAttachmentCreate() server.HandlerFunc {
id, err := ctrl.routeID(w, r)
if err != nil {
return err
}
ctx := services.NewContext(r.Context())
@ -162,6 +163,7 @@ func (ctrl *V1Controller) HandleItemAttachmentUpdate() server.HandlerFunc {
func (ctrl *V1Controller) handleItemAttachmentsHandler(w http.ResponseWriter, r *http.Request) error {
ID, err := ctrl.routeID(w, r)
if err != nil {
return err
}
attachmentId, err := uuid.Parse(chi.URLParam(r, "attachment_id"))

View file

@ -98,6 +98,7 @@ func (ctrl *V1Controller) handleLabelsGeneral() server.HandlerFunc {
ctx := services.NewContext(r.Context())
ID, err := ctrl.routeID(w, r)
if err != nil {
return err
}
switch r.Method {

View file

@ -100,6 +100,7 @@ func (ctrl *V1Controller) handleLocationGeneral() server.HandlerFunc {
ctx := services.NewContext(r.Context())
ID, err := ctrl.routeID(w, r)
if err != nil {
return err
}
switch r.Method {

View file

@ -10,7 +10,6 @@ import (
"path"
"path/filepath"
"github.com/go-chi/chi/v5"
"github.com/hay-kot/homebox/backend/app/api/handlers/debughandlers"
v1 "github.com/hay-kot/homebox/backend/app/api/handlers/v1"
_ "github.com/hay-kot/homebox/backend/app/api/static/docs"
@ -108,27 +107,6 @@ func (a *app) mountRoutes(repos *repo.AllRepos) {
a.server.NotFound(notFoundHandler())
}
// logRoutes logs the routes of the server that are registered within Server.registerRoutes(). This is useful for debugging.
// See https://github.com/go-chi/chi/issues/332 for details and inspiration.
func (a *app) logRoutes(r *chi.Mux) {
desiredSpaces := 10
walkFunc := func(method string, route string, handler http.Handler, middleware ...func(http.Handler) http.Handler) error {
text := "[" + method + "]"
for len(text) < desiredSpaces {
text = text + " "
}
fmt.Printf("Registered Route: %s%s\n", text, route)
return nil
}
if err := chi.Walk(r, walkFunc); err != nil {
fmt.Printf("Logging err: %s\n", err.Error())
}
}
func registerMimes() {
err := mime.AddExtensionType(".js", "application/javascript")
if err != nil {

View file

@ -43,7 +43,7 @@ func (s *Server) toHttpHandler(handler Handler, mw ...Middleware) http.HandlerFu
if err != nil {
if IsShutdownError(err) {
s.Shutdown("SIGTERM")
_ = s.Shutdown("SIGTERM")
}
}
}

View file

@ -72,5 +72,5 @@ func (eb *ErrorBuilder) AddError(err error) {
// Respond sends a JSON response with the ErrorBuilder's errors. If there are no errors, then
// the errors field will be an empty array.
func (eb *ErrorBuilder) Respond(w http.ResponseWriter, statusCode int) {
Respond(w, statusCode, Wrap(nil).AddError(http.StatusText(statusCode), eb.errs))
_ = Respond(w, statusCode, Wrap(nil).AddError(http.StatusText(statusCode), eb.errs))
}

View file

@ -16,7 +16,8 @@ func Test_Respond_NoContent(t *testing.T) {
Name: "dummy",
}
Respond(recorder, http.StatusNoContent, dummystruct)
err := Respond(recorder, http.StatusNoContent, dummystruct)
assert.NoError(t, err)
assert.Equal(t, http.StatusNoContent, recorder.Code)
assert.Empty(t, recorder.Body.String())
@ -30,7 +31,8 @@ func Test_Respond_JSON(t *testing.T) {
Name: "dummy",
}
Respond(recorder, http.StatusCreated, dummystruct)
err := Respond(recorder, http.StatusCreated, dummystruct)
assert.NoError(t, err)
assert.Equal(t, http.StatusCreated, recorder.Code)
assert.JSONEq(t, recorder.Body.String(), `{"name":"dummy"}`)