From bd058be1fbcdb6348660fb596c8b3fc9b9ea1e85 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 17 Feb 2023 18:51:11 -0900 Subject: [PATCH] formatting --- backend/app/api/handlers/v1/v1_ctrl_assets.go | 1 - backend/app/api/handlers/v1/v1_ctrl_auth.go | 2 -- backend/app/api/handlers/v1/v1_ctrl_items.go | 2 -- .../app/api/handlers/v1/v1_ctrl_items_attachments.go | 1 - backend/app/api/handlers/v1/v1_ctrl_locations.go | 1 - backend/app/api/handlers/v1/v1_ctrl_user.go | 1 - backend/app/api/main.go | 2 +- backend/app/api/middleware.go | 4 +--- .../core/services/service_items_attachments_test.go | 1 - backend/internal/core/services/service_user.go | 3 --- backend/internal/data/migrations/migrations.go | 4 ++-- backend/internal/data/repo/repo_documents.go | 6 ++---- backend/internal/data/repo/repo_documents_test.go | 1 - backend/internal/data/repo/repo_group.go | 11 ++--------- backend/internal/data/repo/repo_item_attachments.go | 1 - .../internal/data/repo/repo_item_attachments_test.go | 2 -- backend/internal/data/repo/repo_items.go | 11 ++--------- backend/internal/data/repo/repo_items_test.go | 2 -- backend/internal/data/repo/repo_labels.go | 1 - backend/internal/data/repo/repo_locations.go | 7 ++----- backend/internal/data/repo/repo_locations_test.go | 2 -- backend/internal/data/repo/repo_maintenance_entry.go | 1 - .../internal/data/repo/repo_maintenance_entry_test.go | 1 - backend/internal/data/repo/repo_tokens.go | 5 ----- backend/internal/data/repo/repo_users.go | 1 - backend/internal/data/repo/repo_users_test.go | 1 - backend/internal/sys/config/conf.go | 6 +----- backend/internal/sys/config/conf_mailer_test.go | 1 - backend/internal/sys/validate/errors.go | 3 +-- backend/internal/sys/validate/validate.go | 1 - backend/internal/web/mid/errors.go | 1 - backend/internal/web/mid/logger.go | 1 - backend/pkgs/faker/random.go | 4 +--- backend/pkgs/faker/randoms_test.go | 9 ++++----- backend/pkgs/mailer/mailer_test.go | 3 --- backend/pkgs/mailer/templates.go | 1 - backend/pkgs/server/middleware.go | 1 - backend/pkgs/server/mux.go | 1 - backend/pkgs/server/response_test.go | 1 - backend/pkgs/server/server.go | 1 - backend/pkgs/server/server_test.go | 1 - backend/pkgs/server/worker.go | 3 +-- backend/pkgs/set/funcs.go | 1 - backend/pkgs/set/funcs_test.go | 1 - 44 files changed, 20 insertions(+), 95 deletions(-) diff --git a/backend/app/api/handlers/v1/v1_ctrl_assets.go b/backend/app/api/handlers/v1/v1_ctrl_assets.go index 82653fe..f91a009 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_assets.go +++ b/backend/app/api/handlers/v1/v1_ctrl_assets.go @@ -49,7 +49,6 @@ func (ctrl *V1Controller) HandleAssetGet() server.HandlerFunc { return server.Respond(w, http.StatusBadRequest, "Invalid page size") } } - items, err := ctrl.repo.Items.QueryByAssetID(r.Context(), ctx.GID, repo.AssetID(assetId), int(page), int(pageSize)) if err != nil { diff --git a/backend/app/api/handlers/v1/v1_ctrl_auth.go b/backend/app/api/handlers/v1/v1_ctrl_auth.go index 95a5cb2..a3dbc58 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_auth.go +++ b/backend/app/api/handlers/v1/v1_ctrl_auth.go @@ -50,7 +50,6 @@ func (ctrl *V1Controller) HandleAuthLogin() server.HandlerFunc { loginForm.Password = r.PostFormValue("password") case server.ContentJSON: err := server.Decode(r, loginForm) - if err != nil { log.Err(err).Msg("failed to decode login form") } @@ -72,7 +71,6 @@ func (ctrl *V1Controller) HandleAuthLogin() server.HandlerFunc { } newToken, err := ctrl.svc.User.Login(r.Context(), strings.ToLower(loginForm.Username), loginForm.Password) - if err != nil { return validate.NewRequestError(errors.New("authentication failed"), http.StatusInternalServerError) } diff --git a/backend/app/api/handlers/v1/v1_ctrl_items.go b/backend/app/api/handlers/v1/v1_ctrl_items.go index ec8f580..b82d2f3 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_items.go +++ b/backend/app/api/handlers/v1/v1_ctrl_items.go @@ -26,7 +26,6 @@ import ( // @Router /v1/items [GET] // @Security Bearer func (ctrl *V1Controller) HandleItemsGetAll() server.HandlerFunc { - extractQuery := func(r *http.Request) repo.ItemQuery { params := r.URL.Query() @@ -244,7 +243,6 @@ func (ctrl *V1Controller) HandleGetAllCustomFieldValues() server.HandlerFunc { // @Security Bearer func (ctrl *V1Controller) HandleItemsImport() server.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) error { - err := r.ParseMultipartForm(ctrl.maxUploadSize << 20) if err != nil { log.Err(err).Msg("failed to parse multipart form") diff --git a/backend/app/api/handlers/v1/v1_ctrl_items_attachments.go b/backend/app/api/handlers/v1/v1_ctrl_items_attachments.go index 033f683..00545a4 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_items_attachments.go +++ b/backend/app/api/handlers/v1/v1_ctrl_items_attachments.go @@ -82,7 +82,6 @@ func (ctrl *V1Controller) HandleItemAttachmentCreate() server.HandlerFunc { attachment.Type(attachmentType), file, ) - if err != nil { log.Err(err).Msg("failed to add attachment") return validate.NewRequestError(err, http.StatusInternalServerError) diff --git a/backend/app/api/handlers/v1/v1_ctrl_locations.go b/backend/app/api/handlers/v1/v1_ctrl_locations.go index ee2785a..8f71ab9 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_locations.go +++ b/backend/app/api/handlers/v1/v1_ctrl_locations.go @@ -34,7 +34,6 @@ func (ctrl *V1Controller) HandleLocationTreeQuery() server.HandlerFunc { WithItems: withItems, }, ) - if err != nil { log.Err(err).Msg("failed to get locations tree") return validate.NewRequestError(err, http.StatusInternalServerError) diff --git a/backend/app/api/handlers/v1/v1_ctrl_user.go b/backend/app/api/handlers/v1/v1_ctrl_user.go index 98bc75e..0d034c2 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_user.go +++ b/backend/app/api/handlers/v1/v1_ctrl_user.go @@ -80,7 +80,6 @@ func (ctrl *V1Controller) HandleUserSelfUpdate() server.HandlerFunc { actor := services.UseUserCtx(r.Context()) newData, err := ctrl.svc.User.UpdateSelf(r.Context(), actor.ID, updateData) - if err != nil { return validate.NewRequestError(err, http.StatusInternalServerError) } diff --git a/backend/app/api/main.go b/backend/app/api/main.go index c505eea..b17b0fa 100644 --- a/backend/app/api/main.go +++ b/backend/app/api/main.go @@ -57,7 +57,7 @@ func run(cfg *config.Config) error { // ========================================================================= // Initialize Database & Repos - err := os.MkdirAll(cfg.Storage.Data, 0755) + err := os.MkdirAll(cfg.Storage.Data, 0o755) if err != nil { log.Fatal().Err(err).Msg("failed to create data directory") } diff --git a/backend/app/api/middleware.go b/backend/app/api/middleware.go index 8baddfb..b41c913 100644 --- a/backend/app/api/middleware.go +++ b/backend/app/api/middleware.go @@ -15,9 +15,7 @@ type tokenHasKey struct { key string } -var ( - hashedToken = tokenHasKey{key: "hashedToken"} -) +var hashedToken = tokenHasKey{key: "hashedToken"} type RoleMode int diff --git a/backend/internal/core/services/service_items_attachments_test.go b/backend/internal/core/services/service_items_attachments_test.go index 14e822e..f9db0f6 100644 --- a/backend/internal/core/services/service_items_attachments_test.go +++ b/backend/internal/core/services/service_items_attachments_test.go @@ -58,5 +58,4 @@ func TestItemService_AddAttachment(t *testing.T) { bts, err := os.ReadFile(storedPath) assert.NoError(t, err) assert.Equal(t, contents, string(bts)) - } diff --git a/backend/internal/core/services/service_user.go b/backend/internal/core/services/service_user.go index 053087b..bed3adb 100644 --- a/backend/internal/core/services/service_user.go +++ b/backend/internal/core/services/service_user.go @@ -139,7 +139,6 @@ func (svc *UserService) UpdateSelf(ctx context.Context, ID uuid.UUID, data repo. // User Authentication func (svc *UserService) createSessionToken(ctx context.Context, userId uuid.UUID) (UserAuthTokenDetail, error) { - attachmentToken := hasher.GenerateToken() attachmentData := repo.UserAuthTokenCreate{ UserID: userId, @@ -173,7 +172,6 @@ func (svc *UserService) createSessionToken(ctx context.Context, userId uuid.UUID func (svc *UserService) Login(ctx context.Context, username, password string) (UserAuthTokenDetail, error) { usr, err := svc.repos.Users.GetOneEmail(ctx, username) - if err != nil { // SECURITY: Perform hash to ensure response times are the same hasher.CheckPasswordHash("not-a-real-password", "not-a-real-password") @@ -197,7 +195,6 @@ func (svc *UserService) RenewToken(ctx context.Context, token string) (UserAuthT hash := hasher.HashToken(token) dbToken, err := svc.repos.AuthTokens.GetUserFromToken(ctx, hash) - if err != nil { return UserAuthTokenDetail{}, ErrorInvalidToken } diff --git a/backend/internal/data/migrations/migrations.go b/backend/internal/data/migrations/migrations.go index fba84c5..d477df9 100644 --- a/backend/internal/data/migrations/migrations.go +++ b/backend/internal/data/migrations/migrations.go @@ -13,7 +13,7 @@ var Files embed.FS // It returns an error and a cleanup function. The cleanup function // should be called when the migrations are no longer needed. func Write(temp string) error { - err := os.MkdirAll(temp, 0755) + err := os.MkdirAll(temp, 0o755) if err != nil { return err } @@ -33,7 +33,7 @@ func Write(temp string) error { return err } - err = os.WriteFile(filepath.Join(temp, f.Name()), b, 0644) + err = os.WriteFile(filepath.Join(temp, f.Name()), b, 0o644) if err != nil { return err } diff --git a/backend/internal/data/repo/repo_documents.go b/backend/internal/data/repo/repo_documents.go index abe340d..587a4f1 100644 --- a/backend/internal/data/repo/repo_documents.go +++ b/backend/internal/data/repo/repo_documents.go @@ -14,9 +14,7 @@ import ( "github.com/hay-kot/homebox/backend/pkgs/pathlib" ) -var ( - ErrInvalidDocExtension = errors.New("invalid document extension") -) +var ErrInvalidDocExtension = errors.New("invalid document extension") type DocumentRepository struct { db *ent.Client @@ -74,7 +72,7 @@ func (r *DocumentRepository) Create(ctx context.Context, gid uuid.UUID, doc Docu path := r.path(gid, ext) parent := filepath.Dir(path) - err := os.MkdirAll(parent, 0755) + err := os.MkdirAll(parent, 0o755) if err != nil { return DocumentOut{}, err } diff --git a/backend/internal/data/repo/repo_documents_test.go b/backend/internal/data/repo/repo_documents_test.go index b58b3bb..2a22fac 100644 --- a/backend/internal/data/repo/repo_documents_test.go +++ b/backend/internal/data/repo/repo_documents_test.go @@ -34,7 +34,6 @@ func useDocs(t *testing.T, num int) []DocumentOut { t.Cleanup(func() { for _, id := range ids { err := tRepos.Docs.Delete(context.Background(), id) - if err != nil { assert.True(t, ent.IsNotFound(err)) } diff --git a/backend/internal/data/repo/repo_group.go b/backend/internal/data/repo/repo_group.go index 8e5ea14..678130c 100644 --- a/backend/internal/data/repo/repo_group.go +++ b/backend/internal/data/repo/repo_group.go @@ -76,9 +76,7 @@ type ( } ) -var ( - mapToGroupErr = mapTErrFunc(mapToGroup) -) +var mapToGroupErr = mapTErrFunc(mapToGroup) func mapToGroup(g *ent.Group) Group { return Group{ @@ -90,9 +88,7 @@ func mapToGroup(g *ent.Group) Group { } } -var ( - mapToGroupInvitationErr = mapTErrFunc(mapToGroupInvitation) -) +var mapToGroupInvitationErr = mapTErrFunc(mapToGroupInvitation) func mapToGroupInvitation(g *ent.GroupInvitationToken) GroupInvitation { return GroupInvitation{ @@ -118,7 +114,6 @@ func (r *GroupRepository) StatsLocationsByPurchasePrice(ctx context.Context, GID return sql.As(sql.Sum(t.C(item.FieldPurchasePrice)), "total") }). Scan(ctx, &v) - if err != nil { return nil, err } @@ -145,7 +140,6 @@ func (r *GroupRepository) StatsLabelsByPurchasePrice(ctx context.Context, GID uu return sql.As(sql.Sum(itemTable.C(item.FieldPurchasePrice)), "total") }). Scan(ctx, &v) - if err != nil { return nil, err } @@ -283,7 +277,6 @@ func (r *GroupRepository) InvitationCreate(ctx context.Context, groupID uuid.UUI SetExpiresAt(invite.ExpiresAt). SetUses(invite.Uses). Save(ctx) - if err != nil { return GroupInvitation{}, err } diff --git a/backend/internal/data/repo/repo_item_attachments.go b/backend/internal/data/repo/repo_item_attachments.go index 1e2ef7b..a034369 100644 --- a/backend/internal/data/repo/repo_item_attachments.go +++ b/backend/internal/data/repo/repo_item_attachments.go @@ -68,7 +68,6 @@ func (r *AttachmentRepo) Update(ctx context.Context, itemId uuid.UUID, typ attac itm, err := r.db.Attachment.UpdateOneID(itemId). SetType(typ). Save(ctx) - if err != nil { return nil, err } diff --git a/backend/internal/data/repo/repo_item_attachments_test.go b/backend/internal/data/repo/repo_item_attachments_test.go index 15f70c8..4c9d77d 100644 --- a/backend/internal/data/repo/repo_item_attachments_test.go +++ b/backend/internal/data/repo/repo_item_attachments_test.go @@ -58,7 +58,6 @@ func TestAttachmentRepo_Create(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := tRepos.Attachments.Create(tt.args.ctx, tt.args.itemId, tt.args.docId, tt.args.typ) if (err != nil) != tt.wantErr { t.Errorf("AttachmentRepo.Create() error = %v, wantErr %v", err, tt.wantErr) @@ -119,7 +118,6 @@ func TestAttachmentRepo_Update(t *testing.T) { assert.Equal(t, typ, updated.Type) }) } - } func TestAttachmentRepo_Delete(t *testing.T) { diff --git a/backend/internal/data/repo/repo_items.go b/backend/internal/data/repo/repo_items.go index 4b67b97..842e86d 100644 --- a/backend/internal/data/repo/repo_items.go +++ b/backend/internal/data/repo/repo_items.go @@ -150,9 +150,7 @@ type ( } ) -var ( - mapItemsSummaryErr = mapTEachErrFunc(mapItemSummary) -) +var mapItemsSummaryErr = mapTEachErrFunc(mapItemSummary) func mapItemSummary(item *ent.Item) ItemSummary { var location *LocationSummary @@ -371,7 +369,6 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite } count, err := qb.Count(ctx) - if err != nil { return PaginationResult[ItemSummary]{}, err } @@ -387,7 +384,6 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite } items, err := mapItemsSummaryErr(qb.All(ctx)) - if err != nil { return PaginationResult[ItemSummary]{}, err } @@ -398,7 +394,6 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite Total: count, Items: items, }, nil - } // QueryByAssetID returns items by asset ID. If the item does not exist, an error is returned. @@ -422,7 +417,6 @@ func (e *ItemsRepository) QueryByAssetID(ctx context.Context, gid uuid.UUID, ass WithLocation(). All(ctx), ) - if err != nil { return PaginationResult[ItemSummary]{}, err } @@ -441,6 +435,7 @@ func (e *ItemsRepository) GetAll(ctx context.Context, gid uuid.UUID) ([]ItemOut, Where(item.HasGroupWith(group.ID(gid))). WithLabel(). WithLocation(). + WithFields(). All(ctx)) } @@ -651,7 +646,6 @@ func (e *ItemsRepository) GetAllCustomFieldValues(ctx context.Context, GID uuid. Unique(true). Select(itemfield.FieldTextValue). Scan(ctx, &values) - if err != nil { return nil, fmt.Errorf("failed to get field values: %w", err) } @@ -679,7 +673,6 @@ func (e *ItemsRepository) GetAllCustomFieldNames(ctx context.Context, GID uuid.U Unique(true). Select(itemfield.FieldName). Scan(ctx, &fields) - if err != nil { return nil, fmt.Errorf("failed to get custom fields: %w", err) } diff --git a/backend/internal/data/repo/repo_items_test.go b/backend/internal/data/repo/repo_items_test.go index 3236537..ac2814d 100644 --- a/backend/internal/data/repo/repo_items_test.go +++ b/backend/internal/data/repo/repo_items_test.go @@ -125,7 +125,6 @@ func TestItemsRepository_Create(t *testing.T) { // Cleanup - Also deletes item err = tRepos.Locations.Delete(context.Background(), location.ID) assert.NoError(t, err) - } func TestItemsRepository_Create_Location(t *testing.T) { @@ -222,7 +221,6 @@ func TestItemsRepository_Update_Labels(t *testing.T) { } }) } - } func TestItemsRepository_Update(t *testing.T) { diff --git a/backend/internal/data/repo/repo_labels.go b/backend/internal/data/repo/repo_labels.go index 9d5b11a..a761ef8 100644 --- a/backend/internal/data/repo/repo_labels.go +++ b/backend/internal/data/repo/repo_labels.go @@ -100,7 +100,6 @@ func (r *LabelRepository) Create(ctx context.Context, groupdId uuid.UUID, data L SetColor(data.Color). SetGroupID(groupdId). Save(ctx) - if err != nil { return LabelOut{}, err } diff --git a/backend/internal/data/repo/repo_locations.go b/backend/internal/data/repo/repo_locations.go index 4e72008..2d3ea56 100644 --- a/backend/internal/data/repo/repo_locations.go +++ b/backend/internal/data/repo/repo_locations.go @@ -62,9 +62,7 @@ func mapLocationSummary(location *ent.Location) LocationSummary { } } -var ( - mapLocationOutErr = mapTErrFunc(mapLocationOut) -) +var mapLocationOutErr = mapTErrFunc(mapLocationOut) func mapLocationOut(location *ent.Location) LocationOut { var parent *LocationSummary @@ -181,7 +179,6 @@ func (r *LocationRepository) Create(ctx context.Context, GID uuid.UUID, data Loc } location, err := q.Save(ctx) - if err != nil { return LocationOut{}, err } @@ -322,7 +319,7 @@ func (lr *LocationRepository) Tree(ctx context.Context, GID uuid.UUID, tq TreeQu } func ConvertLocationsToTree(locations []FlatTreeItem) []TreeItem { - var locationMap = make(map[uuid.UUID]*TreeItem, len(locations)) + locationMap := make(map[uuid.UUID]*TreeItem, len(locations)) var rootIds []uuid.UUID diff --git a/backend/internal/data/repo/repo_locations_test.go b/backend/internal/data/repo/repo_locations_test.go index 1ef2295..0334a42 100644 --- a/backend/internal/data/repo/repo_locations_test.go +++ b/backend/internal/data/repo/repo_locations_test.go @@ -31,7 +31,6 @@ func useLocations(t *testing.T, len int) []LocationOut { t.Cleanup(func() { for _, loc := range out { err := tRepos.Locations.Delete(context.Background(), loc.ID) - if err != nil { assert.True(t, ent.IsNotFound(err)) } @@ -74,7 +73,6 @@ func TestLocationRepositoryGetAllWithCount(t *testing.T) { assert.Equal(t, 1, loc.ItemCount) } } - } func TestLocationRepository_Create(t *testing.T) { diff --git a/backend/internal/data/repo/repo_maintenance_entry.go b/backend/internal/data/repo/repo_maintenance_entry.go index 175bd7e..5f95e50 100644 --- a/backend/internal/data/repo/repo_maintenance_entry.go +++ b/backend/internal/data/repo/repo_maintenance_entry.go @@ -93,7 +93,6 @@ func (r *MaintenanceEntryRepository) GetLog(ctx context.Context, itemID uuid.UUI Where(maintenanceentry.ItemID(itemID)). Order(ent.Desc(maintenanceentry.FieldDate)). All(ctx) - if err != nil { return MaintenanceLog{}, err } diff --git a/backend/internal/data/repo/repo_maintenance_entry_test.go b/backend/internal/data/repo/repo_maintenance_entry_test.go index e3df3d0..bc9f6af 100644 --- a/backend/internal/data/repo/repo_maintenance_entry_test.go +++ b/backend/internal/data/repo/repo_maintenance_entry_test.go @@ -61,7 +61,6 @@ func TestMaintenanceEntryRepository_GetLog(t *testing.T) { // Get the log for the item log, err := tRepos.MaintEntry.GetLog(context.Background(), item.ID) - if err != nil { t.Fatalf("failed to get maintenance log: %v", err) } diff --git a/backend/internal/data/repo/repo_tokens.go b/backend/internal/data/repo/repo_tokens.go index 5820227..7ba982e 100644 --- a/backend/internal/data/repo/repo_tokens.go +++ b/backend/internal/data/repo/repo_tokens.go @@ -42,7 +42,6 @@ func (r *TokenRepository) GetUserFromToken(ctx context.Context, token []byte) (U QueryUser(). WithGroup(). Only(ctx) - if err != nil { return UserOut{}, err } @@ -59,7 +58,6 @@ func (r *TokenRepository) GetRoles(ctx context.Context, token string) (*set.Set[ authtokens.Token(tokenHash), )). All(ctx) - if err != nil { return nil, err } @@ -80,7 +78,6 @@ func (r *TokenRepository) CreateToken(ctx context.Context, createToken UserAuthT SetUserID(createToken.UserID). SetExpiresAt(createToken.ExpiresAt). Save(ctx) - if err != nil { return UserAuthToken{}, err } @@ -90,7 +87,6 @@ func (r *TokenRepository) CreateToken(ctx context.Context, createToken UserAuthT SetRole(role). SetToken(dbToken). Save(ctx) - if err != nil { return UserAuthToken{}, err } @@ -115,7 +111,6 @@ func (r *TokenRepository) DeleteToken(ctx context.Context, token []byte) error { // PurgeExpiredTokens removes all expired tokens from the database func (r *TokenRepository) PurgeExpiredTokens(ctx context.Context) (int, error) { tokensDeleted, err := r.db.AuthTokens.Delete().Where(authtokens.ExpiresAtLTE(time.Now())).Exec(ctx) - if err != nil { return 0, err } diff --git a/backend/internal/data/repo/repo_users.go b/backend/internal/data/repo/repo_users.go index 28407f1..03850d6 100644 --- a/backend/internal/data/repo/repo_users.go +++ b/backend/internal/data/repo/repo_users.go @@ -123,7 +123,6 @@ func (e *UserRepository) DeleteAll(ctx context.Context) error { func (e *UserRepository) GetSuperusers(ctx context.Context) ([]*ent.User, error) { users, err := e.db.User.Query().Where(user.IsSuperuser(true)).All(ctx) - if err != nil { return nil, err } diff --git a/backend/internal/data/repo/repo_users_test.go b/backend/internal/data/repo/repo_users_test.go index 882de1c..31d2737 100644 --- a/backend/internal/data/repo/repo_users_test.go +++ b/backend/internal/data/repo/repo_users_test.go @@ -139,7 +139,6 @@ func TestUserRepo_Delete(t *testing.T) { allUsers, _ = tRepos.Users.GetAll(ctx) assert.Equal(t, len(allUsers), 0) - } func TestUserRepo_GetSuperusers(t *testing.T) { diff --git a/backend/internal/sys/config/conf.go b/backend/internal/sys/config/conf.go index a7a17f0..c1655c2 100644 --- a/backend/internal/sys/config/conf.go +++ b/backend/internal/sys/config/conf.go @@ -4,10 +4,9 @@ import ( "encoding/json" "errors" "fmt" + "os" "github.com/ardanlabs/conf/v3" - - "os" ) const ( @@ -55,7 +54,6 @@ func New() (*Config, error) { const prefix = "HBOX" help, err := conf.Parse(prefix, &cfg) - if err != nil { if errors.Is(err, conf.ErrHelpWanted) { fmt.Println(help) @@ -71,11 +69,9 @@ func New() (*Config, error) { // This is useful for debugging. If the marshaller errors out, it will panic. func (c *Config) Print() { res, err := json.MarshalIndent(c, "", " ") - if err != nil { panic(err) } fmt.Println(string(res)) - } diff --git a/backend/internal/sys/config/conf_mailer_test.go b/backend/internal/sys/config/conf_mailer_test.go index 8656755..6bf7c74 100644 --- a/backend/internal/sys/config/conf_mailer_test.go +++ b/backend/internal/sys/config/conf_mailer_test.go @@ -36,5 +36,4 @@ func Test_MailerReady_Failure(t *testing.T) { mc.From = "from" assert.True(t, mc.Ready()) - } diff --git a/backend/internal/sys/validate/errors.go b/backend/internal/sys/validate/errors.go index d08a448..b5c101a 100644 --- a/backend/internal/sys/validate/errors.go +++ b/backend/internal/sys/validate/errors.go @@ -5,8 +5,7 @@ import ( "errors" ) -type UnauthorizedError struct { -} +type UnauthorizedError struct{} func (err *UnauthorizedError) Error() string { return "unauthorized" diff --git a/backend/internal/sys/validate/validate.go b/backend/internal/sys/validate/validate.go index ed22c0f..4a4b7a9 100644 --- a/backend/internal/sys/validate/validate.go +++ b/backend/internal/sys/validate/validate.go @@ -14,7 +14,6 @@ func init() { // FieldErrors array and returned. func Check(val any) error { err := validate.Struct(val) - if err != nil { verrors, ok := err.(validator.ValidationErrors) if !ok { diff --git a/backend/internal/web/mid/errors.go b/backend/internal/web/mid/errors.go index 7aa659c..dc716c9 100644 --- a/backend/internal/web/mid/errors.go +++ b/backend/internal/web/mid/errors.go @@ -13,7 +13,6 @@ func Errors(log zerolog.Logger) server.Middleware { return func(h server.Handler) server.Handler { return server.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error { err := h.ServeHTTP(w, r) - if err != nil { var resp server.ErrorResponse var code int diff --git a/backend/internal/web/mid/logger.go b/backend/internal/web/mid/logger.go index 86b8cdb..fb39c67 100644 --- a/backend/internal/web/mid/logger.go +++ b/backend/internal/web/mid/logger.go @@ -76,7 +76,6 @@ func SugarLogger(log zerolog.Logger) server.Middleware { return func(next server.Handler) server.Handler { return server.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error { - record := &statusRecorder{ResponseWriter: w, Status: http.StatusOK} err := next.ServeHTTP(record, r) // Blocks until the next handler returns. diff --git a/backend/pkgs/faker/random.go b/backend/pkgs/faker/random.go index 67c7114..e7b51b9 100644 --- a/backend/pkgs/faker/random.go +++ b/backend/pkgs/faker/random.go @@ -7,8 +7,7 @@ import ( var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") -type Faker struct { -} +type Faker struct{} func NewFaker() *Faker { rand.Seed(time.Now().UnixNano()) @@ -20,7 +19,6 @@ func (f *Faker) Time() time.Time { } func (f *Faker) Str(length int) string { - b := make([]rune, length) for i := range b { b[i] = letters[rand.Intn(len(letters))] diff --git a/backend/pkgs/faker/randoms_test.go b/backend/pkgs/faker/randoms_test.go index 0773205..c03c564 100644 --- a/backend/pkgs/faker/randoms_test.go +++ b/backend/pkgs/faker/randoms_test.go @@ -20,7 +20,7 @@ func ValidateUnique(values []string) bool { func Test_GetRandomString(t *testing.T) { t.Parallel() // Test that the function returns a string of the correct length - var generated = make([]string, Loops) + generated := make([]string, Loops) faker := NewFaker() @@ -36,7 +36,7 @@ func Test_GetRandomString(t *testing.T) { func Test_GetRandomEmail(t *testing.T) { t.Parallel() // Test that the function returns a string of the correct length - var generated = make([]string, Loops) + generated := make([]string, Loops) faker := NewFaker() @@ -52,8 +52,8 @@ func Test_GetRandomEmail(t *testing.T) { func Test_GetRandomBool(t *testing.T) { t.Parallel() - var trues = 0 - var falses = 0 + trues := 0 + falses := 0 faker := NewFaker() @@ -91,5 +91,4 @@ func Test_RandomNumber(t *testing.T) { t.Errorf("RandomNumber() failed to generate a number between %v and %v", MIN, MAX) } } - } diff --git a/backend/pkgs/mailer/mailer_test.go b/backend/pkgs/mailer/mailer_test.go index 87a0b60..3e67a68 100644 --- a/backend/pkgs/mailer/mailer_test.go +++ b/backend/pkgs/mailer/mailer_test.go @@ -30,14 +30,12 @@ func GetTestMailer() (*Mailer, error) { } return mailer, nil - } func Test_Mailer(t *testing.T) { t.Parallel() mailer, err := GetTestMailer() - if err != nil { t.Skip("Error Reading Test Mailer Config - Skipping") } @@ -47,7 +45,6 @@ func Test_Mailer(t *testing.T) { } message, err := RenderWelcome() - if err != nil { t.Error(err) } diff --git a/backend/pkgs/mailer/templates.go b/backend/pkgs/mailer/templates.go index b7984c0..cc5049f 100644 --- a/backend/pkgs/mailer/templates.go +++ b/backend/pkgs/mailer/templates.go @@ -41,7 +41,6 @@ func DefaultTemplateData() TemplateProps { func render(tpl string, data TemplateProps) (string, error) { tmpl, err := template.New("name").Parse(tpl) - if err != nil { return "", err } diff --git a/backend/pkgs/server/middleware.go b/backend/pkgs/server/middleware.go index f24f06b..8e3bb23 100644 --- a/backend/pkgs/server/middleware.go +++ b/backend/pkgs/server/middleware.go @@ -11,7 +11,6 @@ type Middleware func(Handler) Handler // handler. The middlewares' Handlers will be executed by requests in the order // they are provided. func wrapMiddleware(mw []Middleware, handler Handler) Handler { - // Loop backwards through the middleware invoking each one. Replace the // handler with the new wrapped handler. Looping backwards ensures that the // first middleware of the slice is the first to be executed by requests. diff --git a/backend/pkgs/server/mux.go b/backend/pkgs/server/mux.go index 9e77e32..7f62ab7 100644 --- a/backend/pkgs/server/mux.go +++ b/backend/pkgs/server/mux.go @@ -40,7 +40,6 @@ func (s *Server) toHttpHandler(handler Handler, mw ...Middleware) http.HandlerFu }) err := handler.ServeHTTP(w, r.WithContext(ctx)) - if err != nil { if IsShutdownError(err) { _ = s.Shutdown("SIGTERM") diff --git a/backend/pkgs/server/response_test.go b/backend/pkgs/server/response_test.go index ef23d60..14e7a37 100644 --- a/backend/pkgs/server/response_test.go +++ b/backend/pkgs/server/response_test.go @@ -37,5 +37,4 @@ func Test_Respond_JSON(t *testing.T) { assert.Equal(t, http.StatusCreated, recorder.Code) assert.JSONEq(t, recorder.Body.String(), `{"name":"dummy"}`) assert.Equal(t, "application/json", recorder.Header().Get("Content-Type")) - } diff --git a/backend/pkgs/server/server.go b/backend/pkgs/server/server.go index 921c576..d021b31 100644 --- a/backend/pkgs/server/server.go +++ b/backend/pkgs/server/server.go @@ -79,7 +79,6 @@ func (s *Server) Shutdown(sig string) error { s.wg.Wait() return nil - } func (s *Server) Start() error { diff --git a/backend/pkgs/server/server_test.go b/backend/pkgs/server/server_test.go index 95a93fe..a5cb218 100644 --- a/backend/pkgs/server/server_test.go +++ b/backend/pkgs/server/server_test.go @@ -72,7 +72,6 @@ func Test_GracefulServerShutdownWithWorkers(t *testing.T) { assert.NoError(t, err) assert.True(t, isFinished) - } func Test_GracefulServerShutdownWithRequests(t *testing.T) { diff --git a/backend/pkgs/server/worker.go b/backend/pkgs/server/worker.go index acd6e25..9cf1cc7 100644 --- a/backend/pkgs/server/worker.go +++ b/backend/pkgs/server/worker.go @@ -10,8 +10,7 @@ type Worker interface { // the Worker interface and runs all tasks in a go routine without // a pool or que or limits. It's useful for simple or small applications // with minimal/short background tasks -type SimpleWorker struct { -} +type SimpleWorker struct{} func NewSimpleWorker() *SimpleWorker { return &SimpleWorker{} diff --git a/backend/pkgs/set/funcs.go b/backend/pkgs/set/funcs.go index 0d9a261..d13cdcd 100644 --- a/backend/pkgs/set/funcs.go +++ b/backend/pkgs/set/funcs.go @@ -97,5 +97,4 @@ func Disjoint[T key](a, b Set[T]) bool { } } return true - } diff --git a/backend/pkgs/set/funcs_test.go b/backend/pkgs/set/funcs_test.go index ab3aa0e..cd49ef7 100644 --- a/backend/pkgs/set/funcs_test.go +++ b/backend/pkgs/set/funcs_test.go @@ -28,7 +28,6 @@ var ( ) func TestDiff(t *testing.T) { - tests := []struct { name string args args