Last active
April 17, 2019 18:36
-
-
Save mxygem/078c9247211d089e09b080f01d0256ba to your computer and use it in GitHub Desktop.
go-enum from a value that has 2 hyphens
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| generate: error formatting code main:13:22: expected ';', found '-' (and 8 more errors) | |
| // Code generated by go-enum | |
| // DO NOT EDIT! | |
| package main | |
| import ( | |
| "fmt" | |
| ) | |
| const ( | |
| // EnumHyphensFooBar-Az is a EnumHyphens of type Foo-Bar-Baz | |
| EnumHyphensFooBar-Az EnumHyphens = iota | |
| ) | |
| const _EnumHyphensName = "foo-bar-baz" | |
| var _EnumHyphensNames = []string{ | |
| _EnumHyphensName[0:11], | |
| } | |
| // EnumHyphensNames returns a list of possible string values of EnumHyphens. | |
| func EnumHyphensNames() []string { | |
| tmp := make([]string, len(_EnumHyphensNames)) | |
| copy(tmp, _EnumHyphensNames) | |
| return tmp | |
| } | |
| var _EnumHyphensMap = map[EnumHyphens]string{ | |
| 0: _EnumHyphensName[0:11], | |
| } | |
| // String implements the Stringer interface. | |
| func (x EnumHyphens) String() string { | |
| if str, ok := _EnumHyphensMap[x]; ok { | |
| return str | |
| } | |
| return fmt.Sprintf("EnumHyphens(%d)", x) | |
| } | |
| var _EnumHyphensValue = map[string]EnumHyphens{ | |
| _EnumHyphensName[0:11]: 0, | |
| } | |
| // ParseEnumHyphens attempts to convert a string to a EnumHyphens | |
| func ParseEnumHyphens(name string) (EnumHyphens, error) { | |
| if x, ok := _EnumHyphensValue[name]; ok { | |
| return x, nil | |
| } | |
| return EnumHyphens(0), fmt.Errorf("%s is not a valid EnumHyphens, try [%s]", name, strings.Join(_EnumHyphensNames, ", ")) | |
| } | |
| // MarshalText implements the text marshaller method | |
| func (x *EnumHyphens) MarshalText() ([]byte, error) { | |
| return []byte(x.String()), nil | |
| } | |
| // UnmarshalText implements the text unmarshaller method | |
| func (x *EnumHyphens) UnmarshalText(text []byte) error { | |
| name := string(text) | |
| tmp, err := ParseEnumHyphens(name) | |
| if err != nil { | |
| return err | |
| } | |
| *x = tmp | |
| return nil | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //go:generate go-enum -f=$GOFILE --names --marshal | |
| package main | |
| // EnumHyphens contains an item that has 2+ hyphens | |
| // ENUM(foo-bar-baz) | |
| type EnumHyphens int | |
| func main() {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment