Documentation
¶
Index ¶
- Constants
- Variables
- func ArgumentError(format string, a ...any) error
- func CheckQueryPaging(paging *common.Page, defaultPageSize int32) *common.Page
- func CommitFence(ctx context.Context, db *gorm.DB, ...) (ok bool, err error)
- func CookieToAuth(cookieKey string) func(ctx context.Context, req *http.Request) metadata.MD
- func CurrentDB(ctx context.Context, db *gorm.DB) *gorm.DB
- func CustomErrorHandler(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, ...)
- func DeleteError(obj string) error
- func GetFilterTime(start, end string) (startTime, endTime string, err error)
- func GetResultPaging(query *common.Page, totalCount int32) (result *common.Page)
- func GetTraceId(ctx context.Context) string
- func GetTxLogObj(ctx context.Context, txLogObj interface{}) (err error)
- func GetUserName(ctx context.Context) string
- func GetXidFromContext(ctx context.Context) string
- func InitMetrics()
- func InitTracerProvider(name, addr string) error
- func InterceptorLogger(l logrus.FieldLogger) logging.Logger
- func InternalError(format string, a ...any) error
- func LogWithContext(ctx context.Context) *logrus.Entry
- func NewGormDB(dsn string) (*gorm.DB, error)
- func NewORMOptsContext(ctx context.Context, opts ...ORMOption) context.Context
- func NewTxContext(ctx context.Context, db *gorm.DB) context.Context
- func NotFoundError(err error) error
- func NotTxContext(ctx context.Context) context.Context
- func OK(ctx context.Context) *common.Status
- func PermissionDeniedError() error
- func PrepareFence(ctx context.Context, db *gorm.DB, ...) (ok bool, err error)
- func QueryError(obj string) error
- func RespOK(ctx context.Context) *common.Response
- func RollbackFence(ctx context.Context, db *gorm.DB, ...) (ok bool, err error)
- func SetClaimsWithContext(ctx context.Context, claims *CustomClaims) context.Context
- func TxFromContext(ctx context.Context) *gorm.DB
- func UpdateError(obj string) error
- func WithJwtAuth(signKey string, filterMethods ...string) grpc.UnaryServerInterceptor
- func WithLogger() grpc.UnaryServerInterceptor
- func WithMetrics() grpc.UnaryServerInterceptor
- func WithRateLimit(num int) grpc.UnaryServerInterceptor
- func WithRecovery() grpc.UnaryServerInterceptor
- func WithTrace(h http.Handler) http.Handler
- func WithValidator() grpc.UnaryServerInterceptor
- type CustomClaims
- type ErrResp
- type GormTracer
- type JWT
- type ORMOption
- type Status
- type TokenBucket
- type TxLog
- type TxLogState
Constants ¶
View Source
const AfterName = "gorm.after"
View Source
const BeforeName = "gorm.before"
View Source
const GormTrace = "gorm.trace"
View Source
const OneDayTimestamp = 86400
Variables ¶
View Source
var ( TokenExpired = errors.New("expired token") TokenNotValidYet = errors.New("unactivated token") TokenMalformed = errors.New("unknown token") TokenInvalid = errors.New("invalid token") )
View Source
var ClaimsKey struct{}
View Source
var PanicCounterMetrics = prometheus.NewCounter(prometheus.CounterOpts{
Name: "grpc_req_panics_recovered_total",
Help: "Total number of gRPC requests recovered from internal panic.",
})
View Source
var SrvMetrics = grpcprom.NewServerMetrics( grpcprom.WithServerHandlingTimeHistogram( grpcprom.WithHistogramBuckets([]float64{0.001, 0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120}), ), )
Functions ¶
func ArgumentError ¶
func CheckQueryPaging ¶ added in v0.0.3
func CommitFence ¶
func CookieToAuth ¶
CookieToAuth Specifies that the value of the cookie key is converted to the value of the header Authorization
func CustomErrorHandler ¶
func CustomErrorHandler(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, writer http.ResponseWriter, request *http.Request, err error)
CustomErrorHandler custom Error Handler for HTTP Server
func DeleteError ¶
func GetFilterTime ¶ added in v0.0.3
func GetResultPaging ¶ added in v0.0.3
func GetTxLogObj ¶
func GetUserName ¶
func GetXidFromContext ¶
func InitMetrics ¶
func InitMetrics()
func InitTracerProvider ¶
InitTracerProvider init tracer Provider
func InterceptorLogger ¶
func InterceptorLogger(l logrus.FieldLogger) logging.Logger
InterceptorLogger adapts logrus logger to interceptor logger.
func InternalError ¶
func LogWithContext ¶
LogWithContext get logger with fields(traceId,spanId)
func NewORMOptsContext ¶
func NewTxContext ¶
NewTxContext ctx传递事务连接
func NotFoundError ¶
func NotTxContext ¶
NotTxContext context清理事务DB
func PermissionDeniedError ¶
func PermissionDeniedError() error
func PrepareFence ¶
func QueryError ¶
func RollbackFence ¶
func SetClaimsWithContext ¶
func SetClaimsWithContext(ctx context.Context, claims *CustomClaims) context.Context
func UpdateError ¶
func WithJwtAuth ¶
func WithJwtAuth(signKey string, filterMethods ...string) grpc.UnaryServerInterceptor
func WithLogger ¶
func WithLogger() grpc.UnaryServerInterceptor
func WithMetrics ¶
func WithMetrics() grpc.UnaryServerInterceptor
func WithRateLimit ¶
func WithRateLimit(num int) grpc.UnaryServerInterceptor
WithRateLimit return a new unary server interceptors that performs request rate limiting.
func WithRecovery ¶
func WithRecovery() grpc.UnaryServerInterceptor
func WithValidator ¶
func WithValidator() grpc.UnaryServerInterceptor
Types ¶
type CustomClaims ¶
type CustomClaims struct { UID string Username string NickName string AuthorityId string jwt.StandardClaims }
func GetClaims ¶
func GetClaims(ctx context.Context) *CustomClaims
type GormTracer ¶
type GormTracer struct {
// contains filtered or unexported fields
}
GormTracer gorm trace追踪
func NewGormTracer ¶
func NewGormTracer(db *gorm.DB, spanName string) *GormTracer
func (*GormTracer) Init ¶
func (g *GormTracer) Init() error
type JWT ¶
type JWT struct {
SigningKey []byte
}
func (*JWT) CreateToken ¶
func (j *JWT) CreateToken(claims CustomClaims) (string, error)
CreateToken 创建一个token
func (*JWT) ParseToken ¶
func (j *JWT) ParseToken(tokenString string) (*CustomClaims, error)
ParseToken 解析 token
type ORMOption ¶
func ORMOptsFromContext ¶
ORMOptsFromContext 获取orm的options
type TokenBucket ¶
type TokenBucket struct { Num int // 当前桶中的令牌数据 Size int // 木桶中令牌的容量 Rate time.Duration // 生成一个令牌所需要的时间 UpdateTime time.Time // 记录每次令牌桶更新时间 }
TokenBucket 令牌桶结构体
func NewTokenBucket ¶
func NewTokenBucket(size int, rate time.Duration) *TokenBucket
NewTokenBucket 创建令牌桶
type TxLogState ¶
type TxLogState int8
const ( TxLogStateInit TxLogState = iota TxLogStateCommit TxLogStateRollback )
Click to show internal directories.
Click to hide internal directories.