magnum

command module
v0.0.0-...-9da822e Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2020 License: MIT Imports: 12 Imported by: 0

README

magnum

Go enum generator

Installation

go get github.com/phelmkamp/magnum

Usage

  1. Define a simple struct type

    1. Enumerate values in the struct tag of the name field

      Format is enum:"value[,value2]":

      type Color struct {
          name string `enum:"red,orange,yellow,green,blue,indigo,violet"`
      }
      
    2. (Optional) Enumerate values of other fields with additional struct tags (see house.House)

  2. Run command

    magnum --path=$SRCDIR
    

    Better yet, add the following comment to a file at the root of your source tree (e.g. main.go) and run go generate as part of your build process

    //go:generate magnum
    
  3. That's it!

    An *_enum.go file is generated for each *.go file that has enum tags. This file contains accessors for the enumerated values plus methods to marshal/unmarshal a value to/from text (and JSON).

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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