gocom

package module
v0.0.0-...-bd81c7d Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: MIT Imports: 22 Imported by: 0

README

go-com

创建go程序的基础库封装

Documentation

Index

Constants

View Source
const (
	StdDateFormat                  = "2006-01-02"
	StdTimeFormat                  = "15:04:05"
	StdDateTimeFormat              = "2006-01-02 15:04:05"
	StdTimeWithMsec                = "15:04:05.999999999"
	StdDateTimeWithMsec            = "2006-01-02 15:04:05.999999999"
	StdTimeWithMsecAndTimeZone     = "15:04:05.999999999Z07:00"
	StdDateTimeWithMsecAndTimeZone = "2006-01-02 15:04:05.999999999Z07:00"
)

Variables

View Source
var AddPProfHandlerWrapper = AddPProfHandler

AddPProfHandlerWrapper make sure we are backward compatible

Functions

func AddPProfHandler

func AddPProfHandler(router *gin.Engine)

AddPProfHandler adds several routes from package `net/http/pprof` to *gin.Engine object

func AddWhiteList

func AddWhiteList(url string)

func AllocsHandler

func AllocsHandler() gin.HandlerFunc

AllocsHandler will pass the call from /debug/pprof/allocs to pprof

func Bind

func Bind(c *gin.Context, obj interface{}) bool

func Bind2

func Bind2(c *gin.Context, obj interface{}) (bool, string)

如果绑定失败,则返回错误描述

func BlockHandler

func BlockHandler() gin.HandlerFunc

BlockHandler will pass the call from /debug/pprof/block to pprof

func CheckAuth

func CheckAuth() gin.HandlerFunc

func CmdlineHandler

func CmdlineHandler() gin.HandlerFunc

CmdlineHandler will pass the call from /debug/pprof/cmdline to pprof

func Cors

func Cors() gin.HandlerFunc

func DoHttpRequest

func DoHttpRequest(method string, reqUrl string, headers map[string]string, body io.Reader) (int, []byte, error)

method POST GET headers Ext Header

func DoHttpRequestWithBody

func DoHttpRequestWithBody(method string, reqUrl string, headers map[string]string, reqBody interface{}) (int, []byte, error)

func FormatReqUrl

func FormatReqUrl(reqUrl string, reqForm map[string]string) string

有reqform时,可能需要设置header:request.Header.Set("Content-Type", "application/x-www-form-urlencoded")

func GenAuth

func GenAuth(c *gin.Context, userId int64) error

func GinLogger

func GinLogger(threshold time.Duration) gin.HandlerFunc

func GoroutineHandler

func GoroutineHandler() gin.HandlerFunc

GoroutineHandler will pass the call from /debug/pprof/goroutine to pprof

func HeapHandler

func HeapHandler() gin.HandlerFunc

HeapHandler will pass the call from /debug/pprof/heap to pprof

func HttpFormRequest

func HttpFormRequest(method, addr string, urlParams url.Values, headers map[string]string) ([]byte, int, error)

func HttpForward

func HttpForward(w http.ResponseWriter, r *http.Request, forwardUrl string) error

func HttpPostJson

func HttpPostJson(addr string, urlParams url.Values, headers map[string]string, body interface{}) ([]byte, int, error)

func IndexHandler

func IndexHandler() gin.HandlerFunc

IndexHandler will pass the call from /debug/pprof to pprof

func InitGinAuth

func InitGinAuth(key string) error

func LoadCfgFromFile

func LoadCfgFromFile(filename string, config *Configure) error

example: LoadCfgFromFile("./config.json", cfg)

func MutexHandler

func MutexHandler() gin.HandlerFunc

MutexHandler will pass the call from /debug/pprof/mutex to pprof

func PKCS7Padding

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

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

func ProfileHandler

func ProfileHandler() gin.HandlerFunc

ProfileHandler will pass the call from /debug/pprof/profile to pprof

func SendFailResponse

func SendFailResponse(c *gin.Context, errCode int, errDesc string)

func SendSuccResponse

func SendSuccResponse(c *gin.Context, resp interface{})

func SendSuccSimpleResponse

func SendSuccSimpleResponse(c *gin.Context, content string)

func ShowAllRawBody

func ShowAllRawBody(c *gin.Context)

func SymbolHandler

func SymbolHandler() gin.HandlerFunc

SymbolHandler will pass the call from /debug/pprof/symbol to pprof

func ThreadCreateHandler

