mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
@@ -87,7 +87,7 @@ type Sitemap struct {
|
||||
Filename string
|
||||
}
|
||||
|
||||
func DecodeSitemap(prototype Sitemap, input map[string]interface{}) Sitemap {
|
||||
func DecodeSitemap(prototype Sitemap, input map[string]any) Sitemap {
|
||||
for key, value := range input {
|
||||
switch key {
|
||||
case "changefreq":
|
||||
@@ -177,7 +177,7 @@ func (s *Server) MatchRedirect(pattern string) Redirect {
|
||||
|
||||
type Headers struct {
|
||||
For string
|
||||
Values map[string]interface{}
|
||||
Values map[string]any
|
||||
}
|
||||
|
||||
type Redirect struct {
|
||||
|
@@ -27,7 +27,7 @@ func TestBuild(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
v := New()
|
||||
v.Set("build", map[string]interface{}{
|
||||
v.Set("build", map[string]any{
|
||||
"useResourceCacheWhen": "always",
|
||||
})
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestBuild(t *testing.T) {
|
||||
|
||||
c.Assert(b.UseResourceCacheWhen, qt.Equals, "always")
|
||||
|
||||
v.Set("build", map[string]interface{}{
|
||||
v.Set("build", map[string]any{
|
||||
"useResourceCacheWhen": "foo",
|
||||
})
|
||||
|
||||
|
@@ -47,7 +47,7 @@ func (c *compositeConfig) GetInt(key string) int {
|
||||
return c.base.GetInt(key)
|
||||
}
|
||||
|
||||
func (c *compositeConfig) Merge(key string, value interface{}) {
|
||||
func (c *compositeConfig) Merge(key string, value any) {
|
||||
c.layer.Merge(key, value)
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func (c *compositeConfig) GetParams(key string) maps.Params {
|
||||
return c.base.GetParams(key)
|
||||
}
|
||||
|
||||
func (c *compositeConfig) GetStringMap(key string) map[string]interface{} {
|
||||
func (c *compositeConfig) GetStringMap(key string) map[string]any {
|
||||
if c.layer.IsSet(key) {
|
||||
return c.layer.GetStringMap(key)
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func (c *compositeConfig) GetStringSlice(key string) []string {
|
||||
return c.base.GetStringSlice(key)
|
||||
}
|
||||
|
||||
func (c *compositeConfig) Get(key string) interface{} {
|
||||
func (c *compositeConfig) Get(key string) any {
|
||||
if c.layer.IsSet(key) {
|
||||
return c.layer.Get(key)
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func (c *compositeConfig) GetString(key string) string {
|
||||
return c.base.GetString(key)
|
||||
}
|
||||
|
||||
func (c *compositeConfig) Set(key string, value interface{}) {
|
||||
func (c *compositeConfig) Set(key string, value any) {
|
||||
c.layer.Set(key, value)
|
||||
}
|
||||
|
||||
|
@@ -67,11 +67,11 @@ func FromFile(fs afero.Fs, filename string) (Provider, error) {
|
||||
|
||||
// FromFileToMap is the same as FromFile, but it returns the config values
|
||||
// as a simple map.
|
||||
func FromFileToMap(fs afero.Fs, filename string) (map[string]interface{}, error) {
|
||||
func FromFileToMap(fs afero.Fs, filename string) (map[string]any, error) {
|
||||
return loadConfigFromFile(fs, filename)
|
||||
}
|
||||
|
||||
func readConfig(format metadecoders.Format, data []byte) (map[string]interface{}, error) {
|
||||
func readConfig(format metadecoders.Format, data []byte) (map[string]any, error) {
|
||||
m, err := metadecoders.Default.UnmarshalToMap(data, format)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -82,7 +82,7 @@ func readConfig(format metadecoders.Format, data []byte) (map[string]interface{}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func loadConfigFromFile(fs afero.Fs, filename string) (map[string]interface{}, error) {
|
||||
func loadConfigFromFile(fs afero.Fs, filename string) (map[string]any, error) {
|
||||
m, err := metadecoders.Default.UnmarshalFileToMap(fs, filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -156,13 +156,13 @@ func LoadConfigFromDir(sourceFs afero.Fs, configDir, environment string) (Provid
|
||||
|
||||
root := item
|
||||
if len(keyPath) > 0 {
|
||||
root = make(map[string]interface{})
|
||||
root = make(map[string]any)
|
||||
m := root
|
||||
for i, key := range keyPath {
|
||||
if i >= len(keyPath)-1 {
|
||||
m[key] = item
|
||||
} else {
|
||||
nm := make(map[string]interface{})
|
||||
nm := make(map[string]any)
|
||||
m[key] = nm
|
||||
m = nm
|
||||
}
|
||||
@@ -203,6 +203,6 @@ func init() {
|
||||
|
||||
// RenameKeys renames config keys in m recursively according to a global Hugo
|
||||
// alias definition.
|
||||
func RenameKeys(m map[string]interface{}) {
|
||||
func RenameKeys(m map[string]any) {
|
||||
keyAliases.Rename(m)
|
||||
}
|
||||
|
@@ -24,12 +24,12 @@ type Provider interface {
|
||||
GetInt(key string) int
|
||||
GetBool(key string) bool
|
||||
GetParams(key string) maps.Params
|
||||
GetStringMap(key string) map[string]interface{}
|
||||
GetStringMap(key string) map[string]any
|
||||
GetStringMapString(key string) map[string]string
|
||||
GetStringSlice(key string) []string
|
||||
Get(key string) interface{}
|
||||
Set(key string, value interface{})
|
||||
Merge(key string, value interface{})
|
||||
Get(key string) any
|
||||
Set(key string, value any)
|
||||
Merge(key string, value any)
|
||||
SetDefaults(params maps.Params)
|
||||
SetDefaultMergeStrategy()
|
||||
WalkParams(walkFn func(params ...KeyParams) bool)
|
||||
|
@@ -84,7 +84,7 @@ type defaultConfigProvider struct {
|
||||
keyCache sync.Map
|
||||
}
|
||||
|
||||
func (c *defaultConfigProvider) Get(k string) interface{} {
|
||||
func (c *defaultConfigProvider) Get(k string) any {
|
||||
if k == "" {
|
||||
return c.root
|
||||
}
|
||||
@@ -133,7 +133,7 @@ func (c *defaultConfigProvider) GetParams(k string) maps.Params {
|
||||
return v.(maps.Params)
|
||||
}
|
||||
|
||||
func (c *defaultConfigProvider) GetStringMap(k string) map[string]interface{} {
|
||||
func (c *defaultConfigProvider) GetStringMap(k string) map[string]any {
|
||||
v := c.Get(k)
|
||||
return maps.ToStringMap(v)
|
||||
}
|
||||
@@ -148,7 +148,7 @@ func (c *defaultConfigProvider) GetStringSlice(k string) []string {
|
||||
return cast.ToStringSlice(v)
|
||||
}
|
||||
|
||||
func (c *defaultConfigProvider) Set(k string, v interface{}) {
|
||||
func (c *defaultConfigProvider) Set(k string, v any) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
@@ -166,7 +166,7 @@ func (c *defaultConfigProvider) Set(k string, v interface{}) {
|
||||
}
|
||||
|
||||
switch vv := v.(type) {
|
||||
case map[string]interface{}, map[interface{}]interface{}, map[string]string:
|
||||
case map[string]any, map[any]any, map[string]string:
|
||||
p := maps.MustToParamsAndPrepare(vv)
|
||||
v = p
|
||||
}
|
||||
@@ -198,7 +198,7 @@ func (c *defaultConfigProvider) SetDefaults(params maps.Params) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *defaultConfigProvider) Merge(k string, v interface{}) {
|
||||
func (c *defaultConfigProvider) Merge(k string, v any) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
k = strings.ToLower(k)
|
||||
@@ -289,7 +289,7 @@ func (c *defaultConfigProvider) Merge(k string, v interface{}) {
|
||||
}
|
||||
|
||||
switch vv := v.(type) {
|
||||
case map[string]interface{}, map[interface{}]interface{}, map[string]string:
|
||||
case map[string]any, map[any]any, map[string]string:
|
||||
p := maps.MustToParamsAndPrepare(vv)
|
||||
v = p
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ func TestDefaultConfigProvider(t *testing.T) {
|
||||
c.Run("Set and get", func(c *qt.C) {
|
||||
cfg := New()
|
||||
var k string
|
||||
var v interface{}
|
||||
var v any
|
||||
|
||||
k, v = "foo", "bar"
|
||||
cfg.Set(k, v)
|
||||
@@ -55,7 +55,7 @@ func TestDefaultConfigProvider(t *testing.T) {
|
||||
c.Run("Set and get map", func(c *qt.C) {
|
||||
cfg := New()
|
||||
|
||||
cfg.Set("foo", map[string]interface{}{
|
||||
cfg.Set("foo", map[string]any{
|
||||
"bar": "baz",
|
||||
})
|
||||
|
||||
@@ -63,14 +63,14 @@ func TestDefaultConfigProvider(t *testing.T) {
|
||||
"bar": "baz",
|
||||
})
|
||||
|
||||
c.Assert(cfg.GetStringMap("foo"), qt.DeepEquals, map[string]interface{}{"bar": string("baz")})
|
||||
c.Assert(cfg.GetStringMap("foo"), qt.DeepEquals, map[string]any{"bar": string("baz")})
|
||||
c.Assert(cfg.GetStringMapString("foo"), qt.DeepEquals, map[string]string{"bar": string("baz")})
|
||||
})
|
||||
|
||||
c.Run("Set and get nested", func(c *qt.C) {
|
||||
cfg := New()
|
||||
|
||||
cfg.Set("a", map[string]interface{}{
|
||||
cfg.Set("a", map[string]any{
|
||||
"B": "bv",
|
||||
})
|
||||
cfg.Set("a.c", "cv")
|
||||
@@ -86,7 +86,7 @@ func TestDefaultConfigProvider(t *testing.T) {
|
||||
"a": "av",
|
||||
})
|
||||
|
||||
cfg.Set("b", map[string]interface{}{
|
||||
cfg.Set("b", map[string]any{
|
||||
"b": "bv",
|
||||
})
|
||||
|
||||
@@ -99,7 +99,7 @@ func TestDefaultConfigProvider(t *testing.T) {
|
||||
|
||||
cfg.Set("a", "av")
|
||||
|
||||
cfg.Set("", map[string]interface{}{
|
||||
cfg.Set("", map[string]any{
|
||||
"a": "av2",
|
||||
"b": "bv2",
|
||||
})
|
||||
@@ -113,7 +113,7 @@ func TestDefaultConfigProvider(t *testing.T) {
|
||||
|
||||
cfg.Set("a", "av")
|
||||
|
||||
cfg.Set("", map[string]interface{}{
|
||||
cfg.Set("", map[string]any{
|
||||
"b": "bv2",
|
||||
})
|
||||
|
||||
@@ -124,14 +124,14 @@ func TestDefaultConfigProvider(t *testing.T) {
|
||||
|
||||
cfg = New()
|
||||
|
||||
cfg.Set("", map[string]interface{}{
|
||||
"foo": map[string]interface{}{
|
||||
cfg.Set("", map[string]any{
|
||||
"foo": map[string]any{
|
||||
"a": "av",
|
||||
},
|
||||
})
|
||||
|
||||
cfg.Set("", map[string]interface{}{
|
||||
"foo": map[string]interface{}{
|
||||
cfg.Set("", map[string]any{
|
||||
"foo": map[string]any{
|
||||
"b": "bv2",
|
||||
},
|
||||
})
|
||||
@@ -145,11 +145,11 @@ func TestDefaultConfigProvider(t *testing.T) {
|
||||
c.Run("Merge default strategy", func(c *qt.C) {
|
||||
cfg := New()
|
||||
|
||||
cfg.Set("a", map[string]interface{}{
|
||||
cfg.Set("a", map[string]any{
|
||||
"B": "bv",
|
||||
})
|
||||
|
||||
cfg.Merge("a", map[string]interface{}{
|
||||
cfg.Merge("a", map[string]any{
|
||||
"B": "bv2",
|
||||
"c": "cv2",
|
||||
})
|
||||
@@ -163,7 +163,7 @@ func TestDefaultConfigProvider(t *testing.T) {
|
||||
|
||||
cfg.Set("a", "av")
|
||||
|
||||
cfg.Merge("", map[string]interface{}{
|
||||
cfg.Merge("", map[string]any{
|
||||
"a": "av2",
|
||||
"b": "bv2",
|
||||
})
|
||||
@@ -176,16 +176,16 @@ func TestDefaultConfigProvider(t *testing.T) {
|
||||
c.Run("Merge shallow", func(c *qt.C) {
|
||||
cfg := New()
|
||||
|
||||
cfg.Set("a", map[string]interface{}{
|
||||
cfg.Set("a", map[string]any{
|
||||
"_merge": "shallow",
|
||||
"B": "bv",
|
||||
"c": map[string]interface{}{
|
||||
"c": map[string]any{
|
||||
"b": "bv",
|
||||
},
|
||||
})
|
||||
|
||||
cfg.Merge("a", map[string]interface{}{
|
||||
"c": map[string]interface{}{
|
||||
cfg.Merge("a", map[string]any{
|
||||
"c": map[string]any{
|
||||
"d": "dv2",
|
||||
},
|
||||
"e": "ev2",
|
||||
@@ -203,20 +203,20 @@ func TestDefaultConfigProvider(t *testing.T) {
|
||||
|
||||
// Issue #8679
|
||||
c.Run("Merge typed maps", func(c *qt.C) {
|
||||
for _, left := range []interface{}{
|
||||
for _, left := range []any{
|
||||
map[string]string{
|
||||
"c": "cv1",
|
||||
},
|
||||
map[string]interface{}{
|
||||
map[string]any{
|
||||
"c": "cv1",
|
||||
},
|
||||
map[interface{}]interface{}{
|
||||
map[any]any{
|
||||
"c": "cv1",
|
||||
},
|
||||
} {
|
||||
cfg := New()
|
||||
|
||||
cfg.Set("", map[string]interface{}{
|
||||
cfg.Set("", map[string]any{
|
||||
"b": left,
|
||||
})
|
||||
|
||||
@@ -235,27 +235,27 @@ func TestDefaultConfigProvider(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
for _, left := range []interface{}{
|
||||
for _, left := range []any{
|
||||
map[string]string{
|
||||
"b": "bv1",
|
||||
},
|
||||
map[string]interface{}{
|
||||
map[string]any{
|
||||
"b": "bv1",
|
||||
},
|
||||
map[interface{}]interface{}{
|
||||
map[any]any{
|
||||
"b": "bv1",
|
||||
},
|
||||
} {
|
||||
for _, right := range []interface{}{
|
||||
for _, right := range []any{
|
||||
map[string]string{
|
||||
"b": "bv2",
|
||||
"c": "cv2",
|
||||
},
|
||||
map[string]interface{}{
|
||||
map[string]any{
|
||||
"b": "bv2",
|
||||
"c": "cv2",
|
||||
},
|
||||
map[interface{}]interface{}{
|
||||
map[any]any{
|
||||
"b": "bv2",
|
||||
"c": "cv2",
|
||||
},
|
||||
@@ -280,12 +280,12 @@ func TestDefaultConfigProvider(t *testing.T) {
|
||||
c.Run("Prevent _merge only maps", func(c *qt.C) {
|
||||
cfg := New()
|
||||
|
||||
cfg.Set("", map[string]interface{}{
|
||||
cfg.Set("", map[string]any{
|
||||
"B": "bv",
|
||||
})
|
||||
|
||||
cfg.Merge("", map[string]interface{}{
|
||||
"c": map[string]interface{}{
|
||||
cfg.Merge("", map[string]any{
|
||||
"c": map[string]any{
|
||||
"_merge": "shallow",
|
||||
"d": "dv2",
|
||||
},
|
||||
@@ -299,7 +299,7 @@ func TestDefaultConfigProvider(t *testing.T) {
|
||||
c.Run("IsSet", func(c *qt.C) {
|
||||
cfg := New()
|
||||
|
||||
cfg.Set("a", map[string]interface{}{
|
||||
cfg.Set("a", map[string]any{
|
||||
"B": "bv",
|
||||
})
|
||||
|
||||
@@ -357,15 +357,15 @@ func TestDefaultConfigProvider(t *testing.T) {
|
||||
|
||||
func BenchmarkDefaultConfigProvider(b *testing.B) {
|
||||
type cfger interface {
|
||||
Get(key string) interface{}
|
||||
Set(key string, value interface{})
|
||||
Get(key string) any
|
||||
Set(key string, value any)
|
||||
IsSet(key string) bool
|
||||
}
|
||||
|
||||
newMap := func() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"a": map[string]interface{}{
|
||||
"b": map[string]interface{}{
|
||||
newMap := func() map[string]any {
|
||||
return map[string]any{
|
||||
"a": map[string]any{
|
||||
"b": map[string]any{
|
||||
"c": 32,
|
||||
"d": 43,
|
||||
},
|
||||
|
@@ -35,7 +35,7 @@ func init() {
|
||||
cfg.Set("languages", lang)
|
||||
cfg.SetDefaultMergeStrategy()
|
||||
|
||||
configHelpers := map[string]interface{}{
|
||||
configHelpers := map[string]any{
|
||||
"mergeStrategy": cfg.Get(""),
|
||||
}
|
||||
return docshelper.DocProvider{"config": configHelpers}
|
||||
|
@@ -147,15 +147,15 @@ func (c Config) CheckAllowedHTTPMethod(method string) error {
|
||||
}
|
||||
|
||||
// ToSecurityMap converts c to a map with 'security' as the root key.
|
||||
func (c Config) ToSecurityMap() map[string]interface{} {
|
||||
func (c Config) ToSecurityMap() map[string]any {
|
||||
// Take it to JSON and back to get proper casing etc.
|
||||
asJson, err := json.Marshal(c)
|
||||
herrors.Must(err)
|
||||
m := make(map[string]interface{})
|
||||
m := make(map[string]any)
|
||||
herrors.Must(json.Unmarshal(asJson, &m))
|
||||
|
||||
// Add the root
|
||||
sec := map[string]interface{}{
|
||||
sec := map[string]any{
|
||||
"security": m,
|
||||
}
|
||||
return sec
|
||||
@@ -196,7 +196,7 @@ func stringSliceToWhitelistHook() mapstructure.DecodeHookFuncType {
|
||||
return func(
|
||||
f reflect.Type,
|
||||
t reflect.Type,
|
||||
data interface{}) (interface{}, error) {
|
||||
data any) (any, error) {
|
||||
|
||||
if t != reflect.TypeOf(Whitelist{}) {
|
||||
return data, nil
|
||||
|
@@ -18,7 +18,6 @@ import (
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
"github.com/gohugoio/hugo/config"
|
||||
|
||||
)
|
||||
|
||||
func TestDecodeConfigFromTOML(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user