Skip to content

vearutop/const2map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

const2map

A Go tool to auto generate reflective maps for your enums

Fork

This is a fork of stringer changed to generate a map of names and values instead of String() string.

The purpose is to workaround missing reflection capabilities to access constants names.

Installation

go get github.com/vearutop/const2map

Usage

Having day.go with this contents:

//go:generate const2map -type=Day

type Day int
const (
	Monday Day = iota
	Tuesday
	Wednesday
	Thursday
	Friday
	Saturday
	Sunday
)

After running go generate you will get day_c2m_gen.go

const _Day_name = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday"

var _Day_map = map[Day]string{
	0: _Day_name[0:6],
	1: _Day_name[6:13],
	2: _Day_name[13:22],
	3: _Day_name[22:30],
	4: _Day_name[30:36],
	5: _Day_name[36:44],
	6: _Day_name[44:50],
}

func (i Day) GetMap() map[Day]string {
	return _Day_map
}

About

A Go tool to auto generate reflective maps for your enums

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages