Documentation ¶
Index ¶
- type Infra
- func (infra *Infra) Defer(fn func())
- func (infra *Infra) FullName() string
- func (infra *Infra) Gorm(name string) *gorm.DB
- func (infra *Infra) Hostname() string
- func (infra *Infra) MySQL(name string) *sql.DB
- func (infra *Infra) NewGRPCServer(addr string) *apm.GrpcServer
- func (infra *Infra) NewGin(metricsAuth gin.HandlerFunc, opts ...gin.OptionFunc) *gin.Engine
- func (infra *Infra) NewHTTPServer(addr string) *apm.HTTPServer
- func (infra *Infra) PrependDefer(fn func())
- func (infra *Infra) RangeGormDB(fn func(name string, db *gorm.DB))
- func (infra *Infra) RangeRedisV6(fn func(name string, client *apm.RedisV6))
- func (infra *Infra) RangeRedisV9(fn func(name string, client *redis.Client))
- func (infra *Infra) RangeSqlDB(fn func(name string, db *sql.DB))
- func (infra *Infra) RedisV6(name string) *apm.RedisV6
- func (infra *Infra) RedisV9(name string) *redis.Client
- func (infra *Infra) Stop()
- func (infra *Infra) Tableflip() *tableflip.Upgrader
- func (infra *Infra) WaitToStop()
- type InfraOption
- func WithAPM(otelEndpoint string, opts ...apm.ApmOption) InfraOption
- func WithAutoPProf(autoPProfOpts *apm.AutoPProfOpt, opts ...holmes.Option) InfraOption
- func WithCloser(fn func()) InfraOption
- func WithGorm(name, addr string) InfraOption
- func WithMetrics(collectors ...prometheus.Collector) InfraOption
- func WithMySQL(name, addr string) InfraOption
- func WithRedisV6(name string, opts *redisv6.Options) InfraOption
- func WithRedisV9(name string, opts *redis.Options) InfraOption
- func WithRotateLog(path string, opts ...rotatelogs.Option) InfraOption
- func WithTableflip(opts tableflip.Options, sigs ...os.Signal) InfraOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Infra ¶
type Infra struct { // Name is the business name of the infra. Name string // Tracer is the tracer for the infra, Tracer trace.Tracer // contains filtered or unexported fields }
Infra is an infrastructure manager for goapm. It is recommended to create a single instance of Infra and share it across the application. TODO: add a print function to print the infra's components and closers.
func NewInfra ¶
func NewInfra(name string, opts ...InfraOption) *Infra
NewInfra creates a new infra with the given options.
func (*Infra) Defer ¶ added in v0.0.20
func (infra *Infra) Defer(fn func())
Defer appends a defer function to the infra.
func (*Infra) FullName ¶ added in v0.0.14
FullName returns the full name of the infra, it is the combination of the infra name and the hostname.
func (*Infra) Hostname ¶ added in v0.0.17
Hostname returns the hostname of the machine running the application.
func (*Infra) NewGRPCServer ¶ added in v0.0.7
func (infra *Infra) NewGRPCServer(addr string) *apm.GrpcServer
NewGRPCServer creates a new grpc server with the given address. If the tableflip is created, the server will listen on the address with the tableflip.
func (*Infra) NewGin ¶ added in v0.0.7
func (infra *Infra) NewGin(metricsAuth gin.HandlerFunc, opts ...gin.OptionFunc) *gin.Engine
NewGin creates a new gin engine with otel tracing and metrics. It will automatically add the otel tracing and metrics middleware to the engine. If metricsAuth is not nil, it will add a metrics handler with the given auth middleware.
func (*Infra) NewHTTPServer ¶ added in v0.0.7
func (infra *Infra) NewHTTPServer(addr string) *apm.HTTPServer
NewHTTPServer creates a new http server with the given address. If the tableflip is created, the server will listen on the address with the tableflip. Otherwise, it will listen on the address directly.
func (*Infra) PrependDefer ¶ added in v0.0.20
func (infra *Infra) PrependDefer(fn func())
PrependDefer prepends a defer function to the infra.
func (*Infra) RangeGormDB ¶ added in v0.0.15
RangeGormDB ranges the gorm.DB of the infra.
func (*Infra) RangeRedisV6 ¶ added in v0.0.15
RangeRedisV6 ranges the redis v6 client of the infra.
func (*Infra) RangeRedisV9 ¶ added in v0.0.15
RangeRedisV9 ranges the redis v9 client of the infra.
func (*Infra) RangeSqlDB ¶ added in v0.0.15
RangeSqlDB ranges the sql.DB of the infra.
func (*Infra) WaitToStop ¶ added in v0.0.11
func (infra *Infra) WaitToStop()
WaitToStop waits for the infra to stop. It should be called in front of the infra.Stop().
type InfraOption ¶
type InfraOption func(*Infra)
InfraOption is the option for Infra.
func WithAPM ¶
func WithAPM(otelEndpoint string, opts ...apm.ApmOption) InfraOption
WithAPM creates a new apm and adds it to the infra.
func WithAutoPProf ¶
func WithAutoPProf(autoPProfOpts *apm.AutoPProfOpt, opts ...holmes.Option) InfraOption
WithAutoPProf starts a holmes dumper to automatically record the running state of the program.
func WithCloser ¶ added in v0.0.7
func WithCloser(fn func()) InfraOption
WithCloser adds a closer to the infra.
func WithGorm ¶
func WithGorm(name, addr string) InfraOption
WithGorm creates a new gorm db and adds it to the infra. name is the business name of the db, and addr is the address of the db.
func WithMetrics ¶
func WithMetrics(collectors ...prometheus.Collector) InfraOption
WithMetrics registers the given collectors to the goapm metrics registry. It default provides some collectors defined in goapm/metric.go.
func WithMySQL ¶
func WithMySQL(name, addr string) InfraOption
WithMySQL creates a new mysql db and adds it to the infra. name is the business name of the db, and addr is the address of the db.
func WithRedisV6 ¶
func WithRedisV6(name string, opts *redisv6.Options) InfraOption
WithRedisV6 creates a new redis v6 client and adds it to the infra. name is the business name of the redis, and opts is the options of the redis. nolint:dupl
func WithRedisV9 ¶
func WithRedisV9(name string, opts *redis.Options) InfraOption
WithRedisV9 creates a new redis v9 client and adds it to the infra. name is the business name of the redis, and opts is the options of the redis. nolint:dupl
func WithRotateLog ¶
func WithRotateLog(path string, opts ...rotatelogs.Option) InfraOption
WithRotateLog creates a new rotate log and sets it to the logrus. It default rotates every 7 days and keeps 7 days' logs.
func WithTableflip ¶ added in v0.0.7
func WithTableflip(opts tableflip.Options, sigs ...os.Signal) InfraOption
WithTableflip creates a new tableflip and adds it to the infra. The tableflip is used to support graceful restart. If the tableflip is created, the infra will listen the ports with it for http and rpc servers. NOTE: we recommend that this should be the first option to be called.