Skip to content

Commit

Permalink
chore: switch struct validation to more standard approach
Browse files Browse the repository at this point in the history
  • Loading branch information
shini4i committed Dec 6, 2023
1 parent a3c4f9d commit bd6b48c
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 1,831 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ repos:
- id: go-fmt
- id: go-mod-tidy
- id: go-imports
- id: golangci-lint
15 changes: 6 additions & 9 deletions cmd/argo-watcher/config/config.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package config

import (
"errors"
"net/url"

"github.com/shini4i/argo-watcher/internal/helpers"

envConfig "github.com/caarlos0/env/v9"
envConfig "github.com/caarlos0/env/v10"
"github.com/go-playground/validator/v10"
)

const (
Expand All @@ -22,7 +20,7 @@ type ServerConfig struct {
DeploymentTimeout uint `env:"DEPLOYMENT_TIMEOUT" envDefault:"900" json:"deployment_timeout"`
ArgoRefreshApp bool `env:"ARGO_REFRESH_APP" envDefault:"true" json:"argo_refresh_app"`
RegistryProxyUrl string `env:"DOCKER_IMAGES_PROXY" json:"registry_proxy_url,omitempty"`
StateType string `env:"STATE_TYPE,required" json:"state_type"`
StateType string `env:"STATE_TYPE,required" validate:"oneof=postgres in-memory" json:"state_type"`
StaticFilePath string `env:"STATIC_FILES_PATH" envDefault:"static" json:"-"`
SkipTlsVerify bool `env:"SKIP_TLS_VERIFY" envDefault:"false" json:"skip_tls_verify"`
LogLevel string `env:"LOG_LEVEL" envDefault:"info" json:"log_level"`
Expand Down Expand Up @@ -53,10 +51,9 @@ func NewServerConfig() (*ServerConfig, error) {
return nil, err
}

// custom checks
allowedTypes := []string{"postgres", "in-memory"}
if config.StateType == "" || !helpers.Contains(allowedTypes, config.StateType) {
return nil, errors.New("variable STATE_TYPE must be one of [\"postgres\", \"in-memory\"]")
validate := validator.New()
if err := validate.Struct(&config); err != nil {
return nil, err
}

// return config
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
STATE_TYPE: postgres
ARGO_URL: http://mock:8081
ARGO_TOKEN: example
ARGO_TIMEOUT: 120
DEPLOYMENT_TIMEOUT: 120
DB_HOST: postgres
DB_PORT: 5432
DB_USER: watcher
Expand Down
60 changes: 30 additions & 30 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,40 @@ module github.com/shini4i/argo-watcher
go 1.21

require (
github.com/avast/retry-go/v4 v4.5.0
github.com/caarlos0/env/v9 v9.0.0
github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19
github.com/avast/retry-go/v4 v4.5.1
github.com/caarlos0/env/v10 v10.0.0
github.com/gin-gonic/contrib v0.0.0-20221130124618-7e01895a63f2
github.com/gin-gonic/gin v1.9.1
github.com/go-git/go-billy/v5 v5.4.1
github.com/go-git/go-git/v5 v5.8.1
github.com/golang-migrate/migrate/v4 v4.15.2
github.com/google/uuid v1.3.1
github.com/lib/pq v1.10.6
github.com/prometheus/client_golang v1.16.0
github.com/rs/zerolog v1.30.0
github.com/stretchr/testify v1.8.3
github.com/go-git/go-billy/v5 v5.5.0
github.com/go-git/go-git/v5 v5.10.1
github.com/go-playground/validator/v10 v10.16.0
github.com/golang-migrate/migrate/v4 v4.16.2
github.com/google/uuid v1.4.0
github.com/lib/pq v1.10.9
github.com/prometheus/client_golang v1.17.0
github.com/rs/zerolog v1.31.0
github.com/stretchr/testify v1.8.4
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.1
go.uber.org/mock v0.2.0
github.com/swaggo/swag v1.16.2
go.uber.org/mock v0.3.0
gopkg.in/yaml.v2 v2.4.0
gorm.io/datatypes v1.2.0
gorm.io/driver/postgres v1.5.2
gorm.io/gorm v1.25.4
gorm.io/driver/postgres v1.5.4
gorm.io/gorm v1.25.5
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
Expand All @@ -47,7 +48,6 @@ require (
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -56,7 +56,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.3.1 // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
Expand All @@ -74,23 +74,23 @@ require (
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/skeema/knownhosts v1.2.0 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.uber.org/atomic v1.7.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.10.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/mysql v1.4.7 // indirect
Expand Down
Loading

0 comments on commit bd6b48c

Please sign in to comment.