package sentio import ( "errors" "strings" ) type Side int const ( LONG Side = iota SHORT ) var sides = map[Side]string{ LONG: "LONG", SHORT: "SHORT", } func (s Side) String() string { side, ok := sides[s] if ok { return side } return "undefined" } func SideFromString(s string) (Side, error) { s = strings.TrimSpace(s) s = strings.ToUpper(s) for side, s2 := range sides { if s == s2 { return side, nil } } return -1, errors.New("unknown Side") }