Open
Description
Describe the feature
So far nobody (not even the documentation) has shown a way to marshal data types.
Describe the solution you'd like
Introduce marshaller interfaces like so:
type INIUnmarshaller interface {
UnmarshalINI([]byte) error
}
type INIMarshaller interface {
MarshalINI([]byte, error)
}
Describe alternatives you've considered
Alternative: Manually load data as string and then convert into custom type
Additional context
Usage:
type Permission int
const (
None Permission = iota
Read Permission
Write
Edit
Group
)
type Config struct {
Foo string
Permission Permission
}
var permToStringMap = map[string]Permission = {
"none": None,
"read": Read,
"write": Write,
"edit": Edit,
"group": Group,
}
func (c *Permission) UnmarshalINI(p []byte) error {
p, ok := permToStringMap[string(p)]
if !ok {
return fmt.Errorf("invalid permission `%v`", p)
}
*c = p
return nil
}
config.ini
permission = "Group"
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity