fix: inaccruate 401 & sql busy error (#679)

* fix inaccruate 401 error on SQL db error

* init golangci-lint config

* linter autofix

* testify auto fixes

* fix sqlite busy errors

* fix naming

* more linter errors

* fix rest of linter issues

Former-commit-id: e8449b3a73
This commit is contained in:
Hayden 2024-01-04 11:55:26 -06:00 committed by GitHub
parent 5e83b28ff5
commit 03df23d97c
62 changed files with 389 additions and 292 deletions

View file

@ -1,3 +1,4 @@
// Package config provides the configuration for the application.
package config
import (
@ -16,7 +17,7 @@ const (
type Config struct {
conf.Version
Mode string `yaml:"mode" conf:"default:development"` // development or production
Mode string `yaml:"mode" conf:"default:development"` // development or production
Web WebConfig `yaml:"web"`
Storage Storage `yaml:"storage"`
Log LoggerConf `yaml:"logger"`
@ -27,13 +28,13 @@ type Config struct {
}
type Options struct {
AllowRegistration bool `yaml:"disable_registration" conf:"default:true"`
AllowRegistration bool `yaml:"disable_registration" conf:"default:true"`
AutoIncrementAssetID bool `yaml:"auto_increment_asset_id" conf:"default:true"`
}
type DebugConf struct {
Enabled bool `yaml:"enabled" conf:"default:false"`
Port string `yaml:"port" conf:"default:4000"`
Port string `yaml:"port" conf:"default:4000"`
}
type WebConfig struct {

View file

@ -6,6 +6,6 @@ const (
type Storage struct {
// Data is the path to the root directory
Data string `yaml:"data" conf:"default:./.data"`
SqliteUrl string `yaml:"sqlite-url" conf:"default:./.data/homebox.db?_pragma=busy_timeout=1000&_pragma=journal_mode=WAL&_fk=1"`
Data string `yaml:"data" conf:"default:./.data"`
SqliteURL string `yaml:"sqlite-url" conf:"default:./.data/homebox.db?_pragma=busy_timeout=999&_pragma=journal_mode=WAL&_fk=1"`
}

View file

@ -1,3 +1,4 @@
// Package validate provides a wrapper around the go-playground/validator package
package validate
import (
@ -8,7 +9,7 @@ import (
var validate *validator.Validate
func init() {
func init() { // nolint
validate = validator.New()
err := validate.RegisterValidation("shoutrrr", func(fl validator.FieldLevel) bool {
@ -52,17 +53,16 @@ func init() {
if err != nil {
panic(err)
}
}
// Checks a struct for validation errors and returns any errors the occur. This
// Check a struct for validation errors and returns any errors the occur. This
// wraps the validate.Struct() function and provides some error wrapping. When
// a validator.ValidationErrors is returned, it is wrapped transformed into a
// FieldErrors array and returned.
func Check(val any) error {
err := validate.Struct(val)
if err != nil {
verrors, ok := err.(validator.ValidationErrors)
verrors, ok := err.(validator.ValidationErrors) // nolint - we know it's a validator.ValidationErrors
if !ok {
return err
}