pkg

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: Zlib Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ComponentRedisServer     = 7
	ComponentIDGINHttpServer = 5006
)

Variables

View Source
var API = &APIPkg{}
View Source
var Apollo = &ApolloPkg{Viper: viper.New()}
View Source
var Config = &ConfigPkg{}
View Source
var Database = &DatabasePkg{}
View Source
var GCM = &GoroutineContextManager{
	GlobalGinContextKey: "ppw_gin_context",
}
View Source
var HTTP = &HTTPPkg{}
View Source
var RedisCli = &Redis{}
View Source
var Tracer = &TracerPkg{}

Functions

This section is empty.

Types

type APIPkg added in v0.9.6

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

func (*APIPkg) GetResponse added in v0.9.6

func (p *APIPkg) GetResponse(data interface{}, err error, sqls ...string) (int, interface{})

func (*APIPkg) RegisterRoutes added in v0.9.6

func (p *APIPkg) RegisterRoutes(r *gin.Engine, routes ...Routes)

func (*APIPkg) RegisterValidates added in v0.9.6

func (p *APIPkg) RegisterValidates(validates []Validators)

type ApUpdateCallback added in v0.6.2

type ApUpdateCallback func(appId string, namespace string, changeKeys []string)

ApUpdateCallback 外部指定的apollo配置变更后的回调,用于外部跟进处理配置变更后的后续逻辑

type ApolloConfPkg added in v0.6.6

type ApolloConfPkg struct {
	Service  string                  `mapstructure:"service"`
	CacheDir string                  `mapstructure:"cache_dir"`
	App      map[string]AppConfigPkg `mapstructure:"app"`
}

type ApolloPkg

type ApolloPkg struct {
	*viper.Viper
	// contains filtered or unexported fields
}

func (*ApolloPkg) Alias added in v0.8.9

func (c *ApolloPkg) Alias(alias string) *ApolloPkg

func (*ApolloPkg) GetBool added in v0.6.9

func (c *ApolloPkg) GetBool(key string) bool

func (*ApolloPkg) GetDuration added in v0.6.9

func (c *ApolloPkg) GetDuration(key string) time.Duration

func (*ApolloPkg) GetFloat64 added in v0.6.9

func (c *ApolloPkg) GetFloat64(key string) float64

func (*ApolloPkg) GetInt added in v0.6.9

func (c *ApolloPkg) GetInt(key string) int

func (*ApolloPkg) GetInt32 added in v0.6.9

func (c *ApolloPkg) GetInt32(key string) int32

func (*ApolloPkg) GetInt64 added in v0.6.9

func (c *ApolloPkg) GetInt64(key string) int64

func (*ApolloPkg) GetIntSlice added in v0.6.9

func (c *ApolloPkg) GetIntSlice(key string) []int

func (*ApolloPkg) GetSizeInBytes added in v0.6.9

func (c *ApolloPkg) GetSizeInBytes(key string) uint

func (*ApolloPkg) GetString added in v0.6.9

func (c *ApolloPkg) GetString(key string) string

GetString 重写viper的配置获取方法,兼容键名前缀

func (*ApolloPkg) GetStringMap added in v0.6.9

func (c *ApolloPkg) GetStringMap(key string) map[string]any

func (*ApolloPkg) GetStringMapString added in v0.6.9

func (c *ApolloPkg) GetStringMapString(key string) map[string]string

func (*ApolloPkg) GetStringMapStringSlice added in v0.6.9

func (c *ApolloPkg) GetStringMapStringSlice(key string) map[string][]string

func (*ApolloPkg) GetStringMapStruct added in v0.7.7

func (c *ApolloPkg) GetStringMapStruct(key string, outputStruct interface{}) error

func (*ApolloPkg) GetStringSlice added in v0.6.9

func (c *ApolloPkg) GetStringSlice(key string) []string

func (*ApolloPkg) GetTime added in v0.6.9

func (c *ApolloPkg) GetTime(key string) time.Time

func (*ApolloPkg) GetUint added in v0.6.9

func (c *ApolloPkg) GetUint(key string) uint

func (*ApolloPkg) GetUint16 added in v0.6.9

