mirror of
https://github.com/spf13/viper.git
synced 2024-04-21 12:31:38 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca55de9785 | ||
|
|
9154b900c3 | ||
|
|
08e4a00949 |
@@ -24,7 +24,7 @@ jobs:
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
|
||||
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
|
||||
with:
|
||||
go-version: '1.21'
|
||||
|
||||
@@ -52,7 +52,7 @@ jobs:
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
|
||||
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
|
||||
with:
|
||||
go-version: ${{ matrix.go }}
|
||||
|
||||
@@ -73,7 +73,7 @@ jobs:
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
|
||||
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
|
||||
with:
|
||||
go-version: '1.21'
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ jobs:
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@407ffafae6a767df3e0230c3df91b6443ae8df75 # v2.22.8
|
||||
uses: github/codeql-action/init@c0d1daa7f7e14667747d73a7dbbe8c074bc8bfe2 # v2.22.9
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
@@ -54,7 +54,7 @@ jobs:
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@407ffafae6a767df3e0230c3df91b6443ae8df75 # v2.22.8
|
||||
uses: github/codeql-action/autobuild@c0d1daa7f7e14667747d73a7dbbe8c074bc8bfe2 # v2.22.9
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
@@ -68,5 +68,5 @@ jobs:
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@407ffafae6a767df3e0230c3df91b6443ae8df75 # v2.22.8
|
||||
uses: github/codeql-action/analyze@c0d1daa7f7e14667747d73a7dbbe8c074bc8bfe2 # v2.22.9
|
||||
|
||||
|
||||
@@ -1127,6 +1127,13 @@ func (v *Viper) Unmarshal(rawVal any, opts ...DecoderConfigOption) error {
|
||||
func (v *Viper) decodeStructKeys(input any, opts ...DecoderConfigOption) ([]string, error) {
|
||||
var structKeyMap map[string]any
|
||||
|
||||
rv := reflect.ValueOf(input)
|
||||
for rv.Kind() == reflect.Ptr {
|
||||
rv = reflect.Indirect(rv)
|
||||
}
|
||||
|
||||
input = rv.Interface()
|
||||
|
||||
err := decode(input, defaultDecoderConfig(&structKeyMap, opts...))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1080,6 +1080,48 @@ func TestUnmarshalWithAutomaticEnv(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestUnmarshalIndirection(t *testing.T) {
|
||||
v := New()
|
||||
|
||||
v.Set("foo", "bar")
|
||||
|
||||
type config struct {
|
||||
Foo string
|
||||
}
|
||||
|
||||
var C config
|
||||
|
||||
CC := &C
|
||||
CCC := &CC
|
||||
|
||||
err := v.Unmarshal(&CCC)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, config{"bar"}, C)
|
||||
}
|
||||
|
||||
func TestUnmarshalInterface(t *testing.T) {
|
||||
v := New()
|
||||
|
||||
v.Set("foo", "bar")
|
||||
|
||||
type someInterface interface {
|
||||
Foo() string
|
||||
}
|
||||
|
||||
type config struct {
|
||||
Foo string
|
||||
Fooer someInterface
|
||||
}
|
||||
|
||||
var C config
|
||||
|
||||
err := v.Unmarshal(&C)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, config{Foo: "bar"}, C)
|
||||
}
|
||||
|
||||
func TestBindPFlags(t *testing.T) {
|
||||
v := New() // create independent Viper object
|
||||
flagSet := pflag.NewFlagSet("test", pflag.ContinueOnError)
|
||||
|
||||
Reference in New Issue
Block a user