gox

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: Apache-2.0 Imports: 19 Imported by: 25

README

gox

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

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

感谢Jetbrains

本项目通过Jetbrains开源许可IDE编写源代码,特此感谢

Jetbrains图标

Documentation

Index

Constants

View Source
const (
	// CasePositionNone 无
	CasePositionNone casePosition = iota
	// CasePositionHead 首
	CasePositionHead
	// CasePositionTail 尾
	CasePositionTail
	// CasePositionAll 全部
	CasePositionAll
)
View Source
const (
	// StringEmpty 空字符串
	StringEmpty = ""
	StringSpace = " "

	// Float64Size 64位长度
	Float64Size = 64
)
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 (
	SizeB  Size = 1
	SizeKB      = 1024 * SizeB
	SizeMB      = 1024 * SizeKB
	SizeGB      = 1024 * SizeMB
	SizeTB      = 1024 * SizeGB
	SizePB      = 1024 * SizeTB
	SizeEB      = 1024 * SizePB
)

Variables

This section is empty.

Functions

func Atoi

func Atoi(num string, base int) int64

Atoi 增强版进制转换,支持任意进制,最大76进制

func Atoid added in v0.0.7

func Atoid(num string) int64

Atoid 进制转换,默认使用76进制

func ContentDisposition

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

ContentDisposition 解决附件下载乱码

func Flat added in v0.1.3

func Flat[T flatType](from T) *flatConverter[T]

func FormatInt

func FormatInt(num int64, base int) string

FormatInt 增强版进制转换,最大支持76进制

func FormatIntd added in v0.0.7

func FormatIntd(num int64) string

FormatIntd 进制转换,默认使用76进制

func Gid

func Gid() (id uint64)

Gid 当前协程编号

func If added in v0.1.3

func If[T any](test bool, first T, second T) (t T)

If 模拟三元表达式

func Index added in v0.1.3

func Index[T any](items *[]T, item T) (index int)

Index 在列表中找出元素的下标

func Md5

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

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

func RenderToFile

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

RenderToFile 渲染模板到文件

func Set added in v0.1.3

func Set[T any](setter func(value T), first T, second T)

Set 设置方法,当`first`值为零值时,设置为`second`的值,否则设置`first`的值

func Sha256Hmac

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

Sha256Hmac 计算SHA256加密

func SymmetricKey

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

SymmetricKey 生成对称加密算法密钥

Types

type CannotCompare

type CannotCompare [0]func()

CannotCompare 不能比较

type CannotCopy

type CannotCopy [0]sync.Mutex

CannotCopy 不能复制

type Case added in v0.1.3

type Case string

Case 字符串转换

func (*Case) Camel added in v0.1.3

func (c *Case) Camel(upperPos casePosition) *Case

Camel 转为驼峰写法

func (*Case) Lowercase added in v0.1.6

func (c *Case) Lowercase(pos casePosition) *Case

Lowercase 首字母小写

func (*Case) String added in v0.1.5

func (c *Case) String() string

String 最终结果

func (*Case) Underscore added in v0.1.3

func (c *Case) Underscore(upperPos casePosition) *Case

Underscore 转为下划线写法

type ContentDispositionType

type ContentDispositionType string

ContentDispositionType 下载类型

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

type Created added in v0.1.3

type Created struct {
	// 创建时间
	Created time.Time `xorm:"created default('2020-02-04 09:55:52')" json:"created"`
}

Created 带创建时间模型

type Deleted added in v0.1.3

type Deleted struct {
	// 删除时间,用户软删除
	Deleted time.Time `xorm:"deleted default('2020-02-04 09:55:52')" json:"deleted"`
}

Deleted 软删除模型

type Field

type Field[T any] Kv[string, T]

Field 字段,一个键值对,要求键必须是字符串

type Fields

type Fields[T any] []Field[T]

Fields 字段列表

func (Fields[T]) Connect

func (f Fields[T]) Connect(field Field[T]) (new Fields[T])

