gox

package module
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: May 14, 2021 License: Apache-2.0 Imports: 34 Imported by: 0

README

gox

Golang的基础库,提供各种便捷的方法,包括

  • 字符串
  • 配置
  • 时间处理
  • 基础类型

感谢

jetbrains-variant-4.png

Documentation

Index

Constants

View Source
const (
	// HeaderAcceptLanguage 可接受的语言
	HeaderAcceptLanguage = "Accept-Language"
	// HeaderContentType 请求数据类型
	HeaderContentType = "Content-Type"
	// HeaderAuthorization 授权
	HeaderAuthorization = "Authorization"
	// HeaderContentDisposition 下载时的附件名指定
	HeaderContentDisposition = "Content-disposition"

	// HttpMethodGet GET方法
	HttpMethodGet HttpMethod = "GET"
	// HttpMethodPost POST方法
	HttpMethodPost HttpMethod = "POST"
	// HttpMethodPut PUT方法
	HttpMethodPut HttpMethod = "PUT"
	// HttpMethodDelete DELETE方法
	HttpMethodDelete HttpMethod = "DELETE"
	// HttpMethodPatch PATCH方法
	HttpMethodPatch HttpMethod = "PATCH"
	// HttpMethodHead HEAD方法
	HttpMethodHead HttpMethod = "HEAD"
	// HttpMethodOptions OPTIONS方法
	HttpMethodOptions HttpMethod = "OPTIONS"
)
View Source
const (
	// DefaultTimeLayout 默认的时间布局
	DefaultTimeLayout = "2006-01-02 15:04:05"

	// 时间常量
	// Day 一天
	Day = 24 * time.Hour
	// Week 一周
	Week = 7 * Day
	// Month 一个月
	Month = 30 * Day
	// Year 一年
	Year = 365 * Day
)

Variables

View Source
var (
	// 文件相关
	ErrSrcIsNotFile = &CodeError{ErrorCode: 1002, Message: "源文件不是文件"}

	// 密钥相关
	ErrKeySize = &CodeError{ErrorCode: 2001, Message: "密钥位数有错,必须是8的倍数"}
)
View Source
var (
	// Separate nested key components with dots, e.g. "a.b.1.c.d"
	DotStyle = SeparatorStyle{Middle: "."}

	// Separate with path-like slashes, e.g. a/b/1/c/d
	PathStyle = SeparatorStyle{Middle: "/"}

	// Separate ala Rails, e.g. "a[b][c][1][d]"
	RailsStyle = SeparatorStyle{Before: "[", After: "]"}

	// Separate with underscores, e.g. "a_b_1_c_d"
	UnderscoreStyle = SeparatorStyle{Middle: "_"}
)

Default styles

View Source
var NotValidInputError = errors.New("Not a valid input: map or slice")

Nested input must be a map or slice

View Source
var NotValidJsonInputError = errors.New("Not a valid input, must be a map")

JSON nested input must be a map

View Source
var WeekdayCN = []string{
	"周日",
	"周一",
	"周二",
	"周三",
	"周四",
	"周五",
	"周六",
}

WeekdayCN 中文的星期几

Functions

func CamelName

func CamelName(name string) string

CamelName 下划线写法转为驼峰写法

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

CheckPasswordHash 检查密码的正确性

func ContentDisposition

func ContentDisposition(filename string, dispositionType ContentDispositionType) (disposition string)

ContentDisposition 解决附件下载乱码

func Contract

func Contract(separator string, strings ...string) (result string)

Contract 字符串连接

func CopyFile added in v1.2.0

func CopyFile(src, dst string) (copyFiles []string, err error)

func CreateDir added in v1.2.0

func CreateDir(dirName string) error

func CreateFile added in v1.2.0

func CreateFile(file string) error

func DeleteFile added in v1.2.0

func DeleteFile(src string) (err error)

DeleteFile 删除的文件

func DirNotExistCreate added in v1.2.0

func DirNotExistCreate(path string) (err error)

DirNotExistCreate err为空存在,不会空则

func Flatten

func Flatten(nested map[string]interface{}, prefix string, style SeparatorStyle) (map[string]interface{}, error)

Flatten generates a flat map from a nested one. The original may include values of type map, slice and scalar, but not struct. Keys in the flat map will be a compound of descending map keys and slice iterations. The presentation of keys is set by style. A prefix is joined to each key.

func FlattenString

func FlattenString(nestedStr, prefix string, style SeparatorStyle) (string, error)

FlattenString generates a flat JSON map from a nested one. Keys in the flat map will be a compound of descending map keys and slice iterations. The presentation of keys is set by style. A prefix is joined to each key.

func GetAllFilesBy added in v1.2.0

func GetAllFilesBy(pathName string, ty FileType) (allFiles []string, err error)

func GetContentType added in v1.2.0

func GetContentType(filepath string) (contentType string, err error)

GetContentType 获得文件的ContentType

func GetDirFatherDeep added in v1.2.0

func GetDirFatherDeep(dir string) int

GetDirFatherDeep dir以/开头

func GetDirSonDeep added in v1.2.0

func GetDirSonDeep(dir string) int

func GetFileContentType added in v1.2.0

func GetFileContentType(file *os.File) (contentType string, err error)

GetFileContentType 获得文件的ContentType

func GetFileDir added in v1.2.0

func GetFileDir(filePath string) string

GetFileDir 获得文件的目录形式

func GetFilename added in v1.2.7

func GetFilename(filePath string) string

GetFilename 获得文件名

func GetFilenameWithExt added in v1.2.7

func GetFilenameWithExt(filePath string, ext string) (path string)

GetFilenameWithExt 获得带扩展名的文件名

func GetNeedDeleteFiles added in v1.2.0

func GetNeedDeleteFiles(src string) (deleteFiles []string, err error)

func HashPassword

func HashPassword(password string) (string, error)

HashPassword 生成密码

func HashPasswordWithCost

func HashPasswordWithCost(password string, cost int) (string, error)

HashPasswordWithCost 生成密码

func InitialLowercase

func InitialLowercase(from string) (to string)

InitialLowercase 首字母小写

func IsDir added in v1.2.0

func IsDir(path string) (bool, error)

IsDir 判断所给路径是否为文件夹

func IsFileExist added in v1.2.0

func IsFileExist(filename string) bool

IsFileExist 判断文件是否存在

func IsInArray

func IsInArray(val interface{}, array interface{}) (exists bool, index int)

IsInArray 通用的判断数据是否在数组中

func JSONInit

func JSONInit(db *sql.DB, initializer JSONInitializer, table string, field string) (err error)

JSONInit JSON字段初始化

func JSONString

func JSONString(obj interface{}) string

JSONString 转换成JSON字符串

func ListDir added in v1.2.0

func ListDir(src string) (infos []string, err error)

func MapToStruct

func MapToStruct(model map[string]interface{}, obj interface{}) (err error)

MapToStruct Map转换成结构体

func Md5

func Md5(from string) (to string, err error)

Md5 将字符串加密成Md5字符串

func MoveFile added in v1.2.0

func MoveFile(src, dst string) (err error)

func MySQLJsonInit

func MySQLJsonInit(
	table string, filed string,
	conditionFiled string, conditionValue interface{},
	initField string, initFieldValue interface{},
	paths ...string,
) (sql string, err error)

MySQLJsonInit JSON初始化

func MySQLJsonUpdate

func MySQLJsonUpdate(
	table string, filed string,
	conditionFiled string, conditionValue interface{},
	data map[string]interface{},
) (sql string, err error)

MySQLJsonUpdate 生成MySQL JSON增量更新SQL语句的快捷方式

func MySQLJsonUpdateWithConfig

func MySQLJsonUpdateWithConfig(
	table string, filed string,
	conditionFiled string, conditionValue interface{},
	data map[string]interface{},
	prefix string, style SeparatorStyle,
) (sql string, err error)

MySQLJsonUpdateWithConfig 生成MySQL JSON增量更新SQL语句

func NewJSONSyntaxError

func NewJSONSyntaxError(original []byte) error

NewJSONSyntaxError 创建一个JSON语法错误

func NewPage

func NewPage(items interface{}, totalNum int64, perPage int, page int, extras ...extraPageData) *pageData

NewPage 生成新的分页数据对象

func NewPageExtra added in v1.2.27

func NewPageExtra(key string, value interface{}) *extraPageData

func ParsePackageName

func ParsePackageName(domain string) (name string)

ParsePackageName 从域名解析出包名

func RandString

func RandString(length int) string

RandString 生成随时字符串

func RenameFile added in v1.2.0

func RenameFile(src, dst string) error

func RenderToFile

func RenderToFile(filename string, input string, data interface{}, isFile bool) (err error)

RenderToFile 渲染模板到文件

func SearchString

func SearchString(slice []string, s string) int

SearchString 字符串查询

func Sha256Hmac

func Sha256Hmac(data string, secret string) (sha string, err error)

Sha256Hmac 计算SHA256加密

func StructToMap

func StructToMap(obj interface{}) (model map[string]interface{}, err error)

StructToMap 结构体转换成Map

func SymmetricKey

func SymmetricKey(bits uint) (key []byte, err error)

SymmetricKey 生成对称加密算法密钥

func TruncateDay

func TruncateDay(t time.Time) time.Time

func TruncateUnix

func TruncateUnix(timestamp int64) int64

func UnZip

func UnZip(zipFileName, destFileName string) (err error)

解压

func UnderscoreName

func UnderscoreName(name string, upperInitial bool) string

驼峰式写法转为下划线写法

func ValidFilename added in v1.2.0

func ValidFilename(filename string) bool

ValidFilename 有效文件名(Windows标准)

func ValidFilepath added in v1.2.0

func ValidFilepath(filepath string) bool

ValidFilepath 有效文件夹名

func Zip

func Zip(destFileName string, zipFileNames ...string) (err error)

Zip 压缩文件

Types

type AuthConfig

type AuthConfig struct {
	// Type 授权类型
	Type AuthType `default:"type" json:"type" yaml:"type" validate:"oneof=basic token"`
	// Username 用户名
	Username string `json:"username" yaml:"username"`
	// Password 密码
	Password string `json:"password" yaml:"password"`
	// Token 授权码
	Token string `json:"token" yaml:"token"`
	// Scheme 身份验证方案类型
	Scheme string `json:"scheme" yaml:"scheme"`
}

AuthConfig 授权信息

type AuthType

type AuthType string

AuthType 授权类型

const (
	// AuthTypeBasic 基本Http授权验证
	AuthTypeBasic AuthType = "basic"
	// AuthTypeToken 基本传Token的授权验证
	AuthTypeToken AuthType = "token"
)

type BaseStruct

type BaseStruct struct {
	IdStruct      `xorm:"extends"`
	CreatedStruct `xorm:"extends"`
	UpdatedStruct `xorm:"extends"`
}

BaseStruct 基础数据库模型

type BaseTag

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

BaseTag Tag基础

func (*BaseTag) Contains

func (tag *BaseTag) Contains(option string) (contains bool)

Contains 判断Tag是否包含某个属性

type BaseUser

type BaseUser struct {
	BaseStruct `xorm:"extends"`

	// 用户名
	Username String `xorm:"varchar(32) notnull default('') unique(uidx_name)" json:"username" validate:"omitempty,min=1,max=32,email"`
	// 手机号
	// 类似于+86-17089792784
	Phone String `xorm:"varchar(15) notnull default('') unique(uidx_phone)" json:"phone" validate:"omitempty,mobile"`
	// 密码
	Pwd string `xorm:"varchar(512) notnull default('')" json:"-"`
}

基础用户数据

type CROS added in v1.2.0

type CROS struct {
	AllowOrigins     []string `default:"['*']" yaml:"allowOrigins"`
	AllowCredentials bool     `default:"true" yaml:"allowCredentials"`
}

CROS 跨域配置

type CertificateConfig

type CertificateConfig struct {
	// Skip 是否跳过TLS检查
	Skip bool `default:"true" json:"skip" yaml:"skip"`
	// Root 根秘钥文件路径
	Root string `json:"root" yaml:"root" validate:"required,file"`
	// Clients 客户端
	Clients []ClientCertificate `json:"clients" yaml:"clients" validate:"structonly"`
}

CertificateConfig 秘钥

type CheckConfig added in v1.4.1

type CheckConfig struct {
	// Interval 间隔时间
	Interval time.Duration `json:"interval" yaml:"interval" validate:"required"`
	// Timeout 超时时间
	Timeout time.Duration `json:"timeout" yaml:"timeout" validate:"required"`
	// StartupTimeout 启动时的超时时间
	StartupTimeout time.Duration `json:"startupTimeout" yaml:"startupTimeout" validate:"required"`
}

CheckConfig 检查器配置,可以用于多种场景:健康检查、嗅探器等

type Checksum

type Checksum struct {
	// Sum 校验字符串
	Sum string `json:"sum" validate:"required"`
	// Type 类型
	Type ChecksumType `json:"type" validate:"required,oneof=crc32 crc64 sha1 sha256"`
}

Checksum 数据校验

type ChecksumType

type ChecksumType string

ChecksumType 数据校验合类型

const (
	// ChecksumTypeCrc32 Crc32
	ChecksumTypeCrc32 ChecksumType = "crc32"
	// ChecksumTypeCrc64 Crc64
	ChecksumTypeCrc64 ChecksumType = "crc64"
	// ChecksumTypeSha1 Crc64
	ChecksumTypeSha1 ChecksumType = "sha1"
	// ChecksumTypeSha256 Crc64
	ChecksumTypeSha256 ChecksumType = "sha256"
)

type ClientCertificate

type ClientCertificate struct {
	// Public 公钥文件路径
	Public string `json:"public" yaml:"public" validate:"required,file"`
	// Private 私钥文件路径
	Private string `json:"private" yaml:"private" validate:"required,file"`
}

ClientCertificate 客户端秘钥

type Code

type Code int

Code 消息代码

type CodeError added in v1.2.0