func ThreadCreateHandler() gin.HandlerFunc

ThreadCreateHandler will pass the call from /debug/pprof/threadcreate to pprof

func TimeCounter

func TimeCounter() func()

函数运行计时器,用法,在函数开始的地方添加: defer TimeCounter()()

func TraceHandler

func TraceHandler() gin.HandlerFunc

TraceHandler will pass the call from /debug/pprof/trace to pprof

func WrapGroup

func WrapGroup(router *gin.RouterGroup)

WrapGroup adds several routes from package `net/http/pprof` to *gin.RouterGroup object

Types

type AesCbcPKCS7

type AesCbcPKCS7 struct {
	AesObj cipher.Block
}
var AuthAes *AesCbcPKCS7

func NewAesCbcPKCS7

func NewAesCbcPKCS7(key string) *AesCbcPKCS7

func (*AesCbcPKCS7) AesCBCDecrypt

func (obj *AesCbcPKCS7) AesCBCDecrypt(encryptData []byte) ([]byte, error)

func (*AesCbcPKCS7) AesCBCEncrypt

func (obj *AesCbcPKCS7) AesCBCEncrypt(rawData []byte) ([]byte, error)

func (*AesCbcPKCS7) Decrypt

func (obj *AesCbcPKCS7) Decrypt(rawData string) (string, error)

func (*AesCbcPKCS7) Encrypt

func (obj *AesCbcPKCS7) Encrypt(rawData []byte) (string, error)

type Configure

type Configure struct {
	Listen        string
	LogSetting    LogConfig //推荐
	MysqlSetting  map[string]MysqlConfig
	RedisSetting  map[string]RedisConfig
	OssSetting    map[string]OssConfig
	External      map[string]string
	ExternalInt64 map[string]int64
	GormDebug     bool   //sql 输出开关
	Environment   string //环境变量区分, ONLINE/TEST
}
var Config *Configure

type Empty

type Empty struct{}

type FailResponse

type FailResponse struct {
	// 错误码。0为正常返回,其它为异常,异常时ErrDesc为异常描述。 固定的异常描述请存储于err_code_def.go文件中
	ErrCode int `json:"err_code"`
	// 错误信息。可展示在页面上
	ErrDesc string `json:"err_desc"`
	// 用于定位某次调用的ID,客户端应该在错误时显示(ErrCode:TraceId)
	TraceId string `json:"trace_id"`
}

swagger:model

type LogConfig

type LogConfig struct {
	LogDir   string
	LogFile  string
	LogLevel string
	LogSize  int
}

type MysqlConfig

type MysqlConfig struct {
	MysqlConn            string
	MysqlConnectPoolSize int
}

type OssConfig

type OssConfig struct {
	AccessKeyId     string
	AccessKeySecret string
	Region          string
	Bucket          string
}

type RedisConfig

type RedisConfig struct {
	RedisConn      string
	RedisPassword  string
	ReadTimeout    int
	ConnectTimeout int
	WriteTimeout   int
	IdleTimeout    int
	MinIdleConnNum int
	PoolSize       int
	RedisDb        int
}

type ResponseBase

type ResponseBase struct {
	// 错误码。这里的值为0,主要是为了返回体中有ErrCode字段
	ErrCode int `json:"err_code"`
}

swagger:model

type Set

type Set struct {
	M map[interface{}]Empty
}

func NewSet

func NewSet() *Set

func (*Set) Add

func (s *Set) Add(key interface{})

添加元素

func (*Set) Clear

func (s *Set) Clear()

清空set

func (*Set) Exist

func (s *Set) Exist(key interface{}) bool

检查是否存在

func (*Set) Len

func (s *Set) Len() int

获取长度

func (*Set) Remove

func (s *Set) Remove(key interface{})

删除元素

type SimpleResponse

type SimpleResponse struct {
	// 错误码。这里的值为0,主要是为了返回体中有ErrCode字段
	ErrCode int `json:"err_code"`
	// 返回的内容
	Content string `json:"content"`
}

swagger:model

type UserAgent

type UserAgent struct {
	AppVersion        string `json:"app_version"`
	MobilePlatform    string `json:"mobile_platform"`
	MobileSystem      string `json:"mobile_system"`
	MobileDeviceBrand string `json:"mobile_device_brand"`
}

Directories

Path Synopsis
Package g exposes goroutine struct g to user space.
Package g exposes goroutine struct g to user space.

Jump to

Keyboard shortcuts

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