func (c *ApolloPkg) GetUint16(key string) uint16

func (*ApolloPkg) GetUint32 added in v0.6.9

func (c *ApolloPkg) GetUint32(key string) uint32

func (*ApolloPkg) GetUint64 added in v0.6.9

func (c *ApolloPkg) GetUint64(key string) uint64

func (*ApolloPkg) Start added in v0.6.9

func (c *ApolloPkg) Start(apConf *ApolloConfPkg, callback ApUpdateCallback) error

Start 启动apollo配置中心,配置读写依赖viper

func (*ApolloPkg) Struct added in v0.8.9

func (c *ApolloPkg) Struct(alias string, outputStruct interface{}) error

func (*ApolloPkg) Update

func (c *ApolloPkg) Update(updates map[string]interface{}) error

Update 合并方式更新

type AppConfigPkg added in v0.6.9

type AppConfigPkg struct {
	AppID      string   `mapstructure:"app_id"`
	Cluster    string   `mapstructure:"cluster"`
	Secret     string   `mapstructure:"secret"`
	Namespaces []string `mapstructure:"namespaces"`
}

type Callback

type Callback func(*gorm.DB)

type ConfigPkg

type ConfigPkg struct {
	*viper.Viper
	ConfigPath     string // 本地配置文件路径
	ConfigType     string // 本地配置文件类型
	LocalStructMap map[string]interface{}
}

func (*ConfigPkg) GetStringMapStruct added in v0.7.7

func (c *ConfigPkg) GetStringMapStruct(key string, outputStruct interface{}) error

func (*ConfigPkg) Init

func (c *ConfigPkg) Init(configPath string, configType string)

Init 配置初始化

func (*ConfigPkg) Read

func (c *ConfigPkg) Read(file string) *ConfigPkg

Read 读取本地配置文件

func (*ConfigPkg) Update

func (c *ConfigPkg) Update(updates map[string]interface{}, prefix string) error

Update 动态写入本地配置文件

type CustomLogFormatter

type CustomLogFormatter struct{}

func (*CustomLogFormatter) Format

func (c *CustomLogFormatter) Format(entry *logrus.Entry) ([]byte, error)

type CustomLogHook

type CustomLogHook struct {
	LogDir     string
	Log2Tracer bool
	// contains filtered or unexported fields
}

func (*CustomLogHook) Fire

func (hook *CustomLogHook) Fire(entry *logrus.Entry) error

func (*CustomLogHook) Levels

func (hook *CustomLogHook) Levels() []logrus.Level

type DBPoolConfig added in v0.9.6

type DBPoolConfig struct {
	Type            string `mapstructure:"type"`
	Host            string `mapstructure:"host"`
	Port            int    `mapstructure:"port"`
	User            string `mapstructure:"user"`
	Password        string `mapstructure:"password"`
	Database        string `mapstructure:"db"`
	Charset         string `mapstructure:"charset"`
	TablePrefix     string `mapstructure:"table_prefix"`
	MaxOpenConns    int    `mapstructure:"max_open_conns"`     // 最大连接数
	MaxIdleConns    int    `mapstructure:"max_idle_conns"`     // 最大空闲连接数
	ConnMaxLifetime int    `mapstructure:"conn_max_lifetime"`  // 连接的最大存活时间
	ConnMaxIdleTime int    `mapstructure:"conn_max_idle_time"` // 连接空闲超时
}

type DatabasePkg

type DatabasePkg struct {
}

func (*DatabasePkg) GetDB added in v0.9.6

func (c *DatabasePkg) GetDB(config *DBPoolConfig) *gorm.DB

func (*DatabasePkg) Init

func (c *DatabasePkg) Init(dbc *DBPoolConfig, callback Callback)

type Entry added in v0.9.0

type Entry struct {
	*logrus.Entry
}

func (*Entry) Debug added in v0.9.5

func (e *Entry) Debug(args ...interface{})

func (*Entry) Error added in v0.9.0

func (e *Entry) Error(args ...interface{})

func (*Entry) Fatal added in v0.9.5

func (e *Entry) Fatal(args ...interface{})

func (*Entry) Info added in v0.9.0

func (e *Entry) Info(args ...interface{})