type CodeError struct {
	// ErrorCode 错误码
	ErrorCode ErrorCode `json:"errorCode"`
	// Message 消息
	Message string `json:"message"`
	// Data 数据
	Data interface{} `json:"data"`
}

CodeError 带错误编号和消息的错误

func NewCodeError added in v1.2.0

func NewCodeError(errorCode ErrorCode, message string, data interface{}) *CodeError

NewCodeError 创建错误

func ParseCodeError added in v1.3.15

func ParseCodeError(str string) (ec *CodeError, err error)

ParseCodeError 从JSON字符串中解析错误

func (*CodeError) Error added in v1.2.0

func (ce *CodeError) Error() (str string)

func (*CodeError) ToData added in v1.2.0

func (ce *CodeError) ToData() interface{}

func (*CodeError) ToErrorCode added in v1.2.0

func (ce *CodeError) ToErrorCode() ErrorCode

func (*CodeError) ToMessage added in v1.2.25

func (ce *CodeError) ToMessage() string

type CodeMessage

type CodeMessage struct {
	// Code 消息代码
	Code Code `json:"code"`
	// Title 消息标题
	// 通常是模板字符串
	Title *string `json:"title"`
	// Text 消息内容
	// 通常是模板字符串
	Text *string `json:"text,omitempty"`
}

CodeMessage 带消息代码的消息

func NewCodeMessage

func NewCodeMessage(code Code, title, text string) *CodeMessage

NewCodeMessage 创建消息

func (CodeMessage) ParseText

func (cm CodeMessage) ParseText(params ...interface{}) CodeMessage

ParseText 格式化输出Text,并返回新的消息对象

func (CodeMessage) ParseTitle

func (cm CodeMessage) ParseTitle(params ...interface{}) CodeMessage

ParseTitle 格式化输出Title,并返回新的消息对象

func (CodeMessage) String

func (cm CodeMessage) String() string

String 以字符串的形式打印

func (CodeMessage) ToCode

func (cm CodeMessage) ToCode() Code

ToCode 返回消息代码

type ConnectionConfig added in v1.3.18

type ConnectionConfig struct {
	// MaxOpen 最大打开连接数
	MaxOpen int `default:"150" yaml:"maxOpen" json:"maxOpen"`
	// MaxIdle 最大休眠连接数
	MaxIdle int `default:"30" yaml:"maxIdle" json:"maxIdle"`
	// MaxLifetime 每个连接最大存活时间
	MaxLifetime time.Duration `default:"5s" yaml:"maxLifetime" json:"maxLifetime"`
}

ConnectionConfig 连接池配置

type ContentDispositionType

type ContentDispositionType string

ContentDispositionType 下载类型

const (
	// ContentDispositionTypeAttachment 附件下载
	ContentDispositionTypeAttachment ContentDispositionType = "attachment"
	// ContentDispositionTypeInline 浏览器直接打开
	ContentDispositionTypeInline ContentDispositionType = "inline"
)

type CreatedStruct

type CreatedStruct struct {
	// CreatedAt 创建时间
	CreatedAt Timestamp `xorm:"created default('2020-02-04 09:55:52')" json:"createdAt"`
}

CreatedStruct 带创建时间模型

type DatabaseConfig added in v1.3.18

type DatabaseConfig struct {
	// Type 数据库类型,支持
	Type string `default:"sqlite3" json:"type" yaml:"type"`

	// Address 地址,填写服务器地址
	Address string `default:"127.0.0.1:3306" json:"address" validate:"required"`
	// Username 授权,用户名
	Username string `json:"username,omitempty" yaml:"username"`
	// Password 授权,密码
	Password string `json:"password,omitempty" yaml:"password"`
	// Protocol 协议,默认用Tcp
	Protocol string `default:"tcp" json:"protocol" yaml:"protocol"`
	// Connection 连接池配置
	Connection ConnectionConfig `json:"connection" yaml:"connection"`

	// Suffix 表名的前缀
	Suffix string `json:"suffix" yaml:"suffix"`
	// Prefix 表名后缀
	Prefix string `json:"prefix" yaml:"prefix"`
	// Schema 连接的数据库名
	Schema             string `default:"schema" json:"schema" yaml:"schema"`
	MigrationTableName string `default:"migration" json:"migration_table_name"`
	// Parameters 额外参数
	Parameters string `json:"parameters"`
	// Path SQLite填写数据库文件的路径
	Path string `default:"data.db" json:"path"`
}

DatabaseConfig 数据库配置

func (*DatabaseConfig) Dsn added in v1.3.18

func (dc *DatabaseConfig) Dsn() string

Dsn 取得数据库的DSN

type Debug

type Debug bool

Debug 是否处于调试模式

type DeletedStruct

type DeletedStruct struct {
	// DeletedAt 删除时间,用户软删除
	DeletedAt Timestamp `xorm:"deleted default('2020-02-04 09:55:52')" json:"deletedAt"`
}

