Documentation ¶
Index ¶
- Constants
- Variables
- func BasicAuth(username, password string) gin.HandlerFunc
- func CORS(acceptedOrigin, AcceptedMethods, AcceptedHeaders, MaxAge string) gin.HandlerFunc
- func CreateFolder(path string) error
- func Errf(fomart string, v ...interface{})
- func GetCaller(d int) (string, int)
- func GetRealIP(req *http.Request) string
- func GrpcRecovery(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (resp interface{}, err error)
- func GzipJSON(c *gin.Context, data interface{})
- func HeadSeparator(path string) string
- func InitPrometheus(name string)
- func JSON(c *gin.Context, data interface{})
- func JsonErr(c *gin.Context, err error)
- func JsonMsg(c *gin.Context, msg string)
- func JsonOK(c *gin.Context, data interface{})
- func LoadJSON(name string, data interface{}) error
- func LoadOrSaveJSON(name string, res interface{}, def func() interface{}) (err error)
- func LoadOrSaveToml(name string, data interface{}, def func() interface{}) (err error)
- func LoadToml(name string, data interface{}) error
- func LogControl(trace bool, skip []string) gin.HandlerFunc
- func LogErr(err error, msg string)
- func Logf(fomart string, v ...interface{})
- func MD5(src string) []byte
- func NewGrpcConn(addr string) (*grpc.ClientConn, error)
- func NewRedisClient(addr, pass string, db int) *redis.Client
- func NewRedisClients(addr, pass string) (clients map[int]*redis.Client, err error)
- func NoCache() gin.HandlerFunc
- func PromMetrics() gin.HandlerFunc
- func PrometheusInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (resp interface{}, err error)
- func PromethousHandler() gin.HandlerFunc
- func RandomString(n int) string
- func Run(app AppInterface)
- func SaveJSON(name string, data interface{}) error
- func SaveToml(name string, data interface{}) error
- func StrTime(timestamp int64, timeLayout string) string
- func TailSeparator(path string) string
- func ToJsonStr(data interface{}) string
- func Trace(msg string) func()
- func UUID() string
- func UnixTime(timeStr, layout string) int64
- type App
- type AppInterface
- type DSN
- type GinServer
- type GormDB
- func (db *GormDB) BatchInsert(tb string, value interface{}, batchSize int) error
- func (gdb *GormDB) CloseDB()
- func (db *GormDB) ExecSQL(sql string, values ...interface{}) (int64, error)
- func (db *GormDB) Insert(tb string, value interface{}) error
- func (db *GormDB) Query(dest interface{}, stmt string, values ...interface{}) error
- func (db *GormDB) QueryRow(stmt string, values ...interface{}) *sql.Row
- func (db *GormDB) QueryRows(hand func(*sql.Rows) error, sql string, values ...interface{}) (err error)
- type GrpcServer
- type HttpClient
- func (c *HttpClient) GetJSON(url string, data interface{}) (err error)
- func (c *HttpClient) GetJSONAuth(url, un, pa string, data interface{}) (err error)
- func (c *HttpClient) PostFormJSON(url string, vals url.Values, data interface{}) (err error)
- func (c *HttpClient) PostFormJSONAuth(url, un, pa string, vals url.Values, data interface{}) (err error)
- func (c *HttpClient) PostJSON(url string, src, data interface{}) (err error)
- func (c *HttpClient) PostJSONAuth(url, un, pa string, src, data interface{}) (err error)
- type Queue
- type Resp
- type Serial
- type ServerInterface
- type StmtDB
- type TStamp
- type XmlMap
Constants ¶
const ( CodeOK = iota CodeErr )
返回code值
const ( // TimeLayout1 2006-01-02 15:04:05 TimeLayout1 = "2006-01-02 15:04:05" // TimeLayout2 2006-01-02 TimeLayout2 = "2006-01-02" // TimeLayout3 15:04:05 TimeLayout3 = "15:04:05" // TimeLayout4 20060102150405 TimeLayout4 = "20060102150405" // TimeLayout5 20060102 TimeLayout5 = "20060102" // TimeLayout6 150405 TimeLayout6 = "150405" // TimeLayout7 2006.01.02 TimeLayout7 = "2006.01.02" // TimeLayout8 2006/01/02 TimeLayout8 = "2006/01/02" )
timestamp format layout
Variables ¶
var ( RequestCounter *prometheus.CounterVec LatencyHistogram *prometheus.HistogramVec DurationsSummary *prometheus.SummaryVec )
prmethous监控变量
Functions ¶
func CORS ¶
func CORS(acceptedOrigin, AcceptedMethods, AcceptedHeaders, MaxAge string) gin.HandlerFunc
CORS 设置跨域
func GrpcRecovery ¶ added in v0.0.7
func GrpcRecovery(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)
GrpcRecovery grpc接口panic恢复中间件
func HeadSeparator ¶ added in v0.0.3
HeadSeparator 确保path以/开头
func LoadOrSaveJSON ¶ added in v0.0.3
LoadOrSaveJSON 解析name.json,不存在保存
func LoadOrSaveToml ¶ added in v0.0.3
LoadOrSaveToml 解析name.toml,不存在保存
func LogControl ¶ added in v0.0.3
func LogControl(trace bool, skip []string) gin.HandlerFunc
LogControl 控制gin是否输出log
func NewGrpcConn ¶ added in v0.0.3
func NewGrpcConn(addr string) (*grpc.ClientConn, error)
NewGrpcConn 创建grpc.ClientConn,with insecure and block
func NewRedisClient ¶ added in v0.0.3
NewRedisClient 根据db编号创建redis.Client
func NewRedisClients ¶ added in v0.0.3
NewRedisClients 创建redis.Client map以db编号为key
func PromMetrics ¶ added in v0.0.6
func PromMetrics() gin.HandlerFunc
PromMetrics prometheus metrics 中间件
func PrometheusInterceptor ¶ added in v0.0.6
func PrometheusInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)
PrometheusInterceptor promethous grpc中间件
func PromethousHandler ¶ added in v0.0.6
func PromethousHandler() gin.HandlerFunc
PromethousHandler 启动promethous http监听
func TailSeparator ¶ added in v0.0.3
TailSeparator 确保path以/结尾
Types ¶
type App ¶ added in v0.0.3
type App struct { Na string Start func() bool Stop func() Svrs []ServerInterface }
App 内置App
func (*App) Servers ¶ added in v0.0.3
func (a *App) Servers() []ServerInterface
Servers 实现 Servers() []ServerInterface 接口
type AppInterface ¶ added in v0.0.3
type AppInterface interface { Name() string Servers() []ServerInterface OnStart() bool OnStop() }
AppInterface 应用实现接口
type DSN ¶ added in v0.0.3
type DSN struct { Username string Password string URL string Port string DBName string SkipTran bool PreStmt bool LogLevel logger.LogLevel }
DSN 连接数据库路由参数
type GinServer ¶ added in v0.0.3
GinServer 包含gin的http server
func NewGinServer ¶ added in v0.0.3
NewGinServer 创建GinServer
func (*GinServer) Group ¶ added in v0.0.3
func (s *GinServer) Group(path string, handlers ...gin.HandlerFunc) *gin.RouterGroup
Group 创建gin.RouterGroup
func (*GinServer) Promethous ¶ added in v0.0.6
Promethous 启动Promethous监听
type GormDB ¶ added in v0.0.3
GormDB 内嵌*gorm.DB,添加封装方法
func MustOpenMySQL ¶ added in v0.0.3
MustOpenMySQL 无错的连接MySQL返回*gorm.DB
func MustOpenPostgres ¶ added in v0.0.3
MustOpenPostgres 无错的连接Postgres返回*gorm.DB
func (*GormDB) BatchInsert ¶ added in v0.0.4
BatchInsert 批量插入数据
type GrpcServer ¶ added in v0.0.3
type GrpcServer struct { Name string Addr string *grpc.Server Register func(*GrpcServer) }
GrpcServer 封装grpc server
func NewGrpcServer ¶ added in v0.0.3
func NewGrpcServer(name, addr string, reg func(*GrpcServer), opt ...grpc.ServerOption) *GrpcServer
NewGrpcServer 创建GrpcServer
func (*GrpcServer) Info ¶ added in v0.0.3
func (gs *GrpcServer) Info() string
Info 实现ServerInterface接口
func (*GrpcServer) OnStart ¶ added in v0.0.3
func (gs *GrpcServer) OnStart() bool
OnStart 实现ServerInterface接口
func (*GrpcServer) OnStop ¶ added in v0.0.3
func (gs *GrpcServer) OnStop()
OnStop 实现ServerInterface接口
type HttpClient ¶ added in v0.0.3
HttpClient 嵌入http.Client,添加一些方法
func (*HttpClient) GetJSON ¶ added in v0.0.3
func (c *HttpClient) GetJSON(url string, data interface{}) (err error)
GetJSON GET请求,解析JSON
func (*HttpClient) GetJSONAuth ¶ added in v0.0.3
func (c *HttpClient) GetJSONAuth(url, un, pa string, data interface{}) (err error)
GetJSONAuth GET请求带BasicAuth认证,解析JSON
func (*HttpClient) PostFormJSON ¶ added in v0.0.3
func (c *HttpClient) PostFormJSON(url string, vals url.Values, data interface{}) (err error)
PostFormJSON POST请求,参数Form表单,解析JSON
func (*HttpClient) PostFormJSONAuth ¶ added in v0.0.3
func (c *HttpClient) PostFormJSONAuth(url, un, pa string, vals url.Values, data interface{}) (err error)
PostFormJSONAuth POST请求带BasicAuth认证,参数Form表单,解析JSON
func (*HttpClient) PostJSON ¶ added in v0.0.3
func (c *HttpClient) PostJSON(url string, src, data interface{}) (err error)
PostJSON POST JSON请求,解析JSON
func (*HttpClient) PostJSONAuth ¶ added in v0.0.3
func (c *HttpClient) PostJSONAuth(url, un, pa string, src, data interface{}) (err error)
PostJSONAuth POST JSON请求带BasicAuth认证,解析JSON
type Resp ¶
type Resp struct { Code int `json:"code"` Data interface{} `json:"data,omitempty"` }
Resp http统一返回结构
type ServerInterface ¶ added in v0.0.3
ServerInterface 服务实现接口
type StmtDB ¶
StmtDB 嵌入sqlx.DB,加了statement缓存
func (*StmtDB) DeferLock ¶
func (s *StmtDB) DeferLock() func()
DeferLock 合并锁的使用 example: defer s.DeferLock()()
type TStamp ¶
type TStamp int64
TStamp custom type for int64
func (TStamp) MarshalJSON ¶
MarshalJSON implement Marshaler
func (*TStamp) UnmarshalJSON ¶
UnmarshalJSON implement Unmarshaler
type XmlMap ¶
XmlMap xml转换map
func (XmlMap) MarshalXML ¶
MarshalXML marshals the map to XML
func (*XmlMap) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a map of string to strings