forked from mirror/viper
build: fix lint violations
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
parent
9af8daeeab
commit
97591f0083
|
@ -7,8 +7,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Logger is a unified interface for various logging use cases and practices, including:
|
// Logger is a unified interface for various logging use cases and practices, including:
|
||||||
// - leveled logging
|
// - leveled logging
|
||||||
// - structured logging
|
// - structured logging
|
||||||
type Logger interface {
|
type Logger interface {
|
||||||
// Trace logs a Trace event.
|
// Trace logs a Trace event.
|
||||||
//
|
//
|
||||||
|
|
57
viper.go
57
viper.go
|
@ -132,10 +132,10 @@ type DecoderConfigOption func(*mapstructure.DecoderConfig)
|
||||||
// DecodeHook returns a DecoderConfigOption which overrides the default
|
// DecodeHook returns a DecoderConfigOption which overrides the default
|
||||||
// DecoderConfig.DecodeHook value, the default is:
|
// DecoderConfig.DecodeHook value, the default is:
|
||||||
//
|
//
|
||||||
// mapstructure.ComposeDecodeHookFunc(
|
// mapstructure.ComposeDecodeHookFunc(
|
||||||
// mapstructure.StringToTimeDurationHookFunc(),
|
// mapstructure.StringToTimeDurationHookFunc(),
|
||||||
// mapstructure.StringToSliceHookFunc(","),
|
// mapstructure.StringToSliceHookFunc(","),
|
||||||
// )
|
// )
|
||||||
func DecodeHook(hook mapstructure.DecodeHookFunc) DecoderConfigOption {
|
func DecodeHook(hook mapstructure.DecodeHookFunc) DecoderConfigOption {
|
||||||
return func(c *mapstructure.DecoderConfig) {
|
return func(c *mapstructure.DecoderConfig) {
|
||||||
c.DecodeHook = hook
|
c.DecodeHook = hook
|
||||||
|
@ -156,18 +156,18 @@ func DecodeHook(hook mapstructure.DecodeHookFunc) DecoderConfigOption {
|
||||||
//
|
//
|
||||||
// For example, if values from the following sources were loaded:
|
// For example, if values from the following sources were loaded:
|
||||||
//
|
//
|
||||||
// Defaults : {
|
// Defaults : {
|
||||||
// "secret": "",
|
// "secret": "",
|
||||||
// "user": "default",
|
// "user": "default",
|
||||||
// "endpoint": "https://localhost"
|
// "endpoint": "https://localhost"
|
||||||
// }
|
// }
|
||||||
// Config : {
|
// Config : {
|
||||||
// "user": "root"
|
// "user": "root"
|
||||||
// "secret": "defaultsecret"
|
// "secret": "defaultsecret"
|
||||||
// }
|
// }
|
||||||
// Env : {
|
// Env : {
|
||||||
// "secret": "somesecretkey"
|
// "secret": "somesecretkey"
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// The resulting config will have the following values:
|
// The resulting config will have the following values:
|
||||||
//
|
//
|
||||||
|
@ -785,7 +785,8 @@ func (v *Viper) searchMapWithPathPrefixes(
|
||||||
// isPathShadowedInDeepMap makes sure the given path is not shadowed somewhere
|
// isPathShadowedInDeepMap makes sure the given path is not shadowed somewhere
|
||||||
// on its path in the map.
|
// on its path in the map.
|
||||||
// e.g., if "foo.bar" has a value in the given map, it “shadows”
|
// e.g., if "foo.bar" has a value in the given map, it “shadows”
|
||||||
// "foo.bar.baz" in a lower-priority map
|
//
|
||||||
|
// "foo.bar.baz" in a lower-priority map
|
||||||
func (v *Viper) isPathShadowedInDeepMap(path []string, m map[string]interface{}) string {
|
func (v *Viper) isPathShadowedInDeepMap(path []string, m map[string]interface{}) string {
|
||||||
var parentVal interface{}
|
var parentVal interface{}
|
||||||
for i := 1; i < len(path); i++ {
|
for i := 1; i < len(path); i++ {
|
||||||
|
@ -810,7 +811,8 @@ func (v *Viper) isPathShadowedInDeepMap(path []string, m map[string]interface{})
|
||||||
// isPathShadowedInFlatMap makes sure the given path is not shadowed somewhere
|
// isPathShadowedInFlatMap makes sure the given path is not shadowed somewhere
|
||||||
// in a sub-path of the map.
|
// in a sub-path of the map.
|
||||||
// e.g., if "foo.bar" has a value in the given map, it “shadows”
|
// e.g., if "foo.bar" has a value in the given map, it “shadows”
|
||||||
// "foo.bar.baz" in a lower-priority map
|
//
|
||||||
|
// "foo.bar.baz" in a lower-priority map
|
||||||
func (v *Viper) isPathShadowedInFlatMap(path []string, mi interface{}) string {
|
func (v *Viper) isPathShadowedInFlatMap(path []string, mi interface{}) string {
|
||||||
// unify input map
|
// unify input map
|
||||||
var m map[string]interface{}
|
var m map[string]interface{}
|
||||||
|
@ -835,7 +837,8 @@ func (v *Viper) isPathShadowedInFlatMap(path []string, mi interface{}) string {
|
||||||
// isPathShadowedInAutoEnv makes sure the given path is not shadowed somewhere
|
// isPathShadowedInAutoEnv makes sure the given path is not shadowed somewhere
|
||||||
// in the environment, when automatic env is on.
|
// in the environment, when automatic env is on.
|
||||||
// e.g., if "foo.bar" has a value in the environment, it “shadows”
|
// e.g., if "foo.bar" has a value in the environment, it “shadows”
|
||||||
// "foo.bar.baz" in a lower-priority map
|
//
|
||||||
|
// "foo.bar.baz" in a lower-priority map
|
||||||
func (v *Viper) isPathShadowedInAutoEnv(path []string) string {
|
func (v *Viper) isPathShadowedInAutoEnv(path []string) string {
|
||||||
var parentKey string
|
var parentKey string
|
||||||
for i := 1; i < len(path); i++ {
|
for i := 1; i < len(path); i++ {
|
||||||
|
@ -856,11 +859,11 @@ func (v *Viper) isPathShadowedInAutoEnv(path []string) string {
|
||||||
// would return a string slice for the key if the key's type is inferred by
|
// would return a string slice for the key if the key's type is inferred by
|
||||||
// the default value and the Get function would return:
|
// the default value and the Get function would return:
|
||||||
//
|
//
|
||||||
// []string {"a", "b", "c"}
|
// []string {"a", "b", "c"}
|
||||||
//
|
//
|
||||||
// Otherwise the Get function would return:
|
// Otherwise the Get function would return:
|
||||||
//
|
//
|
||||||
// "a b c"
|
// "a b c"
|
||||||
func SetTypeByDefaultValue(enable bool) { v.SetTypeByDefaultValue(enable) }
|
func SetTypeByDefaultValue(enable bool) { v.SetTypeByDefaultValue(enable) }
|
||||||
|
|
||||||
func (v *Viper) SetTypeByDefaultValue(enable bool) {
|
func (v *Viper) SetTypeByDefaultValue(enable bool) {
|
||||||
|
@ -1137,9 +1140,8 @@ func (v *Viper) BindPFlags(flags *pflag.FlagSet) error {
|
||||||
// BindPFlag binds a specific key to a pflag (as used by cobra).
|
// BindPFlag binds a specific key to a pflag (as used by cobra).
|
||||||
// Example (where serverCmd is a Cobra instance):
|
// Example (where serverCmd is a Cobra instance):
|
||||||
//
|
//
|
||||||
// serverCmd.Flags().Int("port", 1138, "Port to run Application server on")
|
// serverCmd.Flags().Int("port", 1138, "Port to run Application server on")
|
||||||
// Viper.BindPFlag("port", serverCmd.Flags().Lookup("port"))
|
// Viper.BindPFlag("port", serverCmd.Flags().Lookup("port"))
|
||||||
//
|
|
||||||
func BindPFlag(key string, flag *pflag.Flag) error { return v.BindPFlag(key, flag) }
|
func BindPFlag(key string, flag *pflag.Flag) error { return v.BindPFlag(key, flag) }
|
||||||
|
|
||||||
func (v *Viper) BindPFlag(key string, flag *pflag.Flag) error {
|
func (v *Viper) BindPFlag(key string, flag *pflag.Flag) error {
|
||||||
|
@ -1972,9 +1974,10 @@ func (v *Viper) AllKeys() []string {
|
||||||
|
|
||||||
// flattenAndMergeMap recursively flattens the given map into a map[string]bool
|
// flattenAndMergeMap recursively flattens the given map into a map[string]bool
|
||||||
// of key paths (used as a set, easier to manipulate than a []string):
|
// of key paths (used as a set, easier to manipulate than a []string):
|
||||||
// - each path is merged into a single key string, delimited with v.keyDelim
|
// - each path is merged into a single key string, delimited with v.keyDelim
|
||||||
// - if a path is shadowed by an earlier value in the initial shadow map,
|
// - if a path is shadowed by an earlier value in the initial shadow map,
|
||||||
// it is skipped.
|
// it is skipped.
|
||||||
|
//
|
||||||
// The resulting set of paths is merged to the given shadow set at the same time.
|
// The resulting set of paths is merged to the given shadow set at the same time.
|
||||||
func (v *Viper) flattenAndMergeMap(shadow map[string]bool, m map[string]interface{}, prefix string) map[string]bool {
|
func (v *Viper) flattenAndMergeMap(shadow map[string]bool, m map[string]interface{}, prefix string) map[string]bool {
|
||||||
if shadow != nil && prefix != "" && shadow[prefix] {
|
if shadow != nil && prefix != "" && shadow[prefix] {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil" //nolint:staticcheck
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
@ -998,7 +998,7 @@ func TestBindPFlags(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: dupl
|
//nolint:dupl
|
||||||
func TestBindPFlagsStringSlice(t *testing.T) {
|
func TestBindPFlagsStringSlice(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
Expected []string
|
Expected []string
|
||||||
|
@ -1046,7 +1046,7 @@ func TestBindPFlagsStringSlice(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: dupl
|
//nolint:dupl
|
||||||
func TestBindPFlagsStringArray(t *testing.T) {
|
func TestBindPFlagsStringArray(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
Expected []string
|
Expected []string
|
||||||
|
@ -1094,7 +1094,7 @@ func TestBindPFlagsStringArray(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: dupl
|
//nolint:dupl
|
||||||
func TestBindPFlagsIntSlice(t *testing.T) {
|
func TestBindPFlagsIntSlice(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
Expected []int
|
Expected []int
|
||||||
|
|
Loading…
Reference in New Issue