DeletedStruct 软删除模型

type Duration

type Duration time.Duration

Duration 弥补标准库不能使用ParseDuration

func (*Duration) Duration

func (d *Duration) Duration() time.Duration

Duration 转换成time.Duration

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON 编码成JSON

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON 解析JSON

type ElasticsearchConfig added in v1.3.18

type ElasticsearchConfig struct {
	// Address 地址
	Address string `json:"address" yaml:"address" validate:"required,uri"`
	// Username 用户名
	Username string `json:"username" yaml:"username"`
	// Password 密码
	Password string `json:"password" yaml:"password"`
	// Health 健康检查配置
	Health CheckConfig `json:"health" yaml:"health" validate:"structonly"`
	// Sniffer 嗅探器配置
	Sniffer CheckConfig `json:"sniffer" yaml:"sniffer" validate:"structonly"`
	// Gzip 配置是否启用压缩
	Gzip bool `default:"false" json:"gzip" yaml:"gzip"`
	// Headers 传输头
	Headers http.Header `json:"headers" yaml:"headers"`
	// Plugins 配置启动时的必备插件
	Plugins []string `json:"plugins" yaml:"plugins"`
}

ElasticsearchConfig 配置

type Environment

type Environment string

Environment 环境类型

const (
	// EnvironmentDev 开发
	EnvironmentDev Environment = "dev"
	// EnvironmentTest 测试
	EnvironmentTest Environment = "test"
	// EnvironmentQa 测试
	EnvironmentQa Environment = "qa"
	// EnvironmentRelease 发布环境
	EnvironmentRelease Environment = "release"
	// EnvironmentProd 生产
	EnvironmentProd Environment = "prod"
	// EnvironmentLocal 本地环境
	EnvironmentLocal Environment = "local"
	// EnvironmentSimulation 模拟请求(不发真实请求到服务器)
	EnvironmentSimulation Environment = "simulation"
)

type Error added in v1.2.0

type Error interface {
	// ToErrorCode 返回错误码
	ToErrorCode() ErrorCode
	// ToMessage 返回错误消息
	ToMessage() string
	// ToData 返回错误实体
	// 在某些错误下,可能需要返回额外的信息给前端处理
	// 比如,认证错误,需要返回哪些字段有错误
	ToData() interface{}
}

Error 接口,符合条件的错误统一处理

type ErrorCode added in v1.2.0

type ErrorCode int

ToErrorCode 错误码

type Field

type Field interface {
	Key
	Value
}

Field 用于描述一个字段(即键值对)

type FileSize added in v1.2.0

type FileSize string

默认大小:B

func (*FileSize) Size added in v1.2.0

func (fs *FileSize) Size() (num int64)

返回多少B

type FileType added in v1.2.0

type FileType int
const (
	// FileTypeAny 任何文件
	FileTypeAny FileType = 0
	// FileTypeDir 目录
	FileTypeDir FileType = 1
	// FileTypeFile 文件
	FileTypeFile FileType = 2
)

type Grpc added in v1.3.14

type Grpc struct {
	// Host 监听的地址,可以是IP也可以是域名
	Host string `json:"ip" yaml:"ip"`
	// Port 监听的端口
	Port int `default:"8081" json:"port" yaml:"port" validate:"required"`
}

Grpc gRPC配置

func (*Grpc) Addr added in v1.3.16

func (g *Grpc) Addr() string

Addr 返回gRPC需要的地址

type HttpClientConfig added in v1.3.18

type HttpClientConfig struct {
	// Timeout 超时
	Timeout time.Duration `json:"timeout" yaml:"timeout"`
	// Proxy 代理
	Proxy ProxyConfig `json:"proxy" yaml:"proxy" validate:"structonly"`
	// Auth 授权配置
	Auth AuthConfig `json:"auth" yaml:"auth" validate:"structonly"`
	// AllowGetPayload 是否允许Get方法传输数据
	AllowGetPayload bool `default:"true" json:"allowGetPayload" yaml:"allowGetPayload"`
	// Certificate 秘钥配置
	Certificate CertificateConfig `json:"certificate" yaml:"certificate" validate:"structonly"`
	// QueryParams 通用的查询参数
	QueryParams map[string]string `json:"queryParams" yaml:"queryParams"`
	// FormData 表单参数,只对POST和PUT方法有效
	FormData map[string]string `json:"formData" yaml:"formData"`
	// Headers 通用头信息
	Headers map[string]string `json:"headers" yaml:"headers"`
	// Cookies 通用Cookie
	Cookies []*http.Cookie `json:"cookies" yaml:"cookies"`
}

HttpClientConfig Http客户端配置

type HttpConfig added in v1.3.18

