enumerate

command module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2025 License: BSD-3-Clause Imports: 1 Imported by: 0

README

Enumerate

Enumerate is a Go tool that collects constants of user defined types and generates slices that contain every exported const for every exported and annotated type.

The tool works on a per file basis, so make sure your constants of a custom type are in the same file as the type declaration.

Usage

Annotate/comment every exported type you want to enumerate with @enumerate, then run

go run github.com/patrickschaffrath/enumerate@latest

at your Go project root directory.

Example

Your project contains my-project/constants.go with

package myproject

type MyString string // @enumerate

const MyStringOne MyString = "one"
const MyStringTwo MyString = "two"

After running the tool, it will generate my-project/enumerated_constants.go with

package myproject

import "slices"

var EnumeratedMyStrings = []MyString{
 MyStringOne,
 MyStringTwo,
}

func IsMyString(a any) bool {
 v, ok := a.(MyString)
 return ok && slices.Contains(EnumeratedMyStrings, v)
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL