pkg

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Zlib Imports: 36 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 ApolloAlias = func(alias string) *ApolloPkg {
	conf := &ApolloPkg{
		Viper: Apollo.Viper,
	}
	if apKey, ok := Apollo.apAliasMap[alias]; ok {
		conf.prefix = apKey
	}
	return conf
}
View Source
var ApolloStruct = func(alias string, outputStruct interface{}) error {
	conf := ApolloAlias(alias)
	mp := conf.GetStringMap("")
	return decode(mp, &outputStruct)
}
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) 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) 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) 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) 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(map[string]*gorm.DB)

type ConfigPkg

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

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 {
}

func (*DatabasePkg) GetDb

func (c *DatabasePkg) GetDb(configData map[string]interface{}) *gorm.DB

func (*DatabasePkg) Init

func (c *DatabasePkg) Init(conf map[string]interface{}, callback Callback)

type DbPoolConfig

type DbPoolConfig struct {
	Name            string `json:"name"`
	Type            string `json:"type"`
	Host            string `json:"host"`
	Port            int    `json:"port"`
	User            string `json:"user"`
	Password        string `json:"password"`
	Database        string `json:"database"`
	Charset         string `json:"charset"`
	TablePrefix     string `json:"table_prefix"`
	MaxOpenConns    int    `json:"max_open_conns" summary:"最大连接数"`
	MaxIdleConns    int    `json:"max_idle_conns" summary:"最大空闲连接数"`
	ConnMaxLifetime int    `json:"conn_max_lifetime" summary:"连接的最大存活时间"`
	ConnMaxIdleTime int    `json:"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 {
}

func (*HttpPkg) Get

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

func (*HttpPkg) Post

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

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 (*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) 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