enums

package
v0.0.0-...-1ad5891 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: MIT Imports: 0 Imported by: 0

README

enums

Go Enum and its string representation lib.

Refs

Documentation

Overview

Package enums Go enum and its string representation

Example (Output)
package main

import (
	"fmt"

	"github.com/Akagi201/utilgo/enums"
)

var (
	example enums.Enum
	Alpha   = example.Iota("Alpha")
	Beta    = example.Iota("Beta")

	weekday enums.Enum
	Sunday  = weekday.Iota("Sunday")
	Monday  = weekday.Iota("Monday")
)

func main() {
	fmt.Printf("%s\n", example.String(Alpha))
	fmt.Printf("%s\n", example.String(Beta))
	fmt.Println("=======")
	fmt.Printf("%d\t%d\n", Alpha, Alpha+1)
	fmt.Printf("%s\t%s\n", example.String(Beta-1), example.String(Alpha+1))
	fmt.Println("=======")
	if a, ok := example.Get("Alpha"); ok {
		fmt.Printf("%d: %s\n", a, example.String(a))
	}
	if b, ok := example.Get("Beta"); ok {
		fmt.Printf("%d: %s\n", b, example.String(b))
	}

	fmt.Printf("%d:%s\n", Sunday, weekday.String(Sunday))
	fmt.Printf("%d:%s\n", Monday, weekday.String(Monday))

}
Output:

Alpha
Beta
=======
0	1
Alpha	Beta
=======
0: Alpha
1: Beta
0:Sunday
1:Monday

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Enum

type Enum struct {
	// contains filtered or unexported fields
}

Enum holds the enumerables

func (Enum) Get

func (e Enum) Get(s string) (int, bool)

Get lookup the given string for interal enumerable

func (*Enum) Iota

func (e *Enum) Iota(s string) int

Iota converts string to enumerable, similar to Go's iota

func (Enum) String

func (e Enum) String(v int) string

String turns Enum to its string form

Jump to

Keyboard shortcuts

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