Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Dec 1, 2023
1 parent 07866f1 commit d5b4c02
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .golangci.yaml
Expand Up @@ -13,10 +13,10 @@ linters-settings:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- importShadow
- unnamedResult
golint:
min-confidence: 0
goimports:
Expand Down
6 changes: 3 additions & 3 deletions internal/encoding/ini/codec.go
Expand Up @@ -19,7 +19,7 @@ type Codec struct {
LoadOptions LoadOptions
}

func (c *Codec) Encode(v map[string]any) ([]byte, error) {
func (c Codec) Encode(v map[string]any) ([]byte, error) {
cfg := ini.Empty()
ini.PrettyFormat = false

Expand Down Expand Up @@ -62,7 +62,7 @@ func (c *Codec) Encode(v map[string]any) ([]byte, error) {
return buf.Bytes(), nil
}

func (c *Codec) Decode(b []byte, v map[string]any) error {
func (c Codec) Decode(b []byte, v map[string]any) error {
cfg := ini.Empty(c.LoadOptions)

err := cfg.Append(b)
Expand Down Expand Up @@ -90,7 +90,7 @@ func (c *Codec) Decode(b []byte, v map[string]any) error {
return nil
}

func (c *Codec) keyDelimiter() string {
func (c Codec) keyDelimiter() string {
if c.KeyDelimiter == "" {
return "."
}
Expand Down
1 change: 0 additions & 1 deletion logger.go
Expand Up @@ -55,7 +55,6 @@ func (n *discardHandler) Enabled(_ context.Context, _ slog.Level) bool {
return false
}

//nolint:gocritic // hugeParam: _ is heavy (288 bytes); consider passing it by pointer
func (n *discardHandler) Handle(_ context.Context, _ slog.Record) error {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion remote/remote.go
Expand Up @@ -44,7 +44,7 @@ func (rc remoteConfigProvider) Watch(rp viper.RemoteProvider) (io.Reader, error)
return bytes.NewReader(resp), nil
}

func (rc remoteConfigProvider) WatchChannel(rp viper.RemoteProvider) (responseCh <-chan *viper.RemoteResponse, quitCh chan bool) {
func (rc remoteConfigProvider) WatchChannel(rp viper.RemoteProvider) (<-chan *viper.RemoteResponse, chan bool) {
cm, err := getConfigManager(rp)
if err != nil {
return nil, nil
Expand Down
4 changes: 1 addition & 3 deletions viper.go
Expand Up @@ -345,7 +345,7 @@ func (v *Viper) resetEncoding() {
}

{
codec := &ini.Codec{
codec := ini.Codec{
KeyDelimiter: v.keyDelim,
LoadOptions: v.iniLoadOptions,
}
Expand Down Expand Up @@ -2153,8 +2153,6 @@ func (v *Viper) SetConfigPermissions(perm os.FileMode) {
}

// IniLoadOptions sets the load options for ini parsing.
//
//nolint:gocritic // hugeParam: in is heavy (114 bytes); consider passing it by pointer
func IniLoadOptions(in ini.LoadOptions) Option {
return optionFunc(func(v *Viper) {
v.iniLoadOptions = in
Expand Down
24 changes: 13 additions & 11 deletions viper_test.go
Expand Up @@ -234,15 +234,17 @@ func initIni() {
}

// initDirs makes directories for testing.
func initDirs(t *testing.T) (root, config string) {
testDirs := []string{`a a`, `b`, `C_`}
config = `improbable`
func initDirs(t *testing.T) (string, string) {
var (
testDirs = []string{`a a`, `b`, `C_`}
config = `improbable`
)

if runtime.GOOS != "windows" {
testDirs = append(testDirs, `d\d`)
}

root = t.TempDir()
root := t.TempDir()

for _, dir := range testDirs {
innerDir := filepath.Join(root, dir)
Expand Down Expand Up @@ -2236,21 +2238,21 @@ func doTestCaseInsensitive(t *testing.T, typ, config string) {
assert.Equal(t, 5, cast.ToInt(Get("ef.lm.p.q")))
}

func newViperWithConfigFile(t *testing.T) (v *Viper, configFile string) {
func newViperWithConfigFile(t *testing.T) (*Viper, string) {
watchDir := t.TempDir()
configFile = path.Join(watchDir, "config.yaml")
configFile := path.Join(watchDir, "config.yaml")
err := os.WriteFile(configFile, []byte("foo: bar\n"), 0o640)
require.NoError(t, err)
v = New()
v := New()
v.SetConfigFile(configFile)
err = v.ReadInConfig()
require.NoError(t, err)
require.Equal(t, "bar", v.Get("foo"))
return v, configFile
}

func newViperWithSymlinkedConfigFile(t *testing.T) (v *Viper, watchDir, configFile string) {
watchDir = t.TempDir()
func newViperWithSymlinkedConfigFile(t *testing.T) (*Viper, string, string) {
watchDir := t.TempDir()
dataDir1 := path.Join(watchDir, "data1")
err := os.Mkdir(dataDir1, 0o777)
require.NoError(t, err)
Expand All @@ -2261,11 +2263,11 @@ func newViperWithSymlinkedConfigFile(t *testing.T) (v *Viper, watchDir, configFi
// now, symlink the tm `data1` dir to `data` in the baseDir
os.Symlink(dataDir1, path.Join(watchDir, "data"))
// and link the `<watchdir>/datadir1/config.yaml` to `<watchdir>/config.yaml`
configFile = path.Join(watchDir, "config.yaml")
configFile := path.Join(watchDir, "config.yaml")
os.Symlink(path.Join(watchDir, "data", "config.yaml"), configFile)
t.Logf("Config file location: %s\n", path.Join(watchDir, "config.yaml"))
// init Viper
v = New()
v := New()
v.SetConfigFile(configFile)
err = v.ReadInConfig()
require.NoError(t, err)
Expand Down

0 comments on commit d5b4c02

Please sign in to comment.