enum

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Integer = New[PropertyKind](1, "integer")
	String  = New[PropertyKind](2, "string")
	Display = New[PropertyKind](3, "display")
)

Functions

func BitsMerge

func BitsMerge[T any](ss []string) uint32

func BitsSplit

func BitsSplit[T any](d uint32) []string

func BitsTransfer

func BitsTransfer[T any](vs []string) []uint32

func Get

func Get[T any, P enumProperty](v P) (o *T)

Get 获取枚举值常量

func Is

func Is[T any, P enumProperty](v P) bool

Is check whether value v is a valid enum value

func List

func List[T any]() []T

func New

func New[T any](i IntegerType, s ...string) T

New generate EnumClass

func ObjectName

func ObjectName[T any]() string

func StringDict

func StringDict[S any, D any](str string) *D

StringDict 从S到D的枚举映射查询,当前映射的关键是枚举属性String

func Strings

func Strings[T any](p PropertyKind) string

func ToString

func ToString[T any, V enumInteger](i V, defaultValue ...string) string

ToString find the string value of 'i', panic if not the valid enum type or not a valid value, return the defaultValue[0] if not find

func Values

func Values(name string) []string

Values 枚举对象的 String slice,方便参数检查

Types

type IntegerType

type IntegerType int

IntegerType 整形数据 int,为什么这么大,因为有时候,项目会使用位计算 int8很明显不够用,所以使用int, 一般int是32位

func ToInteger

func ToInteger[T any](s string, defaultValue ...IntegerType) IntegerType

ToInteger find the uint8 value of 's' panic if not the valid enum type, return the defaultValue[0] if not find

func (IntegerType) Int

func (ip IntegerType) Int() int

func (IntegerType) Int8

func (ip IntegerType) Int8() int8

func (IntegerType) Int16

func (ip IntegerType) Int16() int16

func (IntegerType) Int32

func (ip IntegerType) Int32() int32

func (IntegerType) Uint

func (ip IntegerType) Uint() uint

func (IntegerType) Uint8

func (ip IntegerType) Uint8() uint8

func (IntegerType) Uint16

func (ip IntegerType) Uint16() uint16

func (IntegerType) Uint32

func (ip IntegerType) Uint32() uint32

type Object

type Object struct {
	Integer *IntegerType // 枚举整形值
	String  string       // 枚举的字符串表示值,英文
	Display string       // 枚举的前端展示值,中文
	// contains filtered or unexported fields
}

Object one enum object

func GetObj

func GetObj[T any, P enumProperty](v P) *Object

GetObj 获取枚举值常量

func Objects

func Objects[T any]() []Object

func Objs

func Objs(name string) []Object

Objs 枚举对象的 String slice,方便参数检查

func Query

func Query[P enumProperty](name string, key P) *Object

func TypeDict

func TypeDict[P enumProperty](s, d string, key P) *Object

TypeDict 从source到dest的枚举映射查询,当前映射的关键是枚举属性是string

type PropertyKind

type PropertyKind Object

Jump to

Keyboard shortcuts

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