Connect 连接其它字段

func (Fields[T]) Connects

func (f Fields[T]) Connects(fields ...Field[T]) (new Fields[T])

Connects 连接其它字段

func (Fields[T]) Fields

func (f Fields[T]) Fields() Fields[T]

Fields 支持自身连写

func (Fields[T]) String

func (f Fields[T]) String() string

type HttpMethod

type HttpMethod string

HttpMethod Http方法

type HttpParameterType

type HttpParameterType string

HttpParameterType Http额外参数类型

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

type Id

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

Id 带序列号的模型

func (*Id) Exists added in v0.1.3

func (i *Id) Exists() bool

func (*Id) IdString added in v0.1.3

func (i *Id) IdString() string

type Key

type Key[T any] interface {
	// Key 返回键值
	Key() T
}

Key 键

type Kv added in v0.1.3

type Kv[K any, V any] interface {
	Key[K]
	Value[V]
}

Kv 键值对

type Model added in v0.1.3

type Model struct {
	Id      `xorm:"extends"`
	Created `xorm:"extends"`
	Updated `xorm:"extends"`
}

Model 基础数据库模型

type Object added in v0.1.3

type Object struct{}

Object 基础对象

type Package added in v0.1.3

type Package string

Package 包名

func (*Package) Name added in v0.1.3

func (p *Package) Name() (name string)

func (*Package) String added in v0.1.3

func (p *Package) String() string

type Size

type Size int64

Size 字节大小

func ParseSize added in v0.0.7

func ParseSize(from string) (size Size, err error)

ParseSize 解析字节大小

func (*Size) Bit added in v0.1.5

func (s *Size) Bit() int64

func (*Size) Bit32 added in v0.1.5

func (s *Size) Bit32() int32

func (*Size) Formatter added in v0.1.3

func (s *Size) Formatter() *sizeFormatter

func (*Size) MarshalJSON added in v0.0.7

func (s *Size) MarshalJSON() (bytes []byte, err error)

func (*Size) String added in v0.0.7

func (s *Size) String() string

func (*Size) UnmarshalJSON added in v0.0.7

func (s *Size) UnmarshalJSON(bytes []byte) (err error)

type SoftDeleted added in v0.1.3

type SoftDeleted struct {
	Model   `xorm:"extends"`
	Deleted `xorm:"extends"`
}

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

type Updated added in v0.1.3

type Updated struct {
	// 最后更新时间
	Updated time.Time `xorm:"updated default('2020-02-04 09:55:52')" json:"updated"`
}

Updated 带修改时间模型

type UriScheme added in v0.1.3

type UriScheme string

UriScheme 协议

const (
	// UriSchemeUnknown 未知协议
	UriSchemeUnknown UriScheme = ``
	// UriSchemeSocksV4 Socks协议
	UriSchemeSocksV4 UriScheme = "socks4"
	// UriSchemeSocksV5 Socks协议
	UriSchemeSocksV5 UriScheme = "socks4"
	// UriSchemeHttp Http协议
	UriSchemeHttp UriScheme = "http"
	// UriSchemeHttps Https协议
	UriSchemeHttps UriScheme = "https"
	// UriSchemeRtmp Rtmp协议
	UriSchemeRtmp UriScheme = "rtmp"
	// UriSchemeMqtt MQTT协议
	UriSchemeMqtt UriScheme = "mqtt"
	// UriSchemeMqtts MQTT安全协议
	UriSchemeMqtts UriScheme = "mqtts"
	// UriSchemeWs Websocket协议
	UriSchemeWs UriScheme = "ws"
	// UriSchemeWss Websocket安全协议
	UriSchemeWss UriScheme = "wss"
)

type User added in v0.1.3

type User struct {
	Model `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"`
	// 密码
	Passwd string `xorm:"varchar(512) notnull default('')" json:"-"`
}

User 基础用户数据

type Value

type Value[T any] interface {
	// Value 返回具体的值
	Value() T
}

Value 值

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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