fix: resolve golangci-lint violations (errcheck, unused, gosimple, ineffassign)
errcheck: add proper error handling with slog.Error for tx.Rollback, key generation, and s3/dav operations. Add nolint comments for intentionally discarded DB scan errors and HTTP write errors. unused: remove dead code (svcRow type, processImage, nonDepositPaymentType, generateSecureCode, colorBold, nGreen, nRed) gosimple S1021: merge var declaration with assignment in manage.go ineffassign: remove dead assignments in settings.go, till.go, images.go Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -103,7 +104,7 @@ func GetCustomServices(w http.ResponseWriter, r *http.Request) {
|
||||
if services == nil {
|
||||
services = []CustomService{}
|
||||
}
|
||||
json.NewEncoder(w).Encode(services)
|
||||
_ = json.NewEncoder(w).Encode(services)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -166,11 +167,13 @@ func GetCustomServices(w http.ResponseWriter, r *http.Request) {
|
||||
// so pgx does not return "conn busy" on the same transaction.
|
||||
if q != "" {
|
||||
var countTotal int64
|
||||
db.Conn.QueryRow(r.Context(), "SELECT COUNT(*) FROM custom_services WHERE name ILIKE $1 OR description ILIKE $1", "%"+q+"%").Scan(&countTotal)
|
||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
||||
_ = db.Conn.QueryRow(r.Context(), "SELECT COUNT(*) FROM custom_services WHERE name ILIKE $1 OR description ILIKE $1", "%"+q+"%").Scan(&countTotal)
|
||||
total = countTotal
|
||||
} else {
|
||||
var countTotal int64
|
||||
db.Conn.QueryRow(r.Context(), "SELECT COUNT(*) FROM custom_services").Scan(&countTotal)
|
||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
||||
_ = db.Conn.QueryRow(r.Context(), "SELECT COUNT(*) FROM custom_services").Scan(&countTotal)
|
||||
total = countTotal
|
||||
}
|
||||
|
||||
@@ -186,7 +189,7 @@ func GetCustomServices(w http.ResponseWriter, r *http.Request) {
|
||||
if services == nil {
|
||||
services = []CustomService{}
|
||||
}
|
||||
json.NewEncoder(w).Encode(CustomServiceListResponse{
|
||||
_ = json.NewEncoder(w).Encode(CustomServiceListResponse{
|
||||
Services: services,
|
||||
Total: total,
|
||||
PerPage: perPage,
|
||||
@@ -259,7 +262,7 @@ func CreateCustomService(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
json.NewEncoder(w).Encode(cs)
|
||||
_ = json.NewEncoder(w).Encode(cs)
|
||||
}
|
||||
|
||||
func GetCustomService(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -299,7 +302,7 @@ func GetCustomService(w http.ResponseWriter, r *http.Request) {
|
||||
cs.LastUsedAt = &lastUsedAt.Time
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(cs)
|
||||
_ = json.NewEncoder(w).Encode(cs)
|
||||
}
|
||||
|
||||
func UpdateCustomService(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -378,7 +381,11 @@ func UpdateCustomService(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer tx.Rollback(r.Context())
|
||||
defer func() {
|
||||
if err := tx.Rollback(r.Context()); err != nil {
|
||||
slog.Error("failed to rollback transaction", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
result, err := tx.Exec(r.Context(), query, args...)
|
||||
if err != nil {
|
||||
@@ -395,7 +402,7 @@ func UpdateCustomService(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(map[string]string{"message": "Custom service updated"})
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"message": "Custom service updated"})
|
||||
}
|
||||
|
||||
func PromoteCustomService(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -410,7 +417,11 @@ func PromoteCustomService(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Failed to start transaction", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer tx.Rollback(r.Context())
|
||||
defer func() {
|
||||
if err := tx.Rollback(r.Context()); err != nil {
|
||||
slog.Error("failed to rollback transaction", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
var name, desc, notes sql.NullString
|
||||
var price float64
|
||||
@@ -473,7 +484,7 @@ func PromoteCustomService(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(map[string]string{
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{
|
||||
"message": "Custom service promoted to regular service",
|
||||
"new_service_id": newServiceID,
|
||||
"custom_service_id": id,
|
||||
@@ -507,7 +518,11 @@ func DeleteCustomService(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer tx.Rollback(r.Context())
|
||||
defer func() {
|
||||
if err := tx.Rollback(r.Context()); err != nil {
|
||||
slog.Error("failed to rollback transaction", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
result, err := tx.Exec(r.Context(), `DELETE FROM custom_services WHERE id = $1`, id)
|
||||
if err != nil {
|
||||
@@ -524,7 +539,7 @@ func DeleteCustomService(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(map[string]string{"message": "Custom service deleted"})
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"message": "Custom service deleted"})
|
||||
}
|
||||
|
||||
func joinStrings(strs []string, sep string) string {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -279,7 +280,11 @@ func CreateDiscountCampaign(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer tx.Rollback(r.Context())
|
||||
defer func() {
|
||||
if err := tx.Rollback(r.Context()); err != nil {
|
||||
slog.Error("failed to rollback transaction", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Insert new campaign
|
||||
query := `
|
||||
@@ -512,7 +517,11 @@ func UpdateDiscountCampaign(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer tx.Rollback(r.Context())
|
||||
defer func() {
|
||||
if err := tx.Rollback(r.Context()); err != nil {
|
||||
slog.Error("failed to rollback transaction", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
_, err = tx.Exec(r.Context(), query, args...)
|
||||
if err != nil {
|
||||
@@ -636,7 +645,11 @@ func DeleteDiscountCampaign(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer tx.Rollback(r.Context())
|
||||
defer func() {
|
||||
if err := tx.Rollback(r.Context()); err != nil {
|
||||
slog.Error("failed to rollback transaction", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
result, err := tx.Exec(r.Context(), query, campaignID)
|
||||
if err != nil {
|
||||
@@ -656,7 +669,7 @@ func DeleteDiscountCampaign(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(map[string]any{
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"message": "Campaign deleted successfully",
|
||||
"id": campaignID,
|
||||
})
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"crussell/internal/validators"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -73,7 +74,7 @@ func GetPatchTests(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(patchTests)
|
||||
_ = json.NewEncoder(w).Encode(patchTests)
|
||||
}
|
||||
|
||||
// CreatePatchTest handles POST /api/admin/patch-tests
|
||||
@@ -100,7 +101,11 @@ func CreatePatchTest(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer tx.Rollback(r.Context())
|
||||
defer func() {
|
||||
if err := tx.Rollback(r.Context()); err != nil {
|
||||
slog.Error("failed to rollback transaction", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
var id string
|
||||
err = tx.QueryRow(r.Context(), query, req.Name, req.Description, req.NoticeDurationHours, req.ExpiryMonths, req.ServiceIDs).Scan(&id)
|
||||
@@ -115,7 +120,7 @@ func CreatePatchTest(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
json.NewEncoder(w).Encode(map[string]string{"id": id})
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"id": id})
|
||||
}
|
||||
|
||||
// UpdatePatchTest handles PUT /api/admin/patch-tests/{id}
|
||||
@@ -176,7 +181,11 @@ func UpdatePatchTest(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer tx.Rollback(r.Context())
|
||||
defer func() {
|
||||
if err := tx.Rollback(r.Context()); err != nil {
|
||||
slog.Error("failed to rollback transaction", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
_, err = tx.Exec(r.Context(), query, args...)
|
||||
if err != nil {
|
||||
@@ -205,7 +214,11 @@ func DeletePatchTest(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer tx.Rollback(r.Context())
|
||||
defer func() {
|
||||
if err := tx.Rollback(r.Context()); err != nil {
|
||||
slog.Error("failed to rollback transaction", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
_, err = tx.Exec(r.Context(), "DELETE FROM patch_tests WHERE id = $1", id)
|
||||
if err != nil {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -68,7 +69,7 @@ func GetPublicBusinessInfo(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(info)
|
||||
_ = json.NewEncoder(w).Encode(info)
|
||||
}
|
||||
|
||||
func GetBusinessSettings(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -90,7 +91,7 @@ func GetBusinessSettings(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(s)
|
||||
_ = json.NewEncoder(w).Encode(s)
|
||||
}
|
||||
|
||||
type UpdateBusinessSettingsRequest struct {
|
||||
@@ -222,7 +223,6 @@ func UpdateBusinessSettings(w http.ResponseWriter, r *http.Request) {
|
||||
if req.VoucherType != nil {
|
||||
setClauses = append(setClauses, "voucher_type = $"+strconv.Itoa(argIdx))
|
||||
args = append(args, *req.VoucherType)
|
||||
argIdx++
|
||||
}
|
||||
|
||||
if len(setClauses) == 0 {
|
||||
@@ -245,7 +245,11 @@ func UpdateBusinessSettings(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Failed to update settings", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer tx.Rollback(r.Context())
|
||||
defer func() {
|
||||
if err := tx.Rollback(r.Context()); err != nil {
|
||||
slog.Error("failed to rollback transaction", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
_, err = tx.Exec(r.Context(), query.String(), args...)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user