mcommon

package module
v0.1.35 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2020 License: MIT Imports: 39 Imported by: 1

README

mcommon

build blog

目录

背景

开发过程中用到的一些通用的golang函数

  • log.go 日志
  • mysql.go mysql操作

使用说明

go get github.com/moremorefun/mcommon

维护者

@moremorefun 那些年我们De过的Bug

使用许可

MIT © moremorefun

Documentation

Index

Constants

View Source
const (
	// ErrorSuccess 成功
	ErrorSuccess = 0
	// ErrorSuccessMsg 成功
	ErrorSuccessMsg = "success"

	// ErrorInternal 内部错误
	ErrorInternal = -1
	// ErrorInternalMsg 内部错误
	ErrorInternalMsg = "internal"

	// ErrorBind 输入绑定错误
	ErrorBind = -2
	// ErrorBindMsg 输入绑定错误
	ErrorBindMsg = "input bind"
)

Variables

View Source
var GinRespInternalErr = GinResp{
	ErrCode: ErrorInternal,
	ErrMsg:  ErrorInternalMsg,
}

GinRespInternalErr 成功返回

View Source
var GinRespSuccess = GinResp{
	ErrCode: ErrorSuccess,
	ErrMsg:  ErrorSuccessMsg,
}

GinRespSuccess 成功返回

View Source
var ZapLog *zap.Logger

ZapLog zap日志对象

Functions

func AesDecrypt added in v0.1.22

func AesDecrypt(cryted string, key string) (string, error)

AesDecrypt aes解密

func AesEncrypt added in v0.1.22

func AesEncrypt(orig string, key string) (string, error)

AesEncrypt 加密

func DbCreate

func DbCreate(dataSourceName string, showSQL bool) *sqlx.DB

DbCreate 创建数据库链接

func DbExecuteCountManyContent

func DbExecuteCountManyContent(ctx context.Context, tx DbExeAble, query string, n int, args ...interface{}) (int64, error)

DbExecuteCountManyContent 返回sql语句并返回执行行数

func DbExecuteCountNamedContent

func DbExecuteCountNamedContent(ctx context.Context, tx DbExeAble, query string, argMap map[string]interface{}) (int64, error)

DbExecuteCountNamedContent 执行sql语句返回执行个数

func DbExecuteLastIDNamedContent

func DbExecuteLastIDNamedContent(ctx context.Context, tx DbExeAble, query string, argMap map[string]interface{}) (int64, error)

DbExecuteLastIDNamedContent 执行sql语句并返回lastID

func DbGetNamedContent

func DbGetNamedContent(ctx context.Context, tx DbExeAble, dest interface{}, query string, argMap map[string]interface{}) (bool, error)

DbGetNamedContent 执行sql查询并返回当个元素

func DbSelectNamedContent

func DbSelectNamedContent(ctx context.Context, tx DbExeAble, dest interface{}, query string, argMap map[string]interface{}) error

DbSelectNamedContent 执行sql查询并返回多行

func DbStructGetDiff added in v0.1.34

func DbStructGetDiff(tx DbExeAble, tableNames []string, sqlFilePath string) (string, error)

DbStructGetDiff 获取数据库更新指令

func DecodeHashID added in v0.1.10

func DecodeHashID(salt string, minLen int, value string) (int, error)

DecodeHashID 解析hash id

func DecodeHashIDs added in v0.1.13

func DecodeHashIDs(salt string, minLen int, value string) ([]int, error)

DecodeHashIDs 解析hash id

func EncodeHashID added in v0.1.10

func EncodeHashID(salt string, minLen, id int) (string, error)

EncodeHashID 获取hash id

func EncodeHashIDs added in v0.1.13

func EncodeHashIDs(salt string, minLen int, ids []int) (string, error)

EncodeHashIDs 获取hash id

func GetHash added in v0.1.30

func GetHash(in string) (string, error)

GetHash 获取hash

func GetUUIDStr

func GetUUIDStr() string

GetUUIDStr 获取唯一字符串

func GinDoEncRespSuccess added in v0.1.23

func GinDoEncRespSuccess(c *gin.Context, key string, isAll bool, data gin.H)

GinDoEncRespSuccess 返回成功信息

func GinDoRespErr added in v0.1.9

func GinDoRespErr(c *gin.Context, code int64, msg string, data gin.H)

GinDoRespErr 返回特殊错误

func GinDoRespInternalErr added in v0.1.9

func GinDoRespInternalErr(c *gin.Context)

GinDoRespInternalErr 返回错误信息

func GinDoRespSuccess added in v0.1.9

func GinDoRespSuccess(c *gin.Context, data gin.H)

GinDoRespSuccess 返回成功信息

func GinFillBindError

func GinFillBindError(c *gin.Context, err error)

GinFillBindError 检测gin输入绑定错误

func GinRepeatReadBody

func GinRepeatReadBody(c *gin.Context) error

GinRepeatReadBody 创建可重复度body

func GinShouldBindRepeat added in v0.1.3

func GinShouldBindRepeat(c *gin.Context, obj interface{}) error

