Review changes

This commit is contained in:
Oleksandr Redko 2023-12-01 21:51:58 +02:00 committed by Márk Sági-Kazár
parent f0c4ccd6cd
commit 36a38682ba
6 changed files with 19 additions and 20 deletions

View File

@ -13,10 +13,10 @@ linters-settings:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- importShadow
- unnamedResult
golint:
min-confidence: 0
goimports:

View File

@ -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
@ -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)
@ -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 "."
}

View File

@ -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
}

View File

@ -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

View File

@ -345,7 +345,7 @@ func (v *Viper) resetEncoding() {
}
{
codec := &ini.Codec{
codec := ini.Codec{
KeyDelimiter: v.keyDelim,
LoadOptions: v.iniLoadOptions,
}
@ -2182,8 +2182,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

View File

@ -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_`}
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)
@ -2342,12 +2344,12 @@ 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)
@ -2355,8 +2357,8 @@ func newViperWithConfigFile(t *testing.T) (v *Viper, configFile string) {
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)
@ -2367,11 +2369,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)