pkg

package
v0.8.14 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: Zlib Imports: 38 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 ApUpdateCallback added in v0.6.2

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

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

type ApiPkg

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

func (*ApiPkg) GetResponse added in v0.8.7

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

func (*ApiPkg) RegisterRoutes

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

func (*ApiPkg) RegisterValidates

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

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
}

func (*CustomLogHook) Fire

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

func (*CustomLogHook) Levels

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

type DatabasePkg

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

func (*DatabasePkg) GetDb

func (c *DatabasePkg) GetDb(config *DbPoolConfig) *gorm.DB

func (*DatabasePkg) Init

func (c *DatabasePkg) Init(dbKey string, dbc *DbPoolConfig, callback Callback)

type DbPoolConfig

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" summary:"最大连接数"`
	MaxIdleConns    int    `mapstructure:"max_idle_conns" summary:"最大空闲连接数"`
	ConnMaxLifetime int    `mapstructure:"conn_max_lifetime" summary:"连接的最大存活时间"`
	ConnMaxIdleTime int    `mapstructure:"conn_max_idle_time" summary:"连接空闲超时"`
}

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(ctx context.Context, msg string, data ...interface{})

func (*GormLogger) Info

func (p *GormLogger) Info(ctx context.Context, msg string, data ...interface{})

func (*GormLogger) LogMode

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

func (*GormLogger) Trace

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

func (*GormLogger) Warn

func (p *GormLogger) Warn(ctx context.Context, msg string, data ...interface{})

type GoroutineContextManager

type GoroutineContextManager struct {
	GlobalGinContextKey string
}

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

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

func NewHttp added in v0.8.5

func NewHttp() *HttpPkg

func (*HttpPkg) Get

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

func (*HttpPkg) GetResBody added in v0.8.9

func (p *HttpPkg) GetResBody() string

func (*HttpPkg) GetResCode added in v0.8.9

func (p *HttpPkg) GetResCode() int

func (*HttpPkg) GetResMsg added in v0.8.9

func (p *HttpPkg) GetResMsg() string

func (*HttpPkg) GetStatusCode added in v0.8.9

func (p *HttpPkg) GetStatusCode() int

func (*HttpPkg) Post

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

func (*HttpPkg) Request added in v0.8.5

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

func (*HttpPkg) Res added in v0.8.9

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

func (*HttpPkg) Set added in v0.8.9

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

func (*HttpPkg) WithContentType added in v0.8.5

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

func (*HttpPkg) WithHeader added in v0.8.5

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

func (*HttpPkg) WithTimeout added in v0.8.5

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

func (*HttpPkg) WithTrans added in v0.8.9

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
}
var Logger *LoggerPkg

func NewLogger

func NewLogger(logDir string) *LoggerPkg

func (*LoggerPkg) WithContent

func (p *LoggerPkg) WithContent(content string) *logrus.Entry

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) 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 ResponseContent

type ResponseContent struct {
	Code  int
	Data  interface{}
	Error error
}

type Routes

type Routes struct {
	Group string
	Rules []Rule
}

type Rule

type Rule struct {
	Method   string
	Route    string
	Handler  interface{}
	DataBind binding.Binding
}

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