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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.15.x, 1.16.x]
go-version: [1.24.x, 1.23.x]

services:
etc:
Expand Down
2 changes: 1 addition & 1 deletion backend/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewOptionalBackend(path string) *Backend {

// Unmarshal takes a struct pointer and unmarshals the file into it,
// using either json or yaml based on the file extention.
func (b *Backend) Unmarshal(ctx context.Context, to interface{}) error {
func (b *Backend) Unmarshal(ctx context.Context, to any) error {
f, err := os.Open(b.path)
if err != nil {
if b.optional {
Expand Down
8 changes: 4 additions & 4 deletions backend/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package file_test
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -17,14 +16,15 @@ import (
func createTempFile(t *testing.T, name, content string) (string, func()) {
t.Helper()

dir, err := ioutil.TempDir("", "confita")
dir, err := os.MkdirTemp("", "confita")
require.NoError(t, err)

path := filepath.Join(dir, name)
f, err := os.Create(path)
require.NoError(t, err)

fmt.Fprintf(f, content)
_, err = fmt.Fprintf(f, "%s", content)
require.NoError(t, err)

require.NoError(t, f.Close())

Expand All @@ -46,7 +46,7 @@ func TestFileBackend(t *testing.T) {
Timeout: 10,
}

testLoad := func(t *testing.T, path string, template interface{}, expected interface{}) {
testLoad := func(t *testing.T, path string, template any, expected any) {
b := file.NewBackend(path)

err := b.Unmarshal(context.Background(), template)
Expand Down
4 changes: 2 additions & 2 deletions backend/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package flags

import (
"context"
"errors"
"flag"
"fmt"
"os"
"reflect"
"time"

"github.com/heetch/confita"
"github.com/pkg/errors"
)

// Backend that loads configuration from the command line flags.
Expand Down Expand Up @@ -137,7 +137,7 @@ func (f *flagValue) String() string {
return f.Key
}

func (f *flagValue) Get() interface{} {
func (f *flagValue) Get() any {
return f.Default.Interface()
}

Expand Down
2 changes: 1 addition & 1 deletion backend/flags/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"
)

func runHelper(t *testing.T, cfg interface{}, args ...string) {
func runHelper(t *testing.T, cfg any, args ...string) {
t.Helper()

flags := flag.NewFlagSet("test", flag.ContinueOnError)
Expand Down
2 changes: 1 addition & 1 deletion backend/vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (b *Backend) Get(ctx context.Context, key string) ([]byte, error) {

if b.v2 {
if data, ok := b.secret.Data["data"]; ok {
data := data.(map[string]interface{})
data := data.(map[string]any)
if v, ok := data[key]; ok {
return []byte(v.(string)), nil
}
Expand Down
4 changes: 2 additions & 2 deletions backend/vault/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestVaultBackend(t *testing.T) {
b := NewBackend(c, path)

_, err = c.Write(path,
map[string]interface{}{
map[string]any{
"foo": "bar",
"data": "nan",
})
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestVaultBackendV2(t *testing.T) {
// For writing we use the Consul client directly,
// so we need to use the full proper path.
_, err = c.Write(path,
map[string]interface{}{
map[string]any{
"data": map[string]string{
"foo": "bar",
"data": "nan",
Expand Down
8 changes: 4 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Loader struct {

// Unmarshaler can be implemented by backends to receive the struct directly and load values into it.
type Unmarshaler interface {
Unmarshal(ctx context.Context, to interface{}) error
Unmarshal(ctx context.Context, to any) error
}

// StructLoader can be implemented by backends to receive the parsed struct informations and load values into it.
Expand All @@ -48,7 +48,7 @@ func NewLoader(backends ...backend.Backend) *Loader {

// Load analyses all the Fields of the given struct for a "config" tag and queries each backend
// in order for the corresponding key. The given context can be used for timeout and cancelation.
func (l *Loader) Load(ctx context.Context, to interface{}) error {
func (l *Loader) Load(ctx context.Context, to any) error {
select {
case <-ctx.Done():
return ctx.Err()
Expand All @@ -74,7 +74,7 @@ func (l *Loader) parseStruct(ref reflect.Value) *StructConfig {
t := ref.Type()

numFields := ref.NumField()
for i := 0; i < numFields; i++ {
for i := range numFields {
field := t.Field(i)
value := ref.Field(i)
typ := value.Type()
Expand Down Expand Up @@ -241,7 +241,7 @@ func (l *Loader) resolve(ctx context.Context, s *StructConfig) error {

// StructConfig holds informations about each field of a struct S.
type StructConfig struct {
S interface{}
S any
Fields []*FieldConfig
}

Expand Down
4 changes: 2 additions & 2 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (u unmarshaler) Get(ctx context.Context, key string) ([]byte, error) {
return nil, nil
}

func (u unmarshaler) Unmarshal(ctx context.Context, to interface{}) error {
func (u unmarshaler) Unmarshal(ctx context.Context, to any) error {
return json.Unmarshal([]byte(u), to)
}

Expand Down Expand Up @@ -516,7 +516,7 @@ func TestSliceField(t *testing.T) {
var errorTests = []struct {
testName string
store store
into interface{}
into any
expectError string
}{{
testName: "bad-duration",
Expand Down
49 changes: 40 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,68 @@ module github.com/heetch/confita

require (
github.com/BurntSushi/toml v0.3.1
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 // indirect
github.com/aws/aws-sdk-go v1.23.20
github.com/coreos/bbolt v1.3.2 // indirect
github.com/coreos/etcd v3.3.3+incompatible
github.com/hashicorp/consul/api v1.1.0
github.com/hashicorp/vault/api v1.0.4
github.com/pkg/errors v0.8.1
github.com/stretchr/testify v1.4.0
gopkg.in/yaml.v2 v2.2.2
)

require (
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 // indirect
github.com/coreos/bbolt v1.3.2 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gogo/protobuf v1.2.0 // indirect
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect
github.com/golang/protobuf v1.3.1 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/gorilla/websocket v1.4.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.8.6 // indirect
github.com/hashicorp/consul/api v1.1.0
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
github.com/hashicorp/go-msgpack v0.5.5 // indirect
github.com/hashicorp/vault/api v1.0.4
github.com/hashicorp/go-multierror v1.0.0 // indirect
github.com/hashicorp/go-retryablehttp v0.5.4 // indirect
github.com/hashicorp/go-rootcerts v1.0.1 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/serf v0.8.2 // indirect
github.com/hashicorp/vault/sdk v0.1.13 // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/jonboulle/clockwork v0.1.0 // indirect
github.com/pkg/errors v0.8.1
github.com/kr/pretty v0.1.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/pierrec/lz4 v2.0.5+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829 // indirect
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/soheilhy/cmux v0.1.4 // indirect
github.com/stretchr/testify v1.4.0
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
github.com/ugorji/go v1.1.4 // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
go.etcd.io/bbolt v1.3.2 // indirect
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284 // indirect
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 // indirect
golang.org/x/sys v0.0.0-20190508220229-2d0786266e9c // indirect
gopkg.in/yaml.v2 v2.2.2
golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107 // indirect
google.golang.org/grpc v1.22.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/square/go-jose.v2 v2.3.1 // indirect
)

go 1.12
go 1.23.0
Loading