type HttpConfig struct {
	// Server 服务器配置
	Server HttpServerConfig `json:"server" yaml:"server" validate:"structonly"`
	// Client 客户端配置
	Client HttpClientConfig `json:"client" yaml:"client" validate:"structonly"`
}

HttpConfig Http配置

type HttpHeader

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

HttpHeader Http请求头

func NewHttpHeader

func NewHttpHeader(key string, value string) *HttpHeader

NewHttpHeader 创建一个Http请求头

func (*HttpHeader) Key

func (hh *HttpHeader) Key() string

func (*HttpHeader) Type

func (hh *HttpHeader) Type() HttpParameterType

func (*HttpHeader) Value

func (hh *HttpHeader) Value() string

type HttpMethod

type HttpMethod string

HttpMethod Http方法

type HttpParameter

type HttpParameter interface {
	// Type 类型
	Type() HttpParameterType
	// Key 键
	Key() string
	// Value 值
	Value() string
}

HttpParameter Http额外参数接口

type HttpParameterType

type HttpParameterType string

HttpParameterType Http额外参数类型

const (
	// HttpParameterTypeHeader 请求头
	HttpParameterTypeHeader HttpParameterType = "header"
	// HttpParameterTypePathParameter 路径参数
	HttpParameterTypePathParameter HttpParameterType = "path"
)

type HttpPathParameter

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

HttpPathParameter Http路径参数

func NewHttpPathParameter

func NewHttpPathParameter(key string, value string) *HttpPathParameter

NewHttpPathParameter 创建一个Http路径参数

func (*HttpPathParameter) Key

func (hh *HttpPathParameter) Key() string

func (*HttpPathParameter) Type

func (*HttpPathParameter) Value

func (hh *HttpPathParameter) Value() string

type HttpServerConfig added in v1.3.18

type HttpServerConfig struct {
	// Host 监听的地址,可以是IP也可以是域名
	Host string `default:"0.0.0.0" json:"host" yaml:"host" validate:"required"`
	// Port 监听的端口
	Port int `default:"8080" json:"port" yaml:"port" validate:"required"`
	// BasePath 前缀地址
	BasePath string `yaml:"basePath"`
	// CROS 跨域配置
	CROS CROS
}

HttpServerConfig Http服务器配置

type Id

type Id int64

Id 表示雪花算法生成出来的编号

func ParseBase64

func ParseBase64(str string) (id Id, err error)

ParseBase64 从Base64字符串中解析编号

func ParseBytes

func ParseBytes(bytes []byte) (id Id, err error)

ParseBytes 从二进制数组里面获得编号

func ParseInt64

func ParseInt64(id int64) Id

ParseInt64 从整形获得编号

func ParseIntBytes

func ParseIntBytes(id [8]byte) Id

ParseIntBytes 从二进制数组获得编号

func ParseString

func ParseString(str string) (id Id, err error)

ParseString 从十进制字符串解析编号

func (Id) Base64

func (i Id) Base64() string

Base64 返回编号的Base64字符串

func (Id) Bytes

func (i Id) Bytes() []byte

Bytes 返回二进制数组表示形式

func (Id) Int64

func (i Id) Int64() int64

Int64 返回整形形式

func (Id) IntBytes

func (i Id) IntBytes() [8]byte

IntBytes 返回8位二进制表示形式

func (Id) MarshalJSON

func (i Id) MarshalJSON() ([]byte, error)

func (Id) Node

func (i Id) Node() int64

Node 返回节点数

func (Id) Step

func (i Id) Step() int64

Step 返回当前自增数量

func (Id) String

func (i Id) String() string

String 返回编号的字符串形式

func (Id) Time

func (i Id) Time() int64

Time 返回时间

func (*Id) UnmarshalJSON

func (i *Id) UnmarshalJSON(data []byte) (err error)

type IdStruct

type IdStruct struct {
	// Id 编号
	Id int64 `xorm:"pk notnull unique index('idx_id') default(0)" json:"id,string"`
}

IdStruct 带序列号的模型

func (*IdStruct) Exists

func (is *IdStruct) Exists() bool

Exists 对象是否存在

func (*IdStruct) IdString

func (is *IdStruct) IdString() string

IdString Id的字符串形式

type Int64Slice added in v1.2.0

type Int64Slice []int64

func (*Int64Slice) FromDB added in v1.2.0

func (s *Int64Slice) FromDB(bytes []byte) error

func (Int64Slice) MarshalJSON added in v1.2.0

func (s Int64Slice) MarshalJSON() ([]byte, error)

func (Int64Slice) ToDB added in v1.2.0

func (s Int64Slice) ToDB() ([]byte, error)

func (*Int64Slice) UnmarshalJSON added in v1.2.0

func (s *Int64Slice) UnmarshalJSON(bytes []byte) error

