enum

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package enum 提供对枚举方法的生成

枚举值需要 MarshalText 和 String 等方法,其代码格式基本相同。 当前包提供了自动生成这些方法的方便途径。

用户需要自定义枚举类型和枚举值,当前包只提供了对各类方法的生成。 用户可以采用当前包中的 make_state.go 的方式生成,也可以采用 cmd/enums 命令行生成。

Index

Constants

This section is empty.

Variables

Functions

func StateValidator

func StateValidator(v any) bool

func Write

func Write(file, pkg string, enum ...*Enum) error

Write 输出枚举内容到指定的文件

Types

type Enum

type Enum struct {
	Name     string   // 类型名
	Receiver string   // 方法的接收名
	Fields   []string // 枚举名称,每个名称前会去除类型名前缀
	// contains filtered or unexported fields
}

Enum 定义枚举类型

type State

type State int8

State 测试用

const (
	StateS1 State = iota + 0
	StateS2
)

State 的枚举值

func ParseState

func ParseState(v string) (State, error)

ParseState 将字符串 v 解析为 State 类型

func (State) IsValid

func (t State) IsValid() bool

IsValid 验证该状态值是否有效

func (State) MarshalText

func (t State) MarshalText() ([]byte, error)

MarshalText encoding.TextMarshaler

func (State) String

func (t State) String() string

String fmt.Stringer

func (*State) UnmarshalText

func (t *State) UnmarshalText(p []byte) error

UnmarshalText encoding.TextUnmarshaler

Jump to

Keyboard shortcuts

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