forked from mitchellh/mapstructure
-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
Look on this small go code
package main
import (
"fmt"
"time"
"github.com/mitchellh/mapstructure"
)
type Record struct {
Date time.Time `json:"date"`
DateP *time.Time `json:"datep"`
Dates []time.Time `json:"dates"`
DatesP []*time.Time `json:"datesp"`
}
func main() {
now := time.Now()
record := Record{
Date: now,
DateP: &now,
Dates: []time.Time{now},
DatesP: []*time.Time{&now},
}
var result map[string]any
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &result,
TagName: "json",
})
if err != nil {
panic(err)
}
if err := decoder.Decode(record); err != nil {
panic(err)
}
fmt.Println(result)
}Result map has all fields except (date) correctly set.
map[
date:map[]
datep:2026-01-12 15:07:35.44162 +0400 +04 m=+0.000086376
dates:[2026-01-12 15:07:35.44162 +0400 +04 m=+0.000086376]
datesp:[2026-01-12 15:07:35.44162 +0400 +04 m=+0.000086376]
]
It seems to be counter intuitive
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels