Documentation ¶
Overview ¶
Package cbl is a common basic library for go.
- `conv` 类型转换
- `errcode` web 常用错误码
- `gen` token/id 生成器
- `ginext` gin 扩展(标准化)
- `net` 网络扩展
- `prom` prometheus middware
- `strings` 字符串扩展
- `wechat_mini` 微信小程序
- `yinyang` 公历和农历转换
- `set` set
- `date` 日期扩展
More read `README.md`
Index ¶
- Variables
- func B2i(b bool) int
- func ConvYinYang(year int, month int, leap int, day int) (time.Time, error)
- func DayOfWeekCN(n int) string
- func DurationString(d time.Duration) string
- func EndOfDay(t time.Time) time.Time
- func EndOfMonth(t time.Time) time.Time
- func EndOfWeek(t time.Time) time.Time
- func EndOfYear(t time.Time) time.Time
- func ErrorResponse(c *gin.Context, err interface{})
- func FormatDayTime(t time.Time, showSec bool) string
- func GenRSessionID() string
- func GenUSessionID() string
- func GenUUIDV1() string
- func GenUUIDV4() string
- func GenVerifyCodeAny(pool string, width int) string
- func GenVerifyCodeCommon(width int) string
- func GenVerifyCodeNumber(width int) string
- func GetOutboundIP() net.IP
- func I2b(i int) bool
- func Int64SliceToString(a []int64, delim string) string
- func IntSliceToString(a []int, delim string) string
- func PromGinMiddleware() gin.HandlerFunc
- func RangeMonth(t time.Time) []time.Time
- func RangeWeek(t time.Time) []time.Time
- func RangeYear(t time.Time) []time.Time
- func SliceDifference(a []string, b []string) []string
- func SliceIntersection(a []string, b []string) []string
- func SliceUnion(a []string, b []string) []string
- func SliceUniq(a []string) []string
- func SliceUniqInt(a []int) []int
- func SliceUniqInt64(a []int64) []int64
- func StartOfDay(t time.Time) time.Time
- func StartOfMonth(t time.Time) time.Time
- func StartOfWeek(t time.Time) time.Time
- func StartOfYear(t time.Time) time.Time
- func StringSplit(source string, sep string) []string
- func SuccessResponse(c *gin.Context, data interface{})
- func TruncateString(str string, length int) string
- func UrlJoin(host string, subs ...string) (string, error)
- type Resp
- type WXMiniSession
- type YangDate
- type YinDate
Constants ¶
This section is empty.
Variables ¶
var ( ErrNone = "" // no error 没错 ErrBadRequest = "Bad Request" // bad request 错误的请求(参数错误) ErrInternalServerError = "Internal Server Error" // server logic error 服务器内部错误, 服务器自身逻辑问题 ErrInvalidParams = "Invalid Params" // invalid params 参数格式错误 ErrInvalidPassword = "Invalid Password" // invalid password 密码错误 ErrInvalidVerifyCode = "Invalid Verify Code" // invalid verify code 验证码无效 ErrLoginRequired = "Login Required" // need login 需要登录 ErrNotFound = "Not Found" // resource not found 资源不存在 ErrOutOfRange = "Out Of Range" // out of range 越界访问 ErrPermissionDenied = "Permission Denied" // permission denied 权限不足 ErrTooManyRequests = "Too Many Requests" // too many requests 请求过于频繁, 限流 )
Functions ¶
func ConvYinYang ¶
ConvYinYang 农历转公历
func DayOfWeekCN ¶ added in v0.2.1
func DurationString ¶ added in v0.3.0
func EndOfMonth ¶ added in v0.3.1
EndOfMonth month end datetime
func ErrorResponse ¶
func GenRSessionID ¶
func GenRSessionID() string
GenRSessionID generate a random session id, most business scene recommand
func GenUUIDV4 ¶
func GenUUIDV4() string
GenUUIDV4 wikipedia said Randomly generated UUIDs have 122 random bits. One's annual risk of being hit by a meteorite is estimated to be one chance in 17 billion, that means the probability is about 0.00000000006 (6 x 10−11), equivalent to the odds of creating a few tens of trillions of UUIDs in a year and having one duplicate.
(most business scene recommand)
func GenVerifyCodeAny ¶ added in v0.2.8
GenVerifyCodeAny generate verify code, get from pool
func GenVerifyCodeCommon ¶ added in v0.2.8
GenVerifyCodeCommon generate verify code, letter + number
func GenVerifyCodeNumber ¶ added in v0.2.8
GenVerifyCodeNumber generate verify code, all is number
func GetOutboundIP ¶
GetOutboundIP get IP address code via https://stackoverflow.com/a/37382208/802815
func Int64SliceToString ¶ added in v0.2.9
Int64SliceToString a int64 slice to string Ref: https://stackoverflow.com/questions/37532255/one-liner-to-transform-int-into-string
func IntSliceToString ¶ added in v0.2.9
IntSliceToString a int64 slice to string Ref: https://stackoverflow.com/questions/37532255/one-liner-to-transform-int-into-string
func PromGinMiddleware ¶
func PromGinMiddleware() gin.HandlerFunc
PromGinMiddleware prometheus for gin, register code:
router.GET("/metrics", gin.WrapH(promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{})))
func RangeMonth ¶ added in v0.3.1
RangeMonth get month every day date
func SliceDifference ¶ added in v0.1.8
SliceDifference 差集
func SliceIntersection ¶ added in v0.1.8
SliceIntersection 交集
func SliceUniqInt ¶ added in v0.2.9
func SliceUniqInt64 ¶ added in v0.2.9
func StartOfMonth ¶ added in v0.3.1
StartOfMonth month start datetime
func StartOfWeek ¶ added in v0.3.1
StartOfWeek week first day
func StringSplit ¶ added in v0.1.6
StringSplit string split by `sep` the standard library `Split` when `source` is a empty string, will return a `[""]` slice. In fact, most of time, we want return a length equal 0 slice, `[]`
func SuccessResponse ¶
func TruncateString ¶ added in v0.2.8
TruncateString Ref: https://dev.to/takakd/go-safe-truncate-string-9h0
Types ¶
type WXMiniSession ¶
type WXMiniSession struct { OpenID string `json:"openid"` SessionKey string `json:"session_key"` UnionID string `json:"unionid"` }
func Code2Session ¶
func Code2Session(appID string, secret string, code string) (*WXMiniSession, error)
Code2Session wxlogin code to session id. https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html
type YinDate ¶
type YinDate struct { YearNum int `json:"year_num"` YearTian string `json:"year_tian"` YearDi string `json:"year_di"` YearZodiac string `json:"year_zodiac"` MonthNum int `json:"month_num"` MonthName string `json:"month_name"` MonthLeap bool `json:"month_leap"` DayNum int `json:"day_num"` DayName string `json:"day_name"` WeekDay string `json:"weekday"` SolarTerm string `json:"solarterm"` }
func ConvYangYin ¶
ConvYangYin 公历转农历
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package cache based on NoSQL Redis, encapsulated common scenario.
|
Package cache based on NoSQL Redis, encapsulated common scenario. |
Package datasize provide computer unit converter.
|
Package datasize provide computer unit converter. |
package datastruct data structure extends for go standard library.
|
package datastruct data structure extends for go standard library. |