func (*Int64Slice) UnmarshalParam added in v1.2.0

func (s *Int64Slice) UnmarshalParam(src string) error

type JSONFielder

type JSONFielder interface {
	// InitializeField 初始化字段
	InitializeField() string
}

JSONFielder JSON字段

type JSONInitialized

type JSONInitialized struct {
	// Initialized 是否初始化
	Initialized bool `json:"initialized,omitempty"`
}

JSONInitialized JSON是否初始化

func (JSONInitialized) InitializeField

func (ji JSONInitialized) InitializeField() string

func (JSONInitialized) IsInitialized

func (ji JSONInitialized) IsInitialized() bool

type JSONInitializer

type JSONInitializer interface {
	// InitSQL 初始化SQL
	InitSQL(table string, field string) (string, error)
	// IsInitialized 是否已经初始化完成
	IsInitialized() bool
}

JSONInitializer JSON初始化者

type JSONSyntaxError

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

JSONSyntaxError JSON语法错误

func (JSONSyntaxError) Error

func (j JSONSyntaxError) Error() string

type Key

type Key interface {
	// Key 键值
	Key() string
}

Key 键

type MapStruct

type MapStruct interface {
	// ToMap 转换成Map
	StructToMap() (model map[string]interface{}, err error)
	// 转换成结构体
	MapToStruct(model map[string]interface{}) (err error)
}

MapStruct Map和结构体转换

type NamedTag

type NamedTag struct {
	BaseTag
	// contains filtered or unexported fields
}

NamedTag 描述Golang的Tag标记

func NewNamedTag

func NewNamedTag(tagString string) *NamedTag

NewTag 创建新Tag

func (*NamedTag) GetName

func (tag *NamedTag) GetName() string

GetName 获得Tag的名称

type NodeId

type NodeId int64

NodeId 表示一个节点的编号

type Paging

type Paging struct {
	// 当前页
	Page int `default:"1" json:"page" validate:"min=1"`
	// 每页个数
	PerPage int `default:"20" json:"perPage" validate:"min=1"`
	// 查询关键字
	Keyword string `json:"keyword"`
	// 排序顺序
	SortOrder string `default:"DESC" json:"sortOrder" validate:"oneof=asc ASC ascending ASCENDING desc DESC descending DESCENDING"`
}

Paging 分页对象

func (*Paging) Limit

func (p *Paging) Limit() int

Limit 获得限制个数

func (*Paging) MySQL

func (p *Paging) MySQL() (start int, offset int)

MySQL 获得MySQL需要的分页参数

func (*Paging) OrderBy

func (p *Paging) OrderBy(sorter Sorter) string

排序字符串

func (*Paging) Start

func (p *Paging) Start() int

Start 获得开始下标

type ProxyConfig

type ProxyConfig struct {
	// Host 主机(可以是Ip或者域名)
	Host string `json:"ip" yaml:"ip" validate:"required"`
	// Port 端口
	Port int `default:"80" json:"port" yaml:"port" validate:"required"`
	// Scheme 代理类型
	Scheme URIScheme `default:"scheme" json:"scheme" yaml:"type" validate:"required,oneof=socks4 socks5 http https"`
	// Username 代理认证用户名
	Username string `json:"username" yaml:"username"`
	// Password 代理认证密码
	Password string `json:"password" yaml:"password"`
}

ProxyConfig 代理配置

func (*ProxyConfig) Addr

func (p *ProxyConfig) Addr() (addr string)

type RedisConfig added in v1.3.18

type RedisConfig struct {
	// Addr 通信地址
	Addr string `default:"127.0.0.1:6379" json:"addr" yaml:"addr" validate:"required"`
	// Password 授权密码
	Password string `json:"password" yaml:"password"`
	// DB 数据库
	DB int `default:"0" json:"db" yaml:"db"`
}

RedisConfig Redis配置

type Secret

type Secret struct {
	// 授权,相当于用户名
	Id string `json:"id" yaml:"id" validate:"required"`
	// 授权,相当于密码
	Key string `json:"key" yaml:"key" validate:"required"`
}

Secret 描述一个第三方应用授权

type SeparatorStyle

type SeparatorStyle struct {
	Before string // Prepend to key
	Middle string // Add between keys
	After  string // Append to key
}

The style of keys. If there is an input with two nested keys "f" and "g", with "f" at the root,

{ "f": { "g": ... } }

the output will be the concatenation

f{Middle}{Before}g{After}...

Any struct element may be blank. If you use Middle, you will probably leave Before & After blank, and vice-versa. See examples in flatten_test.go and the "Default styles" here.

type Snowflake

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

Snowflake 雪花生成器

func NewSnowflake

func NewSnowflake(node NodeId) (snowflake *Snowflake, err error)

