package sentio import ( "fmt" "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 ParseSide(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, fmt.Errorf("`sentio.ParseSide`: undefined Side `%s`", s) }