func (*Entry) Panic added in v0.9.5

func (e *Entry) Panic(args ...interface{})

func (*Entry) Trace added in v0.9.5

func (e *Entry) Trace(args ...interface{})

func (*Entry) Warn added in v0.9.0

func (e *Entry) Warn(args ...interface{})

type EntrySpanOptions

type EntrySpanOptions struct {
	OperationName string
	Component     int32
	Extractor     propagation.Extractor
	Log           []string
	Layer         agentV3.SpanLayer
}

type ExitSpanOptions

type ExitSpanOptions struct {
	OperationName string
	Component     int32
	Log           []string
	Layer         agentV3.SpanLayer
	Peer          string
	Injector      propagation.Injector
}

type GormLogger

type GormLogger struct {
}

func (*GormLogger) Error

func (p *GormLogger) Error(_ context.Context, _ string, _ ...interface{})

func (*GormLogger) Info

func (p *GormLogger) Info(_ context.Context, _ string, _ ...interface{})

func (*GormLogger) LogMode

func (p *GormLogger) LogMode(_ logger.LogLevel) logger.Interface

func (*GormLogger) Trace

func (p *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), _ error)

func (*GormLogger) Warn

func (p *GormLogger) Warn(_ context.Context, _ string, _ ...interface{})

type GoroutineContextManager

type GoroutineContextManager struct {
	GlobalGinContextKey contextKey
}

func (*GoroutineContextManager) GetContext

func (gcm *GoroutineContextManager) GetContext(ctx context.Context) (*gin.Context, bool)

func (*GoroutineContextManager) SetContext

func (gcm *GoroutineContextManager) SetContext(ctx *gin.Context)

type HTTPPkg added in v0.9.6

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

func NewHTTP added in v0.9.6

func NewHTTP() *HTTPPkg

func (*HTTPPkg) Get added in v0.9.6

func (p *HTTPPkg) Get(c context.Context, link string, timeout int, header map[string]string) (string, error)

func (*HTTPPkg) GetResBody added in v0.9.6

func (p *HTTPPkg) GetResBody() string

func (*HTTPPkg) GetResCode added in v0.9.6

func (p *HTTPPkg) GetResCode() int

func (*HTTPPkg) GetResMsg added in v0.9.6

func (p *HTTPPkg) GetResMsg() string

func (*HTTPPkg) GetStatusCode added in v0.9.6

func (p *HTTPPkg) GetStatusCode() int

func (*HTTPPkg) Post added in v0.9.6

func (p *HTTPPkg) Post(c context.Context, link string, body io.Reader, timeout int, header map[string]string) (string, error)

func (*HTTPPkg) Request added in v0.9.6

func (p *HTTPPkg) Request(c context.Context, link string, params map[string]interface{}, method string) *HTTPPkg

func (*HTTPPkg) Res added in v0.9.6

func (p *HTTPPkg) Res(res any) *HTTPPkg

func (*HTTPPkg) Set added in v0.9.6

func (p *HTTPPkg) Set(param string, value string) *HTTPPkg

func (*HTTPPkg) WithContentType added in v0.9.6

func (p *HTTPPkg) WithContentType(contentType string) *HTTPPkg

func (*HTTPPkg) WithHeader added in v0.9.6

func (p *HTTPPkg) WithHeader(header map[string]string) *HTTPPkg

func (*HTTPPkg) WithTimeout added in v0.9.6

func (p *HTTPPkg) WithTimeout(timeout int) *HTTPPkg

func (*HTTPPkg) WithTrans added in v0.9.6

func (p *HTTPPkg) WithTrans() *HTTPPkg

type LocalSpanOptions

type LocalSpanOptions struct {
	OperationName string
	Component     int32
	Log           []string
	Layer         agentV3.SpanLayer
}

type LoggerPkg

type LoggerPkg struct {
	*logrus.Logger
	// contains filtered or unexported fields
}
var Logger *LoggerPkg

func NewLogger

func NewLogger(logDir string, preLogFunc PreLogFunc, log2Tracer bool) *LoggerPkg

func (*LoggerPkg) WithContext added in v0.9.0

func (p *LoggerPkg) WithContext(ctx context.Context) *Entry

