{"id":16440795,"url":"https://github.com/idevelopthings/go-enum","last_synced_at":"2025-02-26T01:25:34.580Z","repository":{"id":154439021,"uuid":"631753851","full_name":"iDevelopThings/go-enum","owner":"iDevelopThings","description":"GoLang enum code generator","archived":false,"fork":false,"pushed_at":"2023-04-24T09:32:55.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-08T15:07:58.090Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iDevelopThings.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-24T01:30:30.000Z","updated_at":"2023-04-24T01:30:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"38182470-4ca3-4b85-98f9-8632232182a3","html_url":"https://github.com/iDevelopThings/go-enum","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Fgo-enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Fgo-enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Fgo-enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Fgo-enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iDevelopThings","download_url":"https://codeload.github.com/iDevelopThings/go-enum/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240774184,"owners_count":19855351,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T09:13:04.981Z","updated_at":"2025-02-26T01:25:34.387Z","avatar_url":"https://github.com/iDevelopThings.png","language":"Go","readme":"# go-enum\n\ngo-enum is a simple and powerful Golang code generator for creating type-safe and human-readable enums. It allows you to define your enums using either struct tags or a simple comment structure. The\ngenerated code provides an easy-to-use API for interacting with your enums.\n\n## Installation\n\nTo install the idevelopthings/go-enum package, simply run:\n\n```bash\ngo get -u github.com/iDevelopThings/go-enum\n```\n\n## Usage\n\nCreate a Go file containing your enum definitions using either of the two supported formats: struct tags or comments. Then use the go:generate directive to run the go-enum code generator.\n\n### Struct Tags Format\n\n```go\n//go:generate go run github.com/iDevelopThings/go-enum -types=MyEnumName,MyOtherEnum -output=my_enums.gen.go -input=my_enums.go\n\ntype MyEnumName struct {\n    SomeEnumValue string `name:\"Special\" description:\"It's a special value with a special name\"`\n    // It's another special value... with a description defined via comment\n    AnotherSpecialValue string\n}\n```\n\n### Comments Format\n\n```go\n// Start:MyOtherEnum\n\n// Name: SomeEnumValue\n// It's a special value with a special name\n\n// Name: AnotherSpecialValue\n// It's another special value... with a description defined via comment\n\n// End:MyOtherEnum\n```\n\n# Generated API\n\nThe generated file contains enums with a consistent API, making it simple for you to use the generated enums in your code.\n\n## Enum Type\nEach generated enum type (e.g., MyName and MyOther) has an embedded Enum[string] field containing the enum value, name, and description. The enum type also has a GetAll() method that returns a\ncontainer object containing all enum values.\n\n## Enum Container\nThe container object (e.g., MyNamesContainer and MyOthersContainer) is a struct that holds a map and a slice of all enum values. It also contains named fields for each enum value for easy access.\n\n## Accessing Enum Values\nYou can access the enum values through the container object, for example:\n\n```go\nmyEnumValue := MyNames.SomeEnumValue\nmyOtherEnumValue := MyOthers.AnotherSpecialValue\n```\n\n## Enum Properties\n\nYou can access the properties of each enum value, such as its name, value, and description:\n\n```go\nfmt.Println(myEnumValue.Name) // Output: \"SomeEnumValue\"\nfmt.Println(myEnumValue.Value) // Output: \"Special\"\nfmt.Println(myEnumValue.Description) // Output: \"It's a special value with a special name\"\n```\n\n## Enum Container Properties\n\nYou can access the slice and map of all enum values using the EnumContainer:\n\n```go\nfmt.Println(MyNames.EnumContainer.Values) // Output: A slice of all MyName enum values\nfmt.Println(MyNames.EnumContainer.Map) // Output: A map of all MyName enum values, keyed by their names\n```\n\n## Iterate Over Enum Values\n\nYou can iterate over all enum values using a loop:\n\n```go\nfor _, myEnum := range MyNames.EnumContainer.Values {\n    fmt.Println(myEnum.Name, myEnum.Value, myEnum.Description)\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidevelopthings%2Fgo-enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidevelopthings%2Fgo-enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidevelopthings%2Fgo-enum/lists"}