Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,20 @@ Check all available options with `go run ./ -h`

```text
Supported Fields:
FIELD FLAG ENV DEFAULT
----- ----- ----- -------
App.Log.Level -app-log-level APP_LOG_LEVEL info
App.Log.Human -app-log-human APP_LOG_HUMAN
App.AdminServer.Enabled -app-adminserver-enabled APP_ADMINSERVER_ENABLED true
App.AdminServer.Addr -app-adminserver-addr APP_ADMINSERVER_ADDR localhost:9000
App.AdminServer.With.DebugURLs -app-adminserver-with-debugurls APP_ADMINSERVER_WITH_DEBUGURLS true
App.AdminServer.With.Metrics -app-adminserver-with-metrics APP_ADMINSERVER_WITH_METRICS true
App.AdminServer.With.Probes -app-adminserver-with-probes APP_ADMINSERVER_WITH_PROBES true
App.Shutdown.GracePeriod -app-shutdown-graceperiod APP_SHUTDOWN_GRACEPERIOD 3s
App.Shutdown.Timeout -app-shutdown-timeout APP_SHUTDOWN_TIMEOUT 5s
FIELD FLAG ENV DEFAULT USAGE
----- ----- ----- ------- -----
App.Log.Level -app-log-level APP_LOG_LEVEL info The log level. Possible values are: trace, debug, info, warn, error, fatal and panic.
App.Log.Human -app-log-human APP_LOG_HUMAN false Whether to use human friendly log output. If true, the log will be printed in a human friendly format. If false, the log will be printed in JSON format.
App.AdminServer.Enabled -app-adminserver-enabled APP_ADMINSERVER_ENABLED true Enables the admin server
App.AdminServer.Addr -app-adminserver-addr APP_ADMINSERVER_ADDR localhost:9000 The address the admin server will bind to. To bind to all interfaces, use :9000.
App.AdminServer.With.DebugURLs -app-adminserver-with-debugurls APP_ADMINSERVER_WITH_DEBUGURLS true Enables the /debug URLs in the admin server.
App.AdminServer.With.Metrics -app-adminserver-with-metrics APP_ADMINSERVER_WITH_METRICS true Enables the /metrics endpoint in the admin server.
App.AdminServer.With.Probes -app-adminserver-with-probes APP_ADMINSERVER_WITH_PROBES true Enables the /ready and /healthy endpoints in the admin server.
App.Shutdown.GracePeriod -app-shutdown-graceperiod APP_SHUTDOWN_GRACEPERIOD 3s The grace period for the shutdown procedure. During normal shutdown procedures, the shutdown function will wait this amount of time before actually starting calling the shutdown handlers.
App.Shutdown.Timeout -app-shutdown-timeout APP_SHUTDOWN_TIMEOUT 5s The timeout for the shutdown procedure. If the shutdown procedure takes longer than this value, the application will force exit.
App.Config.Output -app-config-output APP_CONFIG_OUTPUT Prints the configuration in the desired format and exit. Possible values are: env, yaml and json.
App.Check.Ready -app-check-ready APP_CHECK_READY false Whether to execute a ready check on the application. If true, the application will execute the ready check and exit with code 0 if the check is successful or with code 1 if the check fails.
App.Check.Healthy -app-check-healthy APP_CHECK_HEALTHY false Whether to execute a healthy check on the application. If true, the application will execute the healthy check and exit with code 0 if the check is successful or with code 1 if the check fails.
```

