feat(deps): update golangci-lint to v2
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 5m5s
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 4m53s

This commit was merged in pull request #55.
This commit is contained in:
2025-05-06 17:36:05 +02:00
parent 81380f184e
commit f085ed378e
10 changed files with 36 additions and 28 deletions

View File

@@ -1,6 +1,6 @@
FROM golang:1.24.2@sha256:30baaea08c5d1e858329c50f29fe381e9b7d7bced11a0f5f1f69a1504cdfbf5e AS builder_go FROM golang:1.24.2@sha256:30baaea08c5d1e858329c50f29fe381e9b7d7bced11a0f5f1f69a1504cdfbf5e AS builder_go
WORKDIR /spend-sparrow WORKDIR /spend-sparrow
RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest RUN go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
RUN go install github.com/a-h/templ/cmd/templ@latest RUN go install github.com/a-h/templ/cmd/templ@latest
RUN go install github.com/vektra/mockery/v2@latest RUN go install github.com/vektra/mockery/v2@latest
COPY go.mod go.sum ./ COPY go.mod go.sum ./

View File

@@ -16,7 +16,10 @@ func setupDb(t *testing.T) *sqlx.DB {
t.Fatalf("Error opening database: %v", err) t.Fatalf("Error opening database: %v", err)
} }
t.Cleanup(func() { t.Cleanup(func() {
db.Close() err := db.Close()
if err != nil {
panic(err)
}
}) })
err = RunMigrations(db, "../") err = RunMigrations(db, "../")

View File

@@ -13,7 +13,7 @@ import (
) )
var ( var (
ErrNotFound = errors.New("The value does not exist.") ErrNotFound = errors.New("the value does not exist")
ErrAlreadyExists = errors.New("row already exists") ErrAlreadyExists = errors.New("row already exists")
) )

View File

@@ -7,14 +7,10 @@ import (
func CacheControl(next http.Handler) http.Handler { func CacheControl(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
cached := false shouldCache := strings.HasPrefix(r.URL.Path, "/static")
if strings.HasPrefix(path, "/static") {
cached = true
}
if !cached { if !shouldCache {
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
} }

View File

@@ -20,17 +20,17 @@ var (
) )
func Fatal(message string, args ...interface{}) { func Fatal(message string, args ...interface{}) {
errorMetric.Inc()
s := format(message, args) s := format(message, args)
log.Fatal(s) log.Fatal(s)
errorMetric.Inc()
} }
func Error(message string, args ...interface{}) { func Error(message string, args ...interface{}) {
errorMetric.Inc()
s := format(message, args) s := format(message, args)
slog.Error(s) slog.Error(s)
errorMetric.Inc()
} }
func Warn(message string, args ...interface{}) { func Warn(message string, args ...interface{}) {

View File

@@ -32,7 +32,10 @@ func main() {
if err != nil { if err != nil {
log.Fatal("Could not open Database data.db: %v", err) log.Fatal("Could not open Database data.db: %v", err)
} }
defer db.Close() defer func() {
err := db.Close()
log.Fatal("Could not close Database data.db: %v", err)
}()
run(context.Background(), db, os.Getenv) run(context.Background(), db, os.Getenv)
} }

View File

@@ -1634,7 +1634,10 @@ func setupIntegrationTest(t *testing.T) (db *sqlx.DB, basePath string, ctx conte
t.Fatalf("Could not open Database data.db: %v", err) t.Fatalf("Could not open Database data.db: %v", err)
} }
t.Cleanup(func() { t.Cleanup(func() {
db.Close() err := db.Close()
if err != nil {
panic(err)
}
}) })
testPort := port.Add(1) testPort := port.Add(1)
@@ -1652,17 +1655,18 @@ func setupIntegrationTest(t *testing.T) (db *sqlx.DB, basePath string, ctx conte
func getEnv(port int32) func(string) string { func getEnv(port int32) func(string) string {
return func(key string) string { return func(key string) string {
if key == "PORT" { switch key {
case "PORT":
return fmt.Sprint(port) return fmt.Sprint(port)
} else if key == "SMTP_ENABLED" { case "SMTP_ENABLED":
return "false" return "false"
} else if key == "PROMETHEUS_ENABLED" { case "PROMETHEUS_ENABLED":
return "false" return "false"
} else if key == "BASE_URL" { case "BASE_URL":
return "http://localhost:" + fmt.Sprint(port) return "http://localhost:" + fmt.Sprint(port)
} else if key == "ENVIRONMENT" { case "ENVIRONMENT":
return "test" return "test"
} else { default:
return "" return ""
} }
} }
@@ -1685,10 +1689,12 @@ func waitForReady(
resp, err := client.Do(req) resp, err := client.Do(req)
if err == nil && resp.StatusCode == http.StatusOK { if err == nil && resp.StatusCode == http.StatusOK {
resp.Body.Close() return resp.Body.Close()
return nil
} else if err == nil { } else if err == nil {
resp.Body.Close() err := resp.Body.Close()
if err != nil {
return err
}
} }
select { select {

View File

@@ -149,9 +149,9 @@ func (service AccountImpl) Delete(user *types.User, id uuid.UUID) error {
func (service AccountImpl) validateAccount(name string) error { func (service AccountImpl) validateAccount(name string) error {
if name == "" { if name == "" {
return errors.New("Please enter a value for the \"name\" field.") return errors.New("please enter a value for the \"name\" field")
} else if !safeInputRegex.MatchString(name) { } else if !safeInputRegex.MatchString(name) {
return errors.New("Please use only letters, dashes or numbers for \"name\".") return errors.New("please use only letters, dashes or numbers for \"name\"")
} else { } else {
return nil return nil
} }

View File

@@ -19,7 +19,7 @@ import (
var ( var (
ErrInvalidCredentials = errors.New("invalid email or password") ErrInvalidCredentials = errors.New("invalid email or password")
ErrInvalidPassword = errors.New("The password needs to be 8 characters long, contain at least one number, one special, one uppercase and one lowercase character") ErrInvalidPassword = errors.New("the password needs to be 8 characters long, contain at least one number, one special, one uppercase and one lowercase character")
ErrInvalidEmail = errors.New("invalid email") ErrInvalidEmail = errors.New("invalid email")
ErrAccountExists = errors.New("account already exists") ErrAccountExists = errors.New("account already exists")
ErrSessionIdInvalid = errors.New("session ID is invalid") ErrSessionIdInvalid = errors.New("session ID is invalid")

View File

@@ -6,5 +6,5 @@ import (
var ( var (
ErrInternal = errors.New("internal server error") ErrInternal = errors.New("internal server error")
ErrUnauthorized = errors.New("You are not authorized to perform this action.") ErrUnauthorized = errors.New("you are not authorized to perform this action")
) )