package main
import (
"log"
"github.com/go-ini/ini"
)
var iniOK = []byte(`string = string
uint32 = 1
`)
var iniBad = []byte(`string = string
uint32 = 0
`)
type myStruct struct {
String string `ini:"string"`
UInt32 uint32 `ini:"uint32"`
}
func main() {
cfg, err := ini.Load(iniOK)
if err != nil {
log.Fatalf("Failed to load ini: %s", err)
}
my := &myStruct{}
if err = cfg.Section("").MapTo(my); err != nil {
log.Fatalf("Failed to map: %s", err)
}
log.Printf("UInt32 value = %d", my.UInt32)
cfg, err = ini.Load(iniBad)
if err != nil {
log.Fatalf("Failed to load ini: %s", err)
}
my = &myStruct{}
if err = cfg.Section("").MapTo(my); err != nil {
log.Fatalf("Failed to map: %s", err)
}
log.Printf("UInt32 value = %d", my.UInt32)
}
2016/08/11 15:27:10 UInt32 value = 1
panic: reflect.Set: value of type time.Duration is not assignable to type uint32
goroutine 1 [running]:
panic(0x510780, 0xc82000a5b0)
/usr/local/go/src/runtime/panic.go:481 +0x3e6
reflect.Value.assignTo(0x556000, 0xc82000a5a0, 0x86, 0x578af0, 0xb, 0x510900, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/reflect/value.go:2164 +0x3be
reflect.Value.Set(0x510900, 0xc82000e6d0, 0x18a, 0x556000, 0xc82000a5a0, 0x86)
/usr/local/go/src/reflect/value.go:1334 +0x95
github.com/go-ini/ini.setWithProperType(0x7f9148f480a8, 0x510900, 0xc820010480, 0x510900, 0xc82000e6d0, 0x18a, 0x570c28, 0x1, 0x0, 0x0)
/home/hhecker/go/src/github.com/go-ini/ini/struct.go:166 +0x651
github.com/go-ini/ini.(*Section).mapTo(0xc820012280, 0x547660, 0xc82000e6c0, 0x199, 0x0, 0x0)
/home/hhecker/go/src/github.com/go-ini/ini/struct.go:232 +0x57c
github.com/go-ini/ini.(*Section).MapTo(0xc820012280, 0x502420, 0xc82000e6c0, 0x0, 0x0)
/home/hhecker/go/src/github.com/go-ini/ini/struct.go:251 +0x1d7
main.main()
/home/hhecker/ini-uint32-not-time.go:37 +0x569
exit status 2