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(space, 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, opts ...grpc.DialOption) (*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 PromeMetrics() gin.HandlerFunc
- func PromeTrace(label string) func()
- func PromeUnaryInterceptor() grpc.ServerOption
- 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 TraceUnaryInt(ctx context.Context, method string, req, reply interface{}, ...) error
- func UUID() string
- func UnixTime(timeStr, layout string) int64
- func Warnf(fomart string, v ...interface{})
- func WithTrace() grpc.DialOption
- 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 GrpcConn
- type GrpcConnManager
- type GrpcConnecter
- 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 MqttSubPub
- type Queue
- type QueueManager
- 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 ¶
func GrpcRecovery(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)
GrpcRecovery grpc接口panic恢复中间件
func LoadOrSaveJSON ¶
LoadOrSaveJSON 解析name.json,不存在保存
func LoadOrSaveToml ¶
LoadOrSaveToml 解析name.toml,不存在保存
func LogControl ¶
func LogControl(trace bool, skip []string) gin.HandlerFunc
LogControl 控制gin是否输出log
func NewGrpcConn ¶
func NewGrpcConn(addr string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
NewGrpcConn 创建grpc.ClientConn,with insecure and block
func NewRedisClient ¶
NewRedisClient 根据db编号创建redis.Client
func NewRedisClients ¶
NewRedisClients 创建redis.Client map以db编号为key
func PromeUnaryInterceptor ¶
func PromeUnaryInterceptor() grpc.ServerOption
PromeUnaryInterceptor promethous grpc中间件
func PromethousHandler ¶
func PromethousHandler() gin.HandlerFunc
PromethousHandler 启动promethous http监听
func TraceUnaryInt ¶
func TraceUnaryInt(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error
TraceUnaryInt 计算客户端请求耗时
func WithTrace ¶ added in v0.0.3
func WithTrace() grpc.DialOption
WithTrace 返回TraceUnaryInt的DialOption
Types ¶
type App ¶
type App struct { Na string Start func() bool Stop func() Svrs []ServerInterface }
App 内置App
func NewApp ¶
func NewApp(name string, start func() bool, stop func(), svrs ...ServerInterface) *App
NewApp 创建内置App
func (*App) Servers ¶
func (a *App) Servers() []ServerInterface
Servers 实现 Servers() []ServerInterface 接口
type AppInterface ¶
type AppInterface interface { Name() string Servers() []ServerInterface OnStart() bool OnStop() }
AppInterface 应用实现接口
type DSN ¶
type DSN struct { Username string Password string URL string Port string DBName string SkipTran bool PreStmt bool LogLevel logger.LogLevel }
DSN 连接数据库路由参数
type GinServer ¶
GinServer 包含gin的http server
func (*GinServer) Group ¶
func (s *GinServer) Group(path string, handlers ...gin.HandlerFunc) *gin.RouterGroup
Group 创建gin.RouterGroup
func (*GinServer) Promethous ¶
Promethous 启动Promethous监听
type GormDB ¶
GormDB 内嵌*gorm.DB,添加封装方法
func MustOpenPostgres ¶
MustOpenPostgres 无错的连接Postgres返回*gorm.DB
func (*GormDB) BatchInsert ¶
BatchInsert 批量插入数据
type GrpcConn ¶ added in v0.0.3
type GrpcConn struct {
// contains filtered or unexported fields
}
GrpcConn grpc连接执行
type GrpcConnManager ¶ added in v0.0.3
type GrpcConnManager struct {
// contains filtered or unexported fields
}
GrpcConnManager grpc连接管理器
func NewGrpcConnManager ¶ added in v0.0.3
func NewGrpcConnManager() *GrpcConnManager
NewGrpcConnManager 创建grpc连接管理器
func (*GrpcConnManager) AddConn ¶ added in v0.0.3
func (gm *GrpcConnManager) AddConn(name, addr string, connecter GrpcConnecter, opts ...grpc.DialOption)
AddConn 添加grpc连接
func (*GrpcConnManager) CloseConns ¶ added in v0.0.3
func (gm *GrpcConnManager) CloseConns()
CloseConns 关闭所有连接
func (*GrpcConnManager) Reconnect ¶ added in v0.0.3
func (gm *GrpcConnManager) Reconnect(name string)
Reconnect 重新grpc连接
type GrpcConnecter ¶ added in v0.0.3
type GrpcConnecter interface {
OnConnected(*grpc.ClientConn)
}
GrpcConnecter grpc连接接口
type GrpcServer ¶
type GrpcServer struct { Name string Addr string *grpc.Server Register func(*GrpcServer) }
GrpcServer 封装grpc server
func NewGrpcServer ¶
func NewGrpcServer(name, addr string, reg func(*GrpcServer), opt ...grpc.ServerOption) *GrpcServer
NewGrpcServer 创建GrpcServer
type HttpClient ¶
HttpClient 嵌入http.Client,添加一些方法
func (*HttpClient) GetJSON ¶
func (c *HttpClient) GetJSON(url string, data interface{}) (err error)
GetJSON GET请求,解析JSON
func (*HttpClient) GetJSONAuth ¶
func (c *HttpClient) GetJSONAuth(url, un, pa string, data interface{}) (err error)
GetJSONAuth GET请求带BasicAuth认证,解析JSON
func (*HttpClient) PostFormJSON ¶
func (c *HttpClient) PostFormJSON(url string, vals url.Values, data interface{}) (err error)
PostFormJSON POST请求,参数Form表单,解析JSON
func (*HttpClient) PostFormJSONAuth ¶
func (c *HttpClient) PostFormJSONAuth(url, un, pa string, vals url.Values, data interface{}) (err error)
PostFormJSONAuth POST请求带BasicAuth认证,参数Form表单,解析JSON
func (*HttpClient) PostJSON ¶
func (c *HttpClient) PostJSON(url string, src, data interface{}) (err error)
PostJSON POST JSON请求,解析JSON
func (*HttpClient) PostJSONAuth ¶
func (c *HttpClient) PostJSONAuth(url, un, pa string, src, data interface{}) (err error)
PostJSONAuth POST JSON请求带BasicAuth认证,解析JSON
type MqttSubPub ¶
type MqttSubPub struct {
// contains filtered or unexported fields
}
MqttSubPub MQTT发布订阅
func NewMqttSubPub ¶
func NewMqttSubPub(id, addr, user, pass string, topics ...string) *MqttSubPub
NewMqttSubPub 创建MqttSubPub
func (*MqttSubPub) SetSubDeal ¶
func (m *MqttSubPub) SetSubDeal(deal func(mqtt.Message))
SetSubDeal 设置订阅处理回调
type QueueManager ¶
type QueueManager struct {
// contains filtered or unexported fields
}
QueueManager 队列管理器
func (*QueueManager) PushQueue ¶
func (qm *QueueManager) PushQueue(i int, args interface{}, async bool)
PushQueue 添加任务到管理器队列中
type Resp ¶
type Resp struct { Code int `json:"code"` Data interface{} `json:"data,omitempty"` }
Resp http统一返回结构
type ServerInterface ¶
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