Hi there,
I often use enum types defined as int constants. On external/web APIs I'm using Marshal/UnmarshalText to stringify the value. Now I need to store these enums as well but it seems PropertyLoadSaver is not working on non-structs. The documentation is a bit unclear about what types are supported[0]. Is this a bug or a known issue? When I try to store a value of type `TImpl` the program doesn't even panic so I Save/Load is not called at all. This is an issue because I can't use inequality with a single operator(i.e. I need both > and < ) and the database becomes unreadable to other clients. The enums are used as fields on multiple structs so implementing PropertyLoadSaver on each struct is not really easy.
type TImpl struct{
F1 ImplType
}
type ImplType int
const(
Welcome ImplType = "hello"
GoodBye ImplType = "goodby"
)
func(i *ImplType)Save()([]datastore.Property, error){
panic(i)
if *i == 10{
return []datastore.Property{
{
Value: string("hello"),
},
}, nil
}
return nil, errors.New("expected 10, got something else")
}
func (x *ImplType) Load(ps []datastore.Property) error {
panic(x)
if len(ps) != 1{
return errors.New("Multiple properties?")
}
if s, ok := ps[0].Value.(string); ok {
if s == "hello"{
*x = 10
}else{
*x = 1
}
return nil
}
return errors.New("invalid type ")
}
Mihai.
[0] `This type may be a struct pointer, but it does not have to be.`