enum

command
v0.0.0-...-ed9fe1d Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2018 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

Enum is a tool to automate the creation of methods for enum types.

Setup:

go get github.com/speedland/go/tools/cmd/enum/

Usage: Define enum type using type alias and values by constants with the type name prefix.

    // my_enum.go

    //go:generate enum -type=MyEnum
    type MyEnum int

    const (
	       MyEnumReady MyEnum = iota
	       MyEnumRunning
	       MyEnumSuccess
	       MyEnumFailure
    )

Then you can generate 4 methos by `go generate` command` to use MyEnum as enum.

  • func ParseMyEnum(s string) (MyEnum, error)
  • func ParseMyEnumOr(s string, e MyEnum) (MyEnum)
  • func (MyEnum) String()
  • func (MyEnum) MarshalJSON() ([]byte, error)
  • func (*MyEnum) UnmarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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