aa

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
const (
	CkRsaRoot    = "rsa_root"
	CkEnv        = "env"
	CkTimezoneID = "timezone_id"
	CkTimeFormat = "time_format"
	CkMock       = "mock"
)
View Source
const TraceIdKey = "aa_trace_id"

Variables

This section is empty.

Functions

func Context

func Context(ictx iris.Context) context.Context

这里会整体clone一个context,性能并不好。但是为了代码美化,还是牺牲这点性能,换取统一的trace id传递

func ContextWithTraceID

func ContextWithTraceID(ctx context.Context, traceId string) context.Context

func TraceID

func TraceID(ctx context.Context) string

Types

type Aa

type Aa struct {

	//once sync.Once
	// self imported configurations, e.g. parsed from ini
	Config Config
	// system configuration
	Configuration Configuration
	Log           Log
}

func New

func New() *Aa

func (*Aa) IrisMiddleware

func (app *Aa) IrisMiddleware(ictx iris.Context)

tracePrefix should be captialized

func (*Aa) LoadIni

func (app *Aa) LoadIni(path string) error

func (*Aa) MysqlConfig

func (app *Aa) MysqlConfig(section string) (MysqlConfig, error)

func (*Aa) ParseTimeout

func (app *Aa) ParseTimeout(t string, defaultTimeouts ...time.Duration) (conn time.Duration, read time.Duration, write time.Duration)

ParseTimeout connection timeout, r timeout, w timeout, heartbeat interval 10s, 1000ms

func (*Aa) ParseToConfiguration

func (app *Aa) ParseToConfiguration()

func (*Aa) RedisConfig

func (app *Aa) RedisConfig(section string) (RedisConfig, error)

func (*Aa) Run

func (app *Aa) Run(jobs ...Job)

type Config

type Config interface {
	Reload(app *Aa) error
	LoadAIni(cfgs map[string]json.RawMessage) error // 加载 a ini 一维json配置
	AddOtherConfigs(otherConfigs map[string]string) // 这里有锁,所以要批量设置
	//getOtherConfig(key string) string    // 不要获取太细分,否则容易导致错误不容易被排查
	AddRsaConfigs(rsaConfigs map[string][]byte)
	//GetRsa(name string) ([]byte, bool) // 不要获取太细分,否则容易导致错误不容易被排查
	MustGetString(key string) (string, error)
	GetString(key string, defaultValue ...string) string
	MustGet(key string) (*dtype.Dtype, error)
	Get(key string, defaultValue ...interface{}) *dtype.Dtype
}

type Configuration

type Configuration struct {
	Env          string // dev test preprod product
	TimezoneID   string // e.g. "Asia/Shanghai"
	TimeLocation *time.Location
	TimeFormat   string // e.g. "2006-02-01 15:04:05"
	Mock         bool   // using mock

}

func (Configuration) Log

func (c Configuration) Log()

type Ini

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

func (*Ini) AddOtherConfigs

func (c *Ini) AddOtherConfigs(otherConfigs map[string]string)

这里有锁,所以要批量设置

func (*Ini) AddRsaConfigs

func (c *Ini) AddRsaConfigs(rsaConfigs map[string][]byte)

func (*Ini) Get

func (c *Ini) Get(key string, defaultValue ...interface{}) *dtype.Dtype

Get(key) or Get(key, defaultValue) 先从 ini 文件读取,找不到再去从其他 provider (如数据库拉下来的配置)里面找

func (*Ini) GetString

func (c *Ini) GetString(key string, defaultValue ...string) string

func (*Ini) LoadAIni

func (c *Ini) LoadAIni(cfgs map[string]json.RawMessage) error

func (*Ini) MustGet

func (c *Ini) MustGet(key string) (*dtype.Dtype, error)

func (*Ini) MustGetString

func (c *Ini) MustGetString(key string) (string, error)

func (*Ini) Reload

func (c *Ini) Reload(app *Aa) error

type Job

type Job interface {
	Run(*Aa) error
}

type Log

type Log interface {
	AError(ctx context.Context, e *ae.Error)
	// AuthDebug 包含详细的开发情报的信息,通常只在调试一个程序时使用
	Debug(ctx context.Context, msg string, args ...interface{})

	// Info 情报信息,正常的系统消息,比如骚扰报告,带宽数据等,不需要处理。
	Info(ctx context.Context, msg string, args ...interface{})

	// Notice 不是错误情况,也不需要立即处理。
	Notice(ctx context.Context, msg string, args ...interface{})

	// Warn 警告信息,不是错误,比如系统磁盘使用了85%等。
	Warn(ctx context.Context, msg string, args ...interface{})

	// Error 错误,不是非常紧急,在一定时间内修复即可。
	Error(ctx context.Context, msg string, args ...interface{})

	// Crit 重要情况,如硬盘错误,备用连接丢失
	Crit(ctx context.Context, msg string, args ...interface{})

	// Alert 应该被立即改正的问题,如系统数据库被破坏,ISP连接丢失。
	Alert(ctx context.Context, msg string, args ...interface{})

	// Emerg 紧急情况,需要立即通知技术人员。
	Emerg(ctx context.Context, msg string, args ...interface{})

	Printf(ctx context.Context, msg string, args ...interface{})

	Println(ctx context.Context, msg ...interface{})

	// Trace 跟踪请求链路,用于性能监控
	Trace(ctx context.Context)
}

func NewDefaultLog

func NewDefaultLog() Log

type MysqlConfig

type MysqlConfig struct {
	Schema   string // dbname
	User     string
	Password string
	// Scheme   string // tcp|unix,只支持tcp,unix仅本地可用
	TLS  string // 默认 false,Valid Values:   true, false, skip-verify, preferred, <name>
	Host string

	// mysql客户端在尝试与mysql服务器建立连接时,mysql服务器返回错误握手协议前等待客户端数据包的最大时限。默认10秒。
	ConnTimeout  time.Duration // 使用时,需要设置单位,s, ms等。Timeout for establishing connections, aka dial timeout
	ReadTimeout  time.Duration // 使用时,需要设置单位,s, ms等。I/O read timeout.
	WriteTimeout time.Duration // 使用时,需要设置单位,s, ms等。I/O write timeout.

	Pool MysqlPoolConfig
}

https://github.com/go-sql-driver/mysql/

type MysqlPoolConfig

type MysqlPoolConfig struct {
	MaxIdleConns    int
	MaxOpenConns    int
	ConnMaxLifetime time.Duration
	ConnMaxIdleTime time.Duration
}

type RedisConfig

type RedisConfig struct {
	TLS  bool
	Host string
	Auth string
	Db   uint8 // 默认0,系统配置为16个,方便flush all,但是不常用

	ConnTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	Pool         RedisPoolConfig
}

type RedisPoolConfig

type RedisPoolConfig struct {
	// Maximum number of idle connections in the pool.
	MaxIdle int

	// Maximum number of connections allocated by the pool at a given time.
	// When zero, there is no limit on the number of connections in the pool.
	MaxActive int

	// Close connections after remaining idle for this duration. If the value
	// is zero, then idle connections are not closed. Applications should set
	// the timeout to a value less than the server's timeout.
	IdleTimeout time.Duration

	// If Wait is true and the pool is at the MaxActive limit, then Get() waits
	// for a connection to be returned to the pool before returning.
	Wait bool

	// Close connections older than this duration. If the value is zero, then
	// the pool does not close connections based on age.
	MaxConnLifetime time.Duration
}

Jump to

Keyboard shortcuts

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