NewSnowflake 创建一个雪花生成器

func (*Snowflake) Next

func (s *Snowflake) Next() (id Id)

Next 返回下一个编号

func (*Snowflake) NextId

func (s *Snowflake) NextId() int64

NextId 下一个长整形Id

func (*Snowflake) NextString

func (s *Snowflake) NextString() string

NextString 下一个字符串形式的Id

type SoftDeleteStruct

type SoftDeleteStruct struct {
	BaseStruct    `xorm:"extends"`
	DeletedStruct `xorm:"extends"`
}

SoftDeleteStruct 带软删除功能的数据库模型

type Sorter

type Sorter interface {
	SortFieldName() string
}

Sorter 排序

type String

type String string

func (*String) FromDB

func (s *String) FromDB(bytes []byte) error

func (String) ToDB

func (s String) ToDB() ([]byte, error)

type StringBuilder added in v1.2.0

type StringBuilder struct {
	*bytes.Buffer
}

StringBuilder 内嵌bytes.StringBuilder,支持连写

func NewStringBuilder added in v1.2.0

func NewStringBuilder() *StringBuilder

func (*StringBuilder) Append added in v1.2.0

func (b *StringBuilder) Append(i interface{}) *StringBuilder

type StringSlice

type StringSlice []string

func (*StringSlice) UnmarshalParam

func (ss *StringSlice) UnmarshalParam(src string) error

type Tagger

type Tagger interface {
	Contains(option string) (contains bool)
}

Tagger 支持Tag的接口

type Timestamp

type Timestamp time.Time

Timestamp 时间戳

func Now

func Now() Timestamp

Now 当前时间

func ParseTimestamp

func ParseTimestamp(time time.Time) Timestamp

ParseTimestamp 从Time对象生成Timestamp

func ZeroTimestamp

func ZeroTimestamp() Timestamp

ZeroTimestamp 0值

func (Timestamp) DayEnd

func (t Timestamp) DayEnd() Timestamp

DayEnd 转换为当天23点59分59秒的Timestamp

func (Timestamp) DayStart

func (t Timestamp) DayStart() Timestamp

DayStart 转换为当天0点0分0秒的Timestamp

func (Timestamp) DefaultTimeLayout

func (t Timestamp) DefaultTimeLayout() string

DefaultTimeLayout 按默认时间布局转换为字符串

func (*Timestamp) GobDecode

func (t *Timestamp) GobDecode(data []byte) (err error)

GobDecode Gob序列化解码

func (Timestamp) GobEncode

func (t Timestamp) GobEncode() ([]byte, error)

GobEncode Gob序列化编码

func (Timestamp) IsZero

func (t Timestamp) IsZero() bool

IsZero 是否是零值

func (Timestamp) MarshalJSON

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

MarshalJSON 序列化成JSON时调用

func (Timestamp) Time

func (t Timestamp) Time() time.Time

Time 取得真实的Time对象

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(b []byte) error

UnmarshalJSON 反序列化成JSON时调用

func (*Timestamp) UnmarshalParam

func (t *Timestamp) UnmarshalParam(src string) error

UnmarshalParam 从Echo参数转换

type URIScheme

type URIScheme string

URIScheme 协议

const (
	// URISchemeSocksV4 Socks协议
	URISchemeSocksV4 URIScheme = "socks4"
	// URISchemeSocksV5 Socks协议
	URISchemeSocksV5 URIScheme = "socks4"
	// URISchemeHttp Socks协议
	URISchemeHttp URIScheme = "http"
	// URISchemeHttps Socks协议
	URISchemeHttps URIScheme = "https"
)

type UpdatedStruct

type UpdatedStruct struct {
	// UpdatedAt 最后更新时间
	UpdatedAt Timestamp `xorm:"updated default('2020-02-04 09:55:52')" json:"updatedAt"`
}

UpdatedStruct 带修改时间模型

type Value

type Value interface {
	// Value 具体的值
	Value() interface{}
}

Value 值

type VideoType added in v1.3.14

type VideoType string

VideoType 视频格式类型

const (
	VideoTypeFlv  VideoType = "flv"
	VideoTypeRtmp VideoType = "rtmp"
	VideoTypeHls  VideoType = "m3u8"
	VideoTypeUdp  VideoType = "flv"
)

type Weekday

type Weekday time.Weekday

Weekday 星期几

func (Weekday) MarshalJSON

func (w Weekday) MarshalJSON() ([]byte, error)

MarshalJSON 编码成JSON

func (Weekday) String

func (w Weekday) String() string

String 返回中文的周几

func (*Weekday) UnmarshalJSON

func (w *Weekday) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON 解析成JSON

func (*Weekday) WeekDay

func (w *Weekday) WeekDay() time.Weekday

Weekday 转换为time.Weekday

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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