Skip to content

Commit

Permalink
use uri from provider string (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktong authored Mar 10, 2024
1 parent 8e289e4 commit e10026b
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 34 deletions.
4 changes: 2 additions & 2 deletions examples/aws/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func Example() {
// Output:
// AppConfig
//
// konf.source has value[AppConfig] that is loaded by loader[AppConfig:konf/test/config.yaml].
// konf.source has value[AppConfig] that is loaded by loader[appconfig://konf/config.yaml].
// Here are other value(loader)s:
// - S3(s3://konf-test/config.yaml)
// - Embedded FS(fs:config/config.yaml)
// - Embedded FS(fs:///config/config.yaml)
}

func loadConfig() {
Expand Down
2 changes: 1 addition & 1 deletion examples/azure/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func Example() {
// konf.source has value[App Configuration] that is loaded by loader[https://konftest.azconfig.io].
// Here are other value(loader)s:
// - Blob Storage(https://konftest.blob.core.windows.net/konf-test/config.yaml)
// - Embedded FS(fs:config/config.yaml)
// - Embedded FS(fs:///config/config.yaml)
}

func loadConfig() {
Expand Down
4 changes: 2 additions & 2 deletions examples/gcp/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func Example() {
// Output:
// Secret Manager
//
// konf.source has value[Secret Manager] that is loaded by loader[SecretManager:konf-test].
// konf.source has value[Secret Manager] that is loaded by loader[secret-manager://konf-test].
// Here are other value(loader)s:
// - GCS(gs://konf-test/config.yaml)
// - Embedded FS(fs:config/config.yaml)
// - Embedded FS(fs:///config/config.yaml)
}

func loadConfig() {
Expand Down
2 changes: 1 addition & 1 deletion provider/appconfig/appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (a *AppConfig) Status(onStatus func(bool, error)) {
}

func (a *AppConfig) String() string {
return "AppConfig:" + a.client.application + "/" + a.client.environment + "/" + a.client.profile
return "appconfig://" + a.client.application + "/" + a.client.profile
}

type clientProxy struct {
Expand Down
2 changes: 1 addition & 1 deletion provider/appconfig/appconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,5 +383,5 @@ func TestAppConfig_String(t *testing.T) {
t.Parallel()

loader := appconfig.New("app", "env", "profile")
assert.Equal(t, "AppConfig:app/env/profile", loader.String())
assert.Equal(t, "appconfig://app/profile", loader.String())
}
6 changes: 1 addition & 5 deletions provider/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,5 @@ func (e Env) Load() (map[string]any, error) {
}

func (e Env) String() string {
if e.prefix == "" {
return "env"
}

return "env:" + e.prefix
return "env:" + e.prefix + "*"
}
4 changes: 2 additions & 2 deletions provider/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ func TestEnv_String(t *testing.T) {
{
description: "with prefix",
prefix: "P_",
expected: "env:P_",
expected: "env:P_*",
},
{
description: "no prefix",
expected: "env",
expected: "env:*",
},
}

Expand Down
8 changes: 7 additions & 1 deletion provider/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"encoding/json"
"fmt"
"os"
"path/filepath"
)

// File is a Provider that loads configuration from a OS file.
Expand Down Expand Up @@ -57,5 +58,10 @@ func (f *File) Load() (map[string]any, error) {
}

func (f *File) String() string {
return "file:" + f.path
path, err := filepath.Abs(f.path)
if err != nil {
path = "file:///" + f.path
}

return "file://" + path
}
5 changes: 4 additions & 1 deletion provider/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package file_test

import (
"errors"
"path/filepath"
"testing"

"github.com/nil-go/konf/provider/file"
Expand Down Expand Up @@ -76,5 +77,7 @@ func TestFile_Load(t *testing.T) {
func TestFile_String(t *testing.T) {
t.Parallel()

assert.Equal(t, "file:config.json", file.New("config.json").String())
path, err := filepath.Abs("config.json")
assert.NoError(t, err)
assert.Equal(t, "file://"+path, file.New("config.json").String())
}
6 changes: 1 addition & 5 deletions provider/flag/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,7 @@ func isZeroValue(flg *flag.Flag) bool {
}

func (f Flag) String() string {
if f.prefix == "" {
return "flag"
}

return "flag:" + f.prefix
return "flag:" + f.prefix + "*"
}

type konf interface {
Expand Down
4 changes: 2 additions & 2 deletions provider/flag/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ func TestFlag_String(t *testing.T) {
{
description: "with prefix",
prefix: "P_",
expected: "flag:P_",
expected: "flag:P_*",
},
{
description: "no prefix",
expected: "flag",
expected: "flag:*",
},
}

Expand Down
2 changes: 1 addition & 1 deletion provider/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ func (f FS) Load() (map[string]any, error) {
}

func (f FS) String() string {
return "fs:" + f.path
return "fs:///" + f.path
}
2 changes: 1 addition & 1 deletion provider/fs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,5 @@ func TestFS_Load(t *testing.T) {
func TestFS_String(t *testing.T) {
t.Parallel()

assert.Equal(t, "fs:config.json", kfs.New(fstest.MapFS{}, "config.json").String())
assert.Equal(t, "fs:///config.json", kfs.New(fstest.MapFS{}, "config.json").String())
}
6 changes: 1 addition & 5 deletions provider/pflag/pflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,7 @@ func flagVal(set *pflag.FlagSet, flag *pflag.Flag) (any, error) {
}

func (f PFlag) String() string {
if f.prefix == "" {
return "pflag"
}

return "pflag:" + f.prefix
return "pflag:" + f.prefix + "*"
}

type konf interface {
Expand Down
4 changes: 2 additions & 2 deletions provider/pflag/pflag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ func TestPFlag_String(t *testing.T) {
{
description: "with prefix",
prefix: "P_",
expected: "pflag:P_",
expected: "pflag:P_*",
},
{
description: "no prefix",
expected: "pflag",
expected: "pflag:*",
},
}

Expand Down
2 changes: 1 addition & 1 deletion provider/secretmanager/secretmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (m *SecretManager) Status(onStatus func(bool, error)) {
}

func (m *SecretManager) String() string {
return "SecretManager:" + m.client.project
return "secret-manager://" + m.client.project
}

type clientProxy struct {
Expand Down
2 changes: 1 addition & 1 deletion provider/secretmanager/secretmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func TestSecretManager_String(t *testing.T) {
t.Parallel()

loader := secretmanager.New(secretmanager.WithProject("test"))
assert.Equal(t, "SecretManager:test", loader.String())
assert.Equal(t, "secret-manager://test", loader.String())
}

type secretManagerService struct {
Expand Down

0 comments on commit e10026b

Please sign in to comment.