Git Product home page Git Product logo

const2enum's Introduction

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
}

const2enum's People

Contributors

vearutop avatar nvcnvn avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.