GinShouldBindRepeat 可重复绑定参数

func IntArrToString added in v0.1.17

func IntArrToString(A []int64, denim string) string

IntArrToString 数组转换

func Ip2long added in v0.1.20

func Ip2long(ipAddr string) (uint32, error)

Ip2long 转换ip

func IsIntInSlice

func IsIntInSlice(arr []int64, str int64) bool

IsIntInSlice 数字是否在数组中

func IsStringInSlice

func IsStringInSlice(arr []string, str string) bool

IsStringInSlice 字符串是否在数组中

func LogSetLevel

func LogSetLevel(level zapcore.Level) error

LogSetLevel 设置日志等级

func LogSetToProd

func LogSetToProd() error

LogSetToProd 设置为生产环境

func PKCS7Padding added in v0.1.22

func PKCS7Padding(ciphertext []byte, blocksize int) []byte

PKCS7Padding 补码

func PKCS7UnPadding added in v0.1.22

func PKCS7UnPadding(origData []byte) []byte

PKCS7UnPadding 去码

func QiniuGetDownloadURL added in v0.1.12

func QiniuGetDownloadURL(ctx context.Context, access string, secret string, domain string, fileKey string, deadline int64) string

QiniuGetDownloadURL 获取私有下载链接

func TencenSms added in v0.1.6

func TencenSms(sdkID, sdkKey, appID, sign, templateID string, tels []string, templateParam []string) error

TencenSms 发送短信

func UploadToQiniu added in v0.1.11

func UploadToQiniu(ctx context.Context, access string, secret string, zone *storage.Zone, bucket string, fileKey string, bs []byte) error

UploadToQiniu 上传到qiniu

func WechatCheckSign added in v0.1.31

func WechatCheckSign(appSecret string, paramsMap gin.H) bool

WechatCheckSign 检查签名

func WechatGetPrepay added in v0.1.31

func WechatGetPrepay(appID, mchID, mchKey, payBody, outTradeNo, clientIP, cbURL, tradeType, openID string, totalFee int64) (gin.H, error)

WechatGetPrepay 获取预支付信息

func WechatGetSign added in v0.1.31

func WechatGetSign(appSecret string, paramsMap gin.H) string

WechatGetSign 获取签名

func XMLWalk added in v0.1.31

func XMLWalk(bs []byte) (map[string]interface{}, error)

XMLWalk 遍历xml

Types

type DbExeAble

type DbExeAble interface {
	Rebind(string) string
	Get(dest interface{}, query string, args ...interface{}) error
	Exec(query string, args ...interface{}) (sql.Result, error)
	Select(dest interface{}, query string, args ...interface{}) error
	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}

DbExeAble 数据库接口

type GinResp added in v0.1.5

type GinResp struct {
	ErrCode int64  `json:"error"`
	ErrMsg  string `json:"error_msg"`
	Data    gin.H  `json:"data,omitempty"`
}

func GinFillSuccessData added in v0.1.8

func GinFillSuccessData(data gin.H) GinResp

GinFillSuccessData 填充返回数据

type H added in v0.1.21

type H map[string]interface{}

type LoggerAble

type LoggerAble interface {
	Debugf(template string, args ...interface{})
	Infof(template string, args ...interface{})
	Warnf(template string, args ...interface{})
	Errorf(template string, args ...interface{})
	Fatalf(template string, args ...interface{})
}

LoggerAble 日志对象接口

var Log LoggerAble

Log 对外服务的日志对象

type StWeChatCbBody added in v0.1.31

type StWeChatCbBody struct {
	XMLName       xml.Name `xml:"xml"`
	Text          string   `xml:",chardata"`
	Appid         string   `xml:"appid"`
	Attach        string   `xml:"attach"`
	BankType      string   `xml:"bank_type"`
	FeeType       string   `xml:"fee_type"`
	IsSubscribe   string   `xml:"is_subscribe"`
	MchID         string   `xml:"mch_id"`
	NonceStr      string   `xml:"nonce_str"`
	Openid        string   `xml:"openid"`
	OutTradeNo    string   `xml:"out_trade_no"`
	ResultCode    string   `xml:"result_code"`
	ReturnCode    string   `xml:"return_code"`
	Sign          string   `xml:"sign"`
	TimeEnd       string   `xml:"time_end"`
	TotalFee      string   `xml:"total_fee"`
	CouponFee     string   `xml:"coupon_fee"`
	CouponCount   string   `xml:"coupon_count"`
	CouponType    string   `xml:"coupon_type"`
	CouponID      string   `xml:"coupon_id"`
	TradeType     string   `xml:"trade_type"`
	TransactionID string   `xml:"transaction_id"`
}

StWeChatCbBody 回调信息

func WechatCheckCb added in v0.1.31

func WechatCheckCb(mchKey string, body []byte) (*StWeChatCbBody, error)

WechatCheckCb 验证回调

type XMLNode added in v0.1.31

type XMLNode struct {
	XMLName xml.Name
	Content string    `xml:",chardata"`
	Nodes   []XMLNode `xml:",any"`
}

Jump to

Keyboard shortcuts

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