Documentation
¶
Index ¶
- Constants
- Variables
- func AddSlashes(s string) string
- func BindForm(r *http.Request, obj any) error
- func BindJSON(r *http.Request, obj any) error
- func BindProto(r *http.Request, msg proto.Message) error
- func ContentType(h http.Header) string
- func CreateFile(filename string) (*os.File, error)
- func DebugLogger(options ...zap.Option) *zap.Logger
- func ExcelColumnIndex(name string) int
- func IP2Long(ip string) uint32
- func IsUniqueDuplicateError(err error) bool
- func Long2IP(ip uint32) string
- func MapForm(ptr any, form map[string][]string) error
- func MapFormByTag(ptr any, form map[string][]string, tag string) error
- func MapQuery(ptr any, m map[string][]string) error
- func MappingByPtr(ptr any, setter setter, tag string) error
- func MarshalNoEscapeHTML(v any) ([]byte, error)
- func MyTimeEncoder(t time.Time, e zapcore.PrimitiveArrayEncoder)
- func NewDB(cfg *DBConfig) (*sql.DB, error)
- func NewDBx(cfg *DBConfig) (*sqlx.DB, error)
- func NewHttpClient() *http.Client
- func NewLogger(cfg *LogConfig) *zap.Logger
- func Nonce(size uint8) string
- func OpenFile(filename string) (*os.File, error)
- func QuoteMeta(s string) string
- func StrToTime(layout, datetime string, loc *time.Location) time.Time
- func StripSlashes(s string) string
- func TimeToStr(layout string, timestamp int64, loc *time.Location) string
- func Transaction(ctx context.Context, db *sqlx.DB, ...) (err error)
- func VersionCompare(rangeVer, curVer string) (bool, error)
- func WeekAround(layout string, now time.Time) (monday, sunday string)
- type DBConfig
- type LogConfig
- type Mutex
- type Quantity
- type X
Constants ¶
View Source
const ( HeaderAccept = "Accept" HeaderAuthorization = "Authorization" HeaderContentType = "Content-Type" )
View Source
const ( ContentText = "text/plain; charset=utf-8" ContentJSON = "application/json" ContentXML = "application/xml" ContentForm = "application/x-www-form-urlencoded" ContentStream = "application/octet-stream" ContentMultipartForm = "multipart/form-data" )
View Source
const ( // B - Byte size B Quantity = 1 // KiB - KibiByte size KiB = 1024 * B // MiB - MebiByte size MiB = 1024 * KiB // GiB - GibiByte size GiB = 1024 * MiB // TiB - TebiByte size TiB = 1024 * GiB )
View Source
const MaxFormMemory = 32 << 20
Variables ¶
View Source
var GMT8 = time.FixedZone("CST", 8*3600)
GMT8 东八区时区
View Source
var RestyClient = resty.NewWithClient(NewHttpClient())
RestyClient default client for http request
Functions ¶
func ContentType ¶
func CreateFile ¶
CreateFile 创建或清空指定的文件 文件已存在,则清空;文件或目录不存在,则以0775权限创建
func ExcelColumnIndex ¶
ExcelColumnIndex 返回Excel列名对应的序号,如:A=0,B=1,AA=26,AB=27
func IsUniqueDuplicateError ¶
IsUniqueDuplicateError 判断是否「唯一索引冲突」错误
func MappingByPtr ¶
func MarshalNoEscapeHTML ¶
MarshalNoEscapeHTML 不带HTML转义的JSON序列化
func MyTimeEncoder ¶
func MyTimeEncoder(t time.Time, e zapcore.PrimitiveArrayEncoder)
MyTimeEncoder 自定义时间格式化
func Transaction ¶
func Transaction(ctx context.Context, db *sqlx.DB, fn func(ctx context.Context, tx *sqlx.Tx) error) (err error)
Transaction 执行数据库事物
func VersionCompare ¶
VersionCompare 语义化的版本比较,支持:>, >=, =, !=, <, <=, | (or), & (and). 参数 `rangeVer` 示例:1.0.0, =1.0.0, >2.0.0, >=1.0.0&<2.0.0, <2.0.0|>3.0.0, !=4.0.4
Types ¶
type DBConfig ¶
type DBConfig struct { // Driver 驱动名称 Driver string // DSN 数据源名称 // // [-- MySQL] username:password@tcp(localhost:3306)/dbname?timeout=10s&charset=utf8mb4&collation=utf8mb4_general_ci&parseTime=True&loc=Local // [Postgres] host=localhost port=5432 user=root password=secret dbname=test search_path=schema connect_timeout=10 sslmode=disable // [- SQLite] file::memory:?cache=shared DSN string // MaxOpenConns 设置最大可打开的连接数 MaxOpenConns int // MaxIdleConns 连接池最大闲置连接数 MaxIdleConns int // ConnMaxLifetime 连接的最大生命时长 ConnMaxLifetime time.Duration // ConnMaxIdleTime 连接最大闲置时间 ConnMaxIdleTime time.Duration }
DBConfig 数据库初始化配置
type LogConfig ¶
type LogConfig struct { // Filename 日志名称 Filename string // Level 日志级别 Level zapcore.Level // MaxSize 当前文件多大时轮替;默认:100MB MaxSize int // MaxAge 轮替的旧文件最大保留时长;默认:不限 MaxAge int // MaxBackups 轮替的旧文件最大保留数量;默认:不限 MaxBackups int // Compress 轮替的旧文件是否压缩;默认:不压缩 Compress bool // Stderr 是否输出到控制台 Stderr bool // Options Zap日志选项 Options []zap.Option }
LogConfig 日志初始化配置
type Mutex ¶
type Mutex interface { // Lock 获取锁 Lock(ctx context.Context) (bool, error) // TryLock 尝试获取锁 TryLock(ctx context.Context, attempts int, interval time.Duration) (bool, error) // UnLock 释放锁 UnLock(ctx context.Context) error }
Mutex 分布式锁
Source Files
¶
Click to show internal directories.
Click to hide internal directories.