eagle

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

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

Go to latest
Published: Dec 29, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

README

bw-eagle

High performance go framework based on gin customization

Documentation

Index

Constants

View Source
const (
	DeployEnvDev  = "Development"
	DeployEnvTest = "Test"
	DeployEnvProd = "Production"

	NamespaceDev  = "dev"
	NamespaceTest = "test"
)
View Source
const (
	Success = 0

	ErrUnknown  = 99999 // 未知错误
	ErrInternal = 99998 // 内部错误
	ErrMysql    = 99997 // Mysql错误
	ErrRedis    = 99996 // Redis错误

	ErrParam = 10001 // 参数错误
)

Variables

View Source
var (
	// Http
	HttpEngine *BwHttpEngine
	// Mysql
	MysqlEngine *MysqlClient
	// Redis
	RedisEngine *redis.BwRedisClient
	// MysqlCluster
	MysqlCluster BwMysqlCluster
)

Functions

func AbortRequest

func AbortRequest(c *gin.Context, resp *Response)

终止请求

func AccessLogHandler

func AccessLogHandler() gin.HandlerFunc

接口开启访问日志

func BodySign

func BodySign(key, body string) (string, error)

生成请求体签名

func CheckEnv

func CheckEnv(env string) error

检测运行环境

func ConfigError

func ConfigError(config string) error

func ConfigNotFound

func ConfigNotFound(config string) error

func ErrMsg

func ErrMsg(errCode int) string

获取应用设置的错误信息

func GetBool

func GetBool(key string) bool

func GetConfig

func GetConfig(key string) interface{}

func GetDuration

func GetDuration(key string) time.Duration

func GetEnv

func GetEnv() string

获取运行环境

func GetFloat64

func GetFloat64(key string) float64

func GetInt

func GetInt(key string) int

func GetInt32

func GetInt32(key string) int32

func GetInt64

func GetInt64(key string) int64

func GetOceanApp

func GetOceanApp() string

func GetOceanMode

func GetOceanMode() string

获取 OCEAN_MODE

func GetOceanNamespace

func GetOceanNamespace() string

func GetOceanPodIp

func GetOceanPodIp() string

func GetOceanPodName

func GetOceanPodName() string

func GetOceanVersion

func GetOceanVersion() string

func GetRequestBody

func GetRequestBody(ctx context.Context) string

获取请求body

func GetRequestURI

func GetRequestURI(ctx context.Context) string

获取请求URI

func GetString

func GetString(key string) string

func GetStringMap

func GetStringMap(key string) map[string]interface{}

func GetStringMapString

func GetStringMapString(key string) map[string]string

func GetStringMapStringSlice

func GetStringMapStringSlice(key string) map[string][]string

func GetStringSlice

func GetStringSlice(key string) []string

func GetTime

func GetTime(key string) time.Time

func GetUint

func GetUint(key string) uint

func GetUint32

func GetUint32(key string) uint32

func GetUint64

func GetUint64(key string) uint64

func JsonResponse

func JsonResponse(c *gin.Context, code int, message, result interface{})

func LogAddCustomHeader

func LogAddCustomHeader(header string)

设置日志打印哪些header,非空时打印到日志中

func LogCritical

func LogCritical(ctx context.Context, a interface{})

func LogDebug

func LogDebug(ctx context.Context, a interface{})

func LogError

func LogError(ctx context.Context, a interface{})

func LogInfo

func LogInfo(ctx context.Context, a interface{})

func LogWarn

func LogWarn(ctx context.Context, a interface{})

func New

func New() error

func NewConfig

func NewConfig() error

func NewHttp

func NewHttp() error

func RenderJson

func RenderJson(c *gin.Context, resp *Response)

func Run

func Run() error

启动服务

func RunHttp

func RunHttp() error

func SetErrMsg

func SetErrMsg(errCode int, message string) error

设置应用的错误信息

Types

type BwHttpEngine

type BwHttpEngine struct {
	*gin.Engine
}

type BwMysqlCluster

type BwMysqlCluster map[int]*xorm.Engine