There is a special option to print out the default configuration in `env` or `yaml` format: `go run . -app-config-output=env`.
Expand Down
25 changes: 13 additions & 12 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,36 @@ type Config struct {
Log logger.Config
AdminServer struct {
// Enabled sets the admin server
Enabled bool `default:"true"`
Enabled bool `default:"true" usage:"Enables the admin server"`
// DefaultAdminPort is the default port the app will bind the admin HTTP interface.
Addr string `default:"localhost:9000"`
Addr string `default:"localhost:9000" usage:"The address the admin server will bind to. To bind to all interfaces, use :9000."`
With struct {
// DebugURLs sets the debug URLs in the admin server. To disable them, set to false.
DebugURLs bool `default:"true"`
// Metrics
Metrics bool `default:"true"`
// Probes
Probes bool `default:"true"`
DebugURLs bool `default:"true" usage:"Enables the /debug URLs in the admin server."`
// Metrics enables the /metrics endpoint in the admin server. To disable it, set to false.
Metrics bool `default:"true" usage:"Enables the /metrics endpoint in the admin server."`
// Probes enables the /ready and /healthy endpoints in the admin server. To disable them, set to false.
Probes bool `default:"true" usage:"Enables the /ready and /healthy endpoints in the admin server."`
}
}
Shutdown struct {
// DefaultGracePeriod is the default value for the grace period.
// During normal shutdown procedures, the shutdown function will wait
// this amount of time before actually starting calling the shutdown handlers.
GracePeriod time.Duration `default:"3s"`
GracePeriod time.Duration `default:"3s" usage:"The grace period for the shutdown procedure. During normal shutdown procedures, the shutdown function will wait this amount of time before actually starting calling the shutdown handlers."`
// DefaultShutdownTimeout is the default value for the timeout during shutdown.
Timeout time.Duration `default:"5s"`
Timeout time.Duration `default:"5s" usage:"The timeout for the shutdown procedure. If the shutdown procedure takes longer than this value, the application will force exit."`
}
Config struct {
Output string
// Output sets the output format for the configuration. If set, the application will print the configuration in the desired format and exit. Possible values are: env, yaml and json.
Output string `usage:"Prints the configuration in the desired format and exit. Possible values are: env, yaml and json."`
}
// Check executes a heathy check on the application.
Check struct {
// Ready checks if the application is ready to receive requests.
Ready bool
Ready bool `default:"false" usage:"Whether to execute a ready check on the application. If true, the application will execute the ready check and exit with code 0 if the check is successful or with code 1 if the check fails."`
// Healthy checks if the application is alive.
Healthy bool
Healthy bool `default:"false" usage:"Whether to execute a healthy check on the application. If true, the application will execute the healthy check and exit with code 0 if the check is successful or with code 1 if the check fails."`
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion default.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ func checkProbe(url string) error {
if err != nil {
return err
}

// #nosec: G704
// This is a false positive because the URL is always localhost and the
// port is retrieved from the admin server configuration.
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.66.1 // indirect
github.com/prometheus/procfs v0.17.0 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
golang.org/x/sys v0.36.0 // indirect
google.golang.org/protobuf v1.36.9 // indirect
github.com/prometheus/common v0.67.5 // indirect
github.com/prometheus/procfs v0.19.2 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
golang.org/x/sys v0.41.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9ZoGs=
github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA=
github.com/prometheus/procfs v0.17.0 h1:FuLQ+05u4ZI+SS/w9+BWEM2TXiHKsUQ9TADiRH7DuK0=
github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUOVhe0wYB2zw=
github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4=
github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw=
github.com/prometheus/procfs v0.19.2 h1:zUMhqEW66Ex7OXIiDkll3tl9a1ZdilUOd/F6ZXw4Vws=
github.com/prometheus/procfs v0.19.2/go.mod h1:M0aotyiemPhBCM0z5w87kL22CxfcH05ZpYlu+b4J7mw=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
Expand All @@ -46,17 +46,17 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
61 changes: 0 additions & 61 deletions internal/thirdparty/uconfig/classic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package uconfig_test
import (
"encoding/json"
"flag"
"fmt"
"os"
"testing"

"github.com/arquivei/go-app/internal/thirdparty/uconfig"
"github.com/arquivei/go-app/internal/thirdparty/uconfig/internal/f"
"github.com/arquivei/go-app/internal/thirdparty/uconfig/plugins/secret"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -63,65 +61,6 @@ func TestClassicBasic(t *testing.T) {
assert.Equal(t, expect, value)
}

func TestClassicWithSecret(t *testing.T) {
// Config is part of text fixtures.
type Creds struct {
APIKey string `secret:""`
APIToken string `secret:"API_TOKEN"`
}

type Config struct {
Redis f.Redis
Rethink f.RethinkConfig
Creds Creds
}
expect := Config{
Redis: f.Redis{
Host: "redis-host",
Port: 6379,
},

Rethink: f.RethinkConfig{
Host: f.Host{
Address: "rethink-cluster",
Port: "28015",
},
DB: "base",
Password: "top secret token",
},

Creds: Creds{
APIKey: "top secret token",
APIToken: "top secret token",
},
}

files := uconfig.Files{
{"testdata/classic.json", json.Unmarshal, true},
}

value := Config{}

SecretProvider := func(name string) (string, error) {
// known secrets.
if name == "API_TOKEN" || name == "RETHINK_PASSWORD" || name == "CREDS_APIKEY" {
return "top secret token", nil
}

return "", fmt.Errorf("Secret not found %s", name)
}

// patch the os.Args. for our tests.
os.Args = os.Args[:1]
err := os.Unsetenv("REDIS_HOST")
require.NoError(t, err)

_, err = uconfig.Classic(&value, files, secret.New(SecretProvider))
require.NoError(t, err)

assert.Equal(t, expect, value)
}

func TestClassicBadPlugin(t *testing.T) {
var badPlugin BadPlugin

Expand Down
7 changes: 4 additions & 3 deletions internal/thirdparty/uconfig/internal/f/f.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ type Host struct {

// RethinkConfig is part of text fixtures.
type RethinkConfig struct {
Host Host
DB string `default:"primary" usage:"main database used by our application"`
Password string `secret:""`
Host Host
DB string `default:"primary" usage:"main database used by our application"`
//nolint:gosec
Password string
}

// Redis is part of text fixtures.
Expand Down
84 changes: 0 additions & 84 deletions internal/thirdparty/uconfig/plugins/secret/secret.go

This file was deleted.

Loading