Documentation
¶
Index ¶
- Constants
- Variables
- func CheckMobile(mobile string) bool
- func Contains(set interface{}, obj interface{}) bool
- func ConvertToEncodingBytes(bytes []byte, charset Charset) []byte
- func Decompose(id uint64) map[string]uint64
- func DefaultGoroutineRecover(l *logger.Logger, action string)
- func GetCleanLocationName(name string) string
- func GetCurrentDir() (string, error)
- func GetFileMD5(fileName string) (string, error)
- func GetPrivateIPv4Id() (uint16, error)
- func GetRemoteIP(req *http.Request) string
- func GetStack(skip int) []byte
- func GetUTCTicks(datetime time.Time) int64
- func HttpGet(reqUrl string, params map[string]interface{}) (string, error)
- func HttpGetJsonHeader(url string, params, header []byte) (string, error)
- func HttpPostForm(reqUrl string, params interface{}) (string, error)
- func HttpPostJson(reqUrl string, params interface{}) (string, error)
- func HttpPostJsonHeader(url string, params, header []byte) (string, error)
- func HttpPostJsonWithToken(reqUrl string, params interface{}, token string) (string, error)
- func IndexOfStr(str, substr string) int
- func Insert(db *xorm.Engine, beans ...interface{}) error
- func InsertWithSize(db *xorm.Engine, size int, beans ...interface{}) error
- func InsertWithTableName(db *xorm.Engine, tableName string, beans ...interface{}) error
- func InsertWithTableNameAndSize(db *xorm.Engine, tableName string, size int, beans ...interface{}) error
- func NewPoolingHttpClient() *http.Client
- func PrivateIPv4() (net.IP, error)
- func RandFloat(min, max float64) float64
- func RandInt(min, max int) int
- func RandIntWithZero(min, max int) int
- func SplitChineseName(name string) (string, string)
- func SubStr(input string, begin, end int) string
- func TransInsert(trans *xorm.Session, beans ...interface{}) error
- func TransInsertWithSize(trans *xorm.Session, size int, beans ...interface{}) error
- func TransInsertWithTableName(trans *xorm.Session, tableName string, beans ...interface{}) error
- func TransInsertWithTableNameAndSize(trans *xorm.Session, tableName string, size int, beans ...interface{}) error
- func TransformObject(req interface{}, targetObject interface{}) error
- type Charset
- type IErrorCode
- type Long
- func (t Long) FromString(str string) Long
- func (t Long) IsZero() bool
- func (t Long) MarshalJSON() ([]byte, error)
- func (t Long) MarshalText() ([]byte, error)
- func (t *Long) Scan(value interface{}) error
- func (t Long) String() string
- func (t *Long) UnmarshalJSON(value []byte) error
- func (t *Long) UnmarshalText(data []byte) error
- func (t Long) Value() (driver.Value, error)
- type PagingResult
- type RequestPromise
- func (r *RequestPromise) Call(httpMethod string, targetUri string, data io.Reader) ([]byte, error)
- func (v RequestPromise) MarshalEasyJSON(w *jwriter.Writer)
- func (v RequestPromise) MarshalJSON() ([]byte, error)
- func (r *RequestPromise) SetClient(client *http.Client) *RequestPromise
- func (r *RequestPromise) SetEncoding(encoding Charset) *RequestPromise
- func (r *RequestPromise) SetHeader(key string, value string) *RequestPromise
- func (r *RequestPromise) SetHttpProxy(proxyUri string) *RequestPromise
- func (r *RequestPromise) SetSkipTls() *RequestPromise
- func (r *RequestPromise) SetSocket5Proxy(proxyUri string) *RequestPromise
- func (r *RequestPromise) SetTimeout(timeout time.Duration) *RequestPromise
- func (v *RequestPromise) UnmarshalEasyJSON(l *jlexer.Lexer)
- func (v *RequestPromise) UnmarshalJSON(data []byte) error
- type Res
- type ResHead
- type Snowflake
- type SnowflakeSettings
Constants ¶
const ( DefaultHttpDialTimeout = 20 * time.Second DefaultHttpKeepAlive = 120 * time.Second DefaultHttpMaxIdleConns = 1000 DefaultHttpMaxIdleConnsPerHost = 1000 DefaultHttpIdleConnTimeout = 90 * time.Second DefaultHttpTimeout = 30 * time.Second )
http请求相关默认配置
const ( SnowflakeTimeUnit = 1e7 // 时间单位,一纳秒的多少倍,1e6 = 一毫秒,1e7 = 百分之一秒,1e8 = 十分之一秒 BitLenSequence = 8 // 序列号的个数最多256个(0-255),即每单位时间并发数,如时间单位是1e7,则单实例qps = 25600 BitLenDataCenterId = 3 // 数据中心个数最多8个(0-7),即同一个环境(生产、预发布、测试等)的数据中心(假设一个机房相同数据域的应用服务器集群只有一个,则数据中心数等于机房数)最多有8个 BitLenMachineId = 16 // 同一个数据中心下最多65536个应用实例(0-65535),默认是根据实例ip后两段算实例id(k8s环境动态创建Pod,也建议用此方式),所以需要预留255 * 255这么多 BitLenTime = 1 << 36 // 时间戳之差最大 = 2的36次方 * 时间单位 / 1e9 秒,目前的设计最多可以用21.79年就需要更新开始时间(随之还需要归档旧数据和更新次新数据id) )
Snowflake程序id生成器 源于Twitter的Snowflake算法 但由于原版算法对应的分布式层级结构太简单,所以目前的算法实际是Sony对Snowflake算法的改进版本的Sonyflake算法 Sonyflake算法原版可参考github中的开源项目,当前算法有进一步细微调整
const ( UTF8 = Charset("UTF-8") GB18030 = Charset("GB18030") GBK = Charset("GBK") )
Variables ¶
var ( GB18030Decoder = simplifiedchinese.GB18030.NewDecoder() GBKDecoder = simplifiedchinese.GBK.NewDecoder() )
var SurNames = []string{
"赵", "钱", "孙", "李", "周", "吴", "郑", "王",
"冯", "陈", "卫", "蒋", "沈", "韩", "杨",
"朱", "秦", "尤", "许", "何", "吕", "施", "张",
"孔", "曹", "严", "金", "魏", "陶", "姜",
"戚", "谢", "邹", "喻", "章",
"云", "苏", "潘", "葛", "范", "彭", "郎",
"鲁", "马", "花", "方",
"俞", "任", "袁", "柳", "史", "唐",
}
Functions ¶
func ConvertToEncodingBytes ¶
func DefaultGoroutineRecover ¶
func GetPrivateIPv4Id ¶
func HttpPostForm ¶
func HttpPostJson ¶
func HttpPostJsonHeader ¶
func HttpPostJsonWithToken ¶
func InsertWithTableName ¶
func NewPoolingHttpClient ¶
返回一个采用了连接池和Keepalive配置的http client,可以配合RequestPromise的SetClient函数使用 默认不使用它,而是每次请求新建连接
func PrivateIPv4 ¶
func RandIntWithZero ¶ added in v1.2.6
func SplitChineseName ¶
func TransInsert ¶
func TransInsertWithSize ¶
func TransformObject ¶ added in v1.2.3
func TransformObject(req interface{}, targetObject interface{}) error
用于请求参数,与实体stautc转换 createdBy 周志彪
Types ¶
type IErrorCode ¶
type IErrorCode interface { // 转换为int ToInt() int // 方便与int比较 Equals(errCode int) bool // 获取错误信息 ErrMsg(args ...interface{}) string }
Error Code接口
type Long ¶
type Long int64
func (Long) FromString ¶
func (Long) MarshalJSON ¶
func (Long) MarshalText ¶
func (*Long) UnmarshalJSON ¶
func (*Long) UnmarshalText ¶
type PagingResult ¶
type PagingResult struct { TotalCount int64 `json:"totalCount" xml:"TotalCount"` // 总大小 PageSize int64 `json:"pageSize" xml:"PageSize"` // 分页大小 PageIndex int64 `json:"pageIndex" xml:"PageIndex"` // 页面索引 Data interface{} `json:"data" xml:"Result"` // 分页结果 }
分页数据对象
type RequestPromise ¶
type RequestPromise struct {
// contains filtered or unexported fields
}
http请求配置
func JSONRequest ¶
func JSONRequest() *RequestPromise
返回一个http请求配置对象,默认带上压缩头和Content-Type = application/json; charset=utf-8
func XMLRequest ¶
func XMLRequest() *RequestPromise
返回一个http请求配置对象,默认带上压缩头和Content-Type = application/xml; charset=utf-8
func (*RequestPromise) Call ¶
发起请求并返回响应内容 FORM方式提交数据请设置Content-Type=application/x-www-form-urlencoded请求头,且io.Reader传url.Values.Encode得到的字符串的reader
func (RequestPromise) MarshalEasyJSON ¶ added in v1.2.4
func (v RequestPromise) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (RequestPromise) MarshalJSON ¶ added in v1.2.4
func (v RequestPromise) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*RequestPromise) SetClient ¶
func (r *RequestPromise) SetClient(client *http.Client) *RequestPromise
设置事先实例化好的http client,默认每次请求会新建一个http client
func (*RequestPromise) SetEncoding ¶
func (r *RequestPromise) SetEncoding(encoding Charset) *RequestPromise
设置http响应的编码,默认utf8
func (*RequestPromise) SetHeader ¶
func (r *RequestPromise) SetHeader(key string, value string) *RequestPromise
设置http header
func (*RequestPromise) SetHttpProxy ¶
func (r *RequestPromise) SetHttpProxy(proxyUri string) *RequestPromise
设置http或https代理,默认无代理
func (*RequestPromise) SetSkipTls ¶
func (r *RequestPromise) SetSkipTls() *RequestPromise
设置https忽略本地证书校验
func (*RequestPromise) SetSocket5Proxy ¶
func (r *RequestPromise) SetSocket5Proxy(proxyUri string) *RequestPromise
设置socket5代理,默认无代理
func (*RequestPromise) SetTimeout ¶
func (r *RequestPromise) SetTimeout(timeout time.Duration) *RequestPromise
设置超时时间,从连接到接收到响应的总时间 如果此处不设置则采用http client中设置的超时时间,默认http client超时时间30秒 如果此处设置不等于零的值,则覆盖http client中设置的超时时间 如果此处设置小于零的值,意为不超时
func (*RequestPromise) UnmarshalEasyJSON ¶ added in v1.2.4
func (v *RequestPromise) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*RequestPromise) UnmarshalJSON ¶ added in v1.2.4
func (v *RequestPromise) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type Res ¶
type Res struct { ResHead Body interface{} `json:"body,omitempty"` }
func E2 ¶
func E2(errDetail interface{}, errCode IErrorCode, args ...interface{}) *Res
func (Res) MarshalEasyJSON ¶ added in v1.2.4
MarshalEasyJSON supports easyjson.Marshaler interface
func (Res) MarshalJSON ¶ added in v1.2.4
MarshalJSON supports json.Marshaler interface
func (*Res) UnmarshalEasyJSON ¶ added in v1.2.4
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Res) UnmarshalJSON ¶ added in v1.2.4
UnmarshalJSON supports json.Unmarshaler interface
type ResHead ¶
type ResHead struct { Status int `json:"status"` Msg string `json:"msg,omitempty"` Detail string `json:"-"` HttpStatus int `json:"-"` }
func (ResHead) MarshalEasyJSON ¶ added in v1.2.4
MarshalEasyJSON supports easyjson.Marshaler interface
func (ResHead) MarshalJSON ¶ added in v1.2.4
MarshalJSON supports json.Marshaler interface
func (*ResHead) UnmarshalEasyJSON ¶ added in v1.2.4
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*ResHead) UnmarshalJSON ¶ added in v1.2.4
UnmarshalJSON supports json.Unmarshaler interface
type Snowflake ¶
type Snowflake struct {
// contains filtered or unexported fields
}
func NewSnowflake ¶
func NewSnowflake(st SnowflakeSettings) *Snowflake
func SingletonSnowflakeKeyGen ¶
func SingletonSnowflakeKeyGen() *Snowflake
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
github.com
|
|
axgle/mahonia
This package is a character-set conversion library for Go.
|
This package is a character-set conversion library for Go. |
* Copyright (c) 2015, zheng-ji.info *
|
* Copyright (c) 2015, zheng-ji.info * |
montnets
|
|
* The MIT License (MIT) * * Copyright (c) 2016 tony<wuhaiyang1213@gmail.com> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software.
|
* The MIT License (MIT) * * Copyright (c) 2016 tony<wuhaiyang1213@gmail.com> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. |