gen

package module
v0.0.0-...-e6e958f Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2022 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code int

Code 自定义INT型类型 通过stringer指令为Code添加了String方法实现 那么直接通过fmt.Println(c)时会调用输出String方法而不是c值本身

const (
	CodeErr        Code = iota + 1 // 错误
	CodeMsg                        // 提示
	CodePwdError                   // 密码错误
	CodeAccError                   // 账户错误
	CodeValidError                 // 参数错误
	CodeToRedirect                 // 跳转至
	CodeSuccess    Code = 500      // 登录成功
	CodeForbidden  Code = 600      // 禁止操作
	CodeNotAllow   Code = 700      // 无操作权限
)

通过为自定义类型Code的值定义时给注释备注而指定该code对应的文案 int_x_gen.go 即为生成的go源码文件,可以看到里面实现了fmt.String接口

func (Code) Code

func (c Code) Code() int

Code 为 Code 类型的值转换数字错误编码提供快捷方法

func (Code) Error

func (c Code) Error() string

Error 为 Code 类型实现 error 接口,这样 Code 类型变量可以直接错误 error 返回契合go语言的返回错误特征

stringer 自动生成为 Code 类型实现了 fmt.Stringer 接口 自动具备 String 方法

func (Code) String

func (i Code) String() string

Jump to

Keyboard shortcuts

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