mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-24 21:56:05 +02:00
@@ -33,18 +33,18 @@ import (
|
||||
// Unmarshal unmarshals the data given, which can be either a string, json.RawMessage
|
||||
// or a Resource. Supported formats are JSON, TOML, YAML, and CSV.
|
||||
// You can optionally provide an options map as the first argument.
|
||||
func (ns *Namespace) Unmarshal(args ...interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) Unmarshal(args ...any) (any, error) {
|
||||
if len(args) < 1 || len(args) > 2 {
|
||||
return nil, errors.New("unmarshal takes 1 or 2 arguments")
|
||||
}
|
||||
|
||||
var data interface{}
|
||||
var data any
|
||||
decoder := metadecoders.Default
|
||||
|
||||
if len(args) == 1 {
|
||||
data = args[0]
|
||||
} else {
|
||||
m, ok := args[0].(map[string]interface{})
|
||||
m, ok := args[0].(map[string]any)
|
||||
if !ok {
|
||||
return nil, errors.New("first argument must be a map")
|
||||
}
|
||||
@@ -69,7 +69,7 @@ func (ns *Namespace) Unmarshal(args ...interface{}) (interface{}, error) {
|
||||
key += decoder.OptionsKey()
|
||||
}
|
||||
|
||||
return ns.cache.GetOrCreate(key, func() (interface{}, error) {
|
||||
return ns.cache.GetOrCreate(key, func() (any, error) {
|
||||
f := metadecoders.FormatFromMediaType(r.MediaType())
|
||||
if f == "" {
|
||||
return nil, errors.Errorf("MIME %q not supported", r.MediaType())
|
||||
@@ -101,7 +101,7 @@ func (ns *Namespace) Unmarshal(args ...interface{}) (interface{}, error) {
|
||||
|
||||
key := helpers.MD5String(dataStr)
|
||||
|
||||
return ns.cache.GetOrCreate(key, func() (interface{}, error) {
|
||||
return ns.cache.GetOrCreate(key, func() (any, error) {
|
||||
f := decoder.FormatFromContentString(dataStr)
|
||||
if f == "" {
|
||||
return nil, errors.New("unknown format")
|
||||
@@ -111,7 +111,7 @@ func (ns *Namespace) Unmarshal(args ...interface{}) (interface{}, error) {
|
||||
})
|
||||
}
|
||||
|
||||
func decodeDecoder(m map[string]interface{}) (metadecoders.Decoder, error) {
|
||||
func decodeDecoder(m map[string]any) (metadecoders.Decoder, error) {
|
||||
opts := metadecoders.Default
|
||||
|
||||
if m == nil {
|
||||
@@ -144,7 +144,7 @@ func decodeDecoder(m map[string]interface{}) (metadecoders.Decoder, error) {
|
||||
return opts, err
|
||||
}
|
||||
|
||||
func stringToRune(v interface{}) (rune, error) {
|
||||
func stringToRune(v any) (rune, error) {
|
||||
s, err := cast.ToStringE(v)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
Reference in New Issue
Block a user