func NewMysqlCluster

func NewMysqlCluster(configs []*mysqlClusterConfig) (BwMysqlCluster, error)

简易版mysql集群多实例 TODO 某实例宕机后如何让上层业务感知,摘除该实例 TODO 某实例宕机一段时间后又恢复了如何让上层业务感知,启用该实例

func (*BwMysqlCluster) Engine

func (mc *BwMysqlCluster) Engine(id int) *xorm.Engine

返回集群中某一个实例,使用时最好判断是否为nil

func (*BwMysqlCluster) Engines

func (mc *BwMysqlCluster) Engines() map[int]*xorm.Engine

返回所有实例

func (*BwMysqlCluster) FirstEngine

func (mc *BwMysqlCluster) FirstEngine() *xorm.Engine

返回首个实例

type HttpClient

type HttpClient struct {
	*middleware.HttpClient
}

func NewHttpClient

func NewHttpClient(t time.Duration) *HttpClient

func (*HttpClient) Get

func (client *HttpClient) Get(ctx context.Context, url string, query map[string]string, headers map[string]string) (string, error)

func (*HttpClient) MultiplePost

func (client *HttpClient) MultiplePost(ctx context.Context, url string, params map[string]string, headers map[string]string, bodyList map[int]interface{}) (map[int]string, map[int]error)

Content-Type 是 application/json;charset=utf-8

func (*HttpClient) OriginPost

func (client *HttpClient) OriginPost(ctx context.Context, url string, query map[string]string, headers map[string]string, body string) (string, error)

Content-Type 自定义

func (*HttpClient) Post

func (client *HttpClient) Post(ctx context.Context, url string, query map[string]string, headers map[string]string, body interface{}) (string, error)

Content-Type 是 application/json;charset=utf-8

func (*HttpClient) TFormGet

func (client *HttpClient) TFormGet(ctx context.Context, addr string, query map[string]string, headers map[string]string) (string, error)

请求第三方服务 Content-Type 是 application/x-www-form-urlencoded 无链路追踪

func (*HttpClient) TFormPost

func (client *HttpClient) TFormPost(ctx context.Context, addr string, query map[string]string, headers map[string]string, body map[string]string) (string, error)

请求第三方服务 Content-Type 是 application/x-www-form-urlencoded 无链路追踪

type Model

type Model struct {
	// contains filtered or unexported fields
}

func NewModel

func NewModel(table string) *Model

func (*Model) Count

func (m *Model) Count(cond map[string]interface{}) (count int64, err error)

func (*Model) Find

func (m *Model) Find(record interface{}, cond ...interface{}) error

func (*Model) FindAndCount

func (m *Model) FindAndCount(record interface{}, cond ...interface{}) (int64, error)

func (*Model) Get

func (m *Model) Get(cond map[string]interface{}, result interface{}) (err error)

func (*Model) Insert

func (m *Model) Insert(data interface{}) (int64, error)

func (*Model) InsertMulti

func (m *Model) InsertMulti(rowsSlicePtr interface{}) (int64, error)

func (*Model) InsertOne

func (m *Model) InsertOne(data interface{}) (int64, error)

func (*Model) Update

func (m *Model) Update(cond, fields map[string]interface{}) (int64, error)

type MysqlClient

type MysqlClient struct {
	*xorm.Engine
}

func NewMysql

func NewMysql(config *mysqlConfig) (*MysqlClient, error)

func (*MysqlClient) Status

func (e *MysqlClient) Status() *MysqlStatus

type MysqlStatus

type MysqlStatus struct {
	// 数据库状态统计
	DDStats *sql.DBStats
}

type Response

type Response struct {
	// contains filtered or unexported fields
}

func NewCodeResponse

func NewCodeResponse(errCode int, result interface{}) *Response

func NewResponse

func NewResponse(errCode int, message, result interface{}) *Response

func (*Response) GetErrCode

func (r *Response) GetErrCode() int

func (*Response) GetMessage

func (r *Response) GetMessage() interface{}

func (*Response) GetResult

func (r *Response) GetResult() interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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