type PreLogFunc added in v0.9.7

type PreLogFunc func(title string, content string) (string, string)

type Redis

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

func NewRedisClient added in v0.7.9

func NewRedisClient(host string, port int, auth string, poolSize int, defaultDB int, prefix string) *Redis

func (*Redis) Client added in v1.0.1

func (p *Redis) Client() *redis.Client

func (*Redis) Del

func (p *Redis) Del(c context.Context, key string) error

func (*Redis) Get

func (p *Redis) Get(c context.Context, key string) *redis.StringCmd

func (*Redis) Init

func (p *Redis) Init(host string, port int, auth string, poolSize int, defaultDB int, prefix string)

func (*Redis) Set

func (p *Redis) Set(c context.Context, key string, value interface{}, expiration time.Duration) error

func (*Redis) SetNX

func (p *Redis) SetNX(c context.Context, key string, value interface{}, expiration time.Duration) error

type Routes

type Routes struct {
	Group       string
	Rules       []Rule
	Middlewares []gin.HandlerFunc
}

type Rule

type Rule struct {
	Method      string
	Route       string
	Handler     interface{}
	DataBind    binding.Binding
	Middlewares []gin.HandlerFunc
}

type Session added in v0.8.21

type Session interface {
	Create(*gin.Context, string, string, time.Duration) error
	Get(*gin.Context, string) (string, error)
	Delete(*gin.Context, string) error
}

type SessionWithRedis added in v0.8.21

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

func NewSession added in v0.8.21

func NewSession(client *Redis, prefix string, cookieName string, cookieDomain string, secure bool, httpOnly bool) *SessionWithRedis

func (*SessionWithRedis) Create added in v0.8.21

func (s *SessionWithRedis) Create(c *gin.Context, sessionName string, data string, ttl time.Duration) error

Create 创建 session sessionName 用于区分不同 session,比如用户 session 与管理员 session data 存储在 session 中的数据 ttl session 有效期

func (*SessionWithRedis) Delete added in v0.8.21

func (s *SessionWithRedis) Delete(c *gin.Context, sessionName string) error

func (*SessionWithRedis) Get added in v0.8.21

func (s *SessionWithRedis) Get(c *gin.Context, sessionName string) (string, error)

type TracerPkg

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

func (*TracerPkg) CheckEnable added in v0.6.2

func (p *TracerPkg) CheckEnable() bool

func (*TracerPkg) CreateEntrySpan

func (p *TracerPkg) CreateEntrySpan(c context.Context, opts EntrySpanOptions) (go2sky.Span, context.Context, error)

CreateEntrySpan 创建入口起始span,最终出口调用sky.GetGcm().DeleteContext()

func (*TracerPkg) CreateExitSpan

func (p *TracerPkg) CreateExitSpan(c context.Context, opts ExitSpanOptions) (go2sky.Span, error)

CreateExitSpan 创建对外请求span,返回的content为当前请求的主线context

func (*TracerPkg) CreateExitSpanWithContext

func (p *TracerPkg) CreateExitSpanWithContext(c context.Context, opts ExitSpanOptions) (go2sky.Span, context.Context, error)

func (*TracerPkg) CreateLocalSpan

func (p *TracerPkg) CreateLocalSpan(c context.Context, opts LocalSpanOptions) (go2sky.Span, context.Context, error)

CreateLocalSpan 创建内部自定span

func (*TracerPkg) DisableTracer added in v0.8.4

func (p *TracerPkg) DisableTracer()

func (*TracerPkg) EnableTracer added in v0.8.4

func (p *TracerPkg) EnableTracer()

func (*TracerPkg) Init

func (p *TracerPkg) Init(serviceAddr string, serviceName string, enable bool)

func (*TracerPkg) SpanErr

func (p *TracerPkg) SpanErr(span go2sky.Span, content ...string)

func (*TracerPkg) SpanTag

func (p *TracerPkg) SpanTag(span go2sky.Span, tag go2sky.Tag, content string)

type Validators

type Validators struct {
	Tag     string
	RegExp  string
	Handler func(fl validator.FieldLevel) bool
	Msg     string
}

Jump to

Keyboard shortcuts

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