types

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DB = "db"

Variables

View Source
var (
	// ErrNotSupported 未实现/不支持
	ErrNotSupported = errors.New("not supported")
	// ErrLoginClaim 登录失败
	ErrLoginClaim = errors.New("not valid subject")
	// ErrUnauthorized 未授权
	ErrUnauthorized = errors.New("unauthorized")
	// ErrParamFormat 参数校验失败
	ErrParamFormat = errors.New("not valid param")
	// ErrInvalidUser 用户校验失败
	ErrInvalidUser = errors.New("invalid user")
	//ErrRecordNotNew 不是新记录
	ErrRecordNotNew = errors.New("record not new")
	// ErrRecordNotFound returns a "record not found error".
	ErrRecordNotFound = errors.New("record not found")
	// ErrInvalidSQL occurs when you attempt a query with invalid SQL
	ErrInvalidSQL = errors.New("invalid SQL")
	// ErrInvalidTransaction occurs when you are trying to `Commit` or `Rollback`
	ErrInvalidTransaction = errors.New("no valid transaction")
	// ErrCantStartTransaction can't start transaction when you are trying to start one with `Begin`
	ErrCantStartTransaction = errors.New("can't start transaction")
	// ErrUnaddressable unaddressable value
	ErrUnaddressable = errors.New("using unaddressable value")
	// ErrUnKnown Error UnKnown
	ErrUnKnown = errors.New("UnKnown Error")
)

Functions

func NewError

func NewError(text string) error

func NewRichError

func NewRichError(format string, a ...any) error

Types

type API

type API struct {
	Router *gin.RouterGroup //路由
}

API 结构体

type DataSource

type DataSource struct {
	Dialect  string `yaml:"dialect"`  //数据库类型
	Server   string `yaml:"server"`   ////数据库地址
	Port     int    `yaml:"port"`     //数据库端口
	Database string `yaml:"database"` //数据库名称
	Username string `yaml:"username"` //数据库用户名
	Password string `yaml:"password"` //数据库密码
}

DataSource 数据源

type Entity

type Entity struct {
	CreatedAt times.PrettyTime `json:"CreatedAt" gorm:"COLUMN:created_at"`           //创建时间
	CreatedBy *int64           `json:"CreatedBy" gorm:"COLUMN:created_by"`           //创建者
	UpdatedAt times.PrettyTime `json:"UpdatedAt" gorm:"COLUMN:updated_at"`           //修改时间
	UpdatedBy *int64           `json:"UpdatedBy" gorm:"COLUMN:updated_by"`           //修改者
	DeletedAt gorm.DeletedAt   `json:"DeletedAt,omitempty" gorm:"COLUMN:deleted_at"` //删除时间
	DeletedBy *int64           `json:"DeletedBy,omitempty" gorm:"COLUMN:deleted_by"` //删除者
	Remark    *string          `json:"Remark,omitempty" gorm:"COLUMN:remark"`        //备注
}

Entity 实体类基本模型

type EntityFields

type EntityFields interface {
	Fields() []string
}

EntityFields 实体

type Errors

type Errors []error

Errors contains all happened errors

func (Errors) Add

func (errs Errors) Add(newErrors ...error) Errors

Add adds an error to a given slice of errors

func (Errors) Error

func (errs Errors) Error() string

Error takes a slice of all errors that have occurred and returns it as a formatted string

func (Errors) GetErrors

func (errs Errors) GetErrors() []error

GetErrors gets all errors that have occurred and returns a slice of errors (Error type)

type License

type License struct {
	Signature string                                  `yaml:"signature"`
	Payload   `yaml:",inline" mapstructure:",squash"` //mapstructure 用于viper嵌入结构体
}

License 授权信息

type Log

type Log struct {
	Level      string `yaml:"level"`
	Path       string `yaml:"path"`
	File       string `yaml:"file"`
	MaxSize    int64  `yaml:"maxsize"`
	MaxAge     uint   `yaml:"maxage"`
	MaxBackups uint   `yaml:"maxbackups"`
	MaxCount   uint   `yaml:"maxcount"`
}

type Model

type Model struct {
	CreatedAt times.PrettyTime `json:"CreatedAt" gorm:"COLUMN:created_at"`           //创建时间
	CreatedBy *string          `json:"CreatedBy" gorm:"COLUMN:created_by"`           //创建者
	UpdatedAt times.PrettyTime `json:"UpdatedAt" gorm:"COLUMN:updated_at"`           //修改时间
	UpdatedBy *string          `json:"UpdatedBy" gorm:"COLUMN:updated_by"`           //修改者
	DeletedAt gorm.DeletedAt   `json:"DeletedAt,omitempty" gorm:"COLUMN:deleted_at"` //删除时间
	DeletedBy *string          `json:"DeletedBy,omitempty" gorm:"COLUMN:deleted_by"` //删除者
	Remark    *string          `json:"Remark,omitempty" gorm:"COLUMN:remark"`        //备注
}

Model 实体类基本模型

type Payload

type Payload struct {
	Uid     string `json:"uid" yaml:"uid"`         //产品码
	Product string `json:"product" yaml:"product"` //产品
	Version string `json:"version" yaml:"version"` //版本
	Company string `json:"company" yaml:"company"` //公司
	Expire  string `json:"expire" yaml:"expire"`   //过期时间
	Random  string `json:"random" yaml:"random"`   //随机数
}

Payload 载荷

type RestResult

type RestResult struct {
	Code    uint   `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data"`
}

func Adapt

func Adapt(err error) RestResult

Adapt 自适应

func AdaptData

func AdaptData(data any, err error) RestResult

func Error

func Error(err error, data any) RestResult

func Fail

func Fail(message string, data any) RestResult

func Info

func Info(code uint, message string, data any) RestResult

func Success

func Success(data any) RestResult

type SensitiveString

type SensitiveString struct {
	Sensitive string
}

SensitiveString 敏感信息 ******** ⬛🈲㊙🚫🔒㊙

func (SensitiveString) MarshalJSON

func (t SensitiveString) MarshalJSON() ([]byte, error)

MarshalJSON 写入json时会调用 隐藏敏感数据

func (*SensitiveString) Scan

func (t *SensitiveString) Scan(v any) error

Scan 读取数据库时会调用 valueof 注意是指针类型 method

func (SensitiveString) String

func (t SensitiveString) String() string

func (*SensitiveString) UnmarshalJSON

func (t *SensitiveString) UnmarshalJSON(data []byte) error

UnmarshalJSON 读取json时会调用 序列化为string

func (SensitiveString) Value

func (t SensitiveString) Value() (driver.Value, error)

Value 写入数据库时会调用

type Service

type Service struct {
	DB *gorm.DB //数据库连接
	N  string   //数据库名称
}

Service 服务

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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