Documentation
¶
Index ¶
- Constants
- Variables
- func FullVersion() string
- func Short() string
- type ApiDoc
- type Application
- func (a *Application) HTTPPrefix() string
- func (a *Application) HandleError(err error)
- func (a *Application) Init() error
- func (a *Application) Name() string
- func (i *Application) Priority() int
- func (a *Application) Start(ctx context.Context) error
- func (a *Application) String() string
- func (a *Application) SwagerDocs(swo *spec.Swagger)
- type BuildConfig
- type BuildHook
- type CORS
- type ErrHandler
- type GinRouterBuilder
- type GoRestfulRouterBuilder
- type Grpc
- func (g *Grpc) AddInterceptors(interceptors ...grpc.UnaryServerInterceptor)
- func (g *Grpc) Addr() string
- func (g *Grpc) Interceptors() (interceptors []grpc.UnaryServerInterceptor)
- func (g *Grpc) Parse() error
- func (g *Grpc) ServerOpts() []grpc.ServerOption
- func (g *Grpc) Start(ctx context.Context, cb ErrHandler)
- func (g *Grpc) Stop(ctx context.Context) error
- type HealthCheck
- type Http
- type METRIC_PROVIDER
- type Metric
- type RouterBuilder
- type ServiceInfoCtxKey
- type TRACE_PROVIDER
- type Trace
- type WEB_FRAMEWORK
Constants ¶
View Source
const (
AppName = "app"
)
Variables ¶
View Source
var ( GIT_TAG string GIT_COMMIT string GIT_BRANCH string BUILD_TIME string GO_VERSION string )
编译时注入
Functions ¶
Types ¶
type Application ¶
type Application struct {
ioc.ObjectImpl
AppName string `json:"name" yaml:"name" toml:"name" env:"APP_NAME"`
AppDescription string `json:"description" yaml:"description" toml:"description" env:"APP_DESCRIPTION"`
EncryptKey string `json:"encrypt_key" yaml:"encrypt_key" toml:"encrypt_key" env:"APP_ENCRYPT_KEY"`
CipherPrefix string `json:"cipher_prefix" yaml:"cipher_prefix" toml:"cipher_prefix" env:"APP_CIPHER_PREFIX"`
Trace *Trace `toml:"trace" json:"trace" yaml:"trace" envPrefix:"TRACE_"`
Metric *Metric `toml:"metric" json:"metric" yaml:"metric" envPrefix:"METRIC_"`
HTTP *Http `json:"http" yaml:"http" toml:"http" envPrefix:"HTTP_"`
GRPC *Grpc `json:"grpc" yaml:"grpc" toml:"grpc" envPrefix:"GRPC_"`
// contains filtered or unexported fields
}
func App ¶
func App() *Application
func (*Application) HTTPPrefix ¶
func (a *Application) HTTPPrefix() string
func (*Application) HandleError ¶
func (a *Application) HandleError(err error)
func (*Application) Init ¶
func (a *Application) Init() error
func (*Application) Name ¶
func (a *Application) Name() string
func (*Application) Priority ¶
func (i *Application) Priority() int
func (*Application) String ¶
func (a *Application) String() string
func (*Application) SwagerDocs ¶
func (a *Application) SwagerDocs(swo *spec.Swagger)
type BuildConfig ¶
type CORS ¶ added in v2.0.2
type CORS struct {
Enabled bool `toml:"enabled" json:"enabled" yaml:"enabled" env:"ENABLED"`
AllowedHeaders []string `json:"cors_allowed_headers" yaml:"cors_allowed_headers" toml:"cors_allowed_headers" env:"ALLOWED_HEADERS" envSeparator:","`
AllowedDomains []string `json:"cors_allowed_domains" yaml:"cors_allowed_domains" toml:"cors_allowed_domains" env:"ALLOWED_DOMAINS" envSeparator:","`
AllowedMethods []string `json:"cors_allowed_methods" yaml:"cors_allowed_methods" toml:"cors_allowed_methods" env:"ALLOWED_METHODS" envSeparator:","`
}
type ErrHandler ¶
type ErrHandler func(error)
type GinRouterBuilder ¶
type GinRouterBuilder struct {
// contains filtered or unexported fields
}
func NewGinRouterBuilder ¶
func NewGinRouterBuilder() *GinRouterBuilder
func (*GinRouterBuilder) Config ¶
func (b *GinRouterBuilder) Config(c *BuildConfig)
type GoRestfulRouterBuilder ¶
type GoRestfulRouterBuilder struct {
// contains filtered or unexported fields
}
func NewGoRestfulRouterBuilder ¶
func NewGoRestfulRouterBuilder() *GoRestfulRouterBuilder
func (*GoRestfulRouterBuilder) Build ¶
func (b *GoRestfulRouterBuilder) Build() (http.Handler, error)
func (*GoRestfulRouterBuilder) Config ¶
func (b *GoRestfulRouterBuilder) Config(c *BuildConfig)
type Grpc ¶
type Grpc struct {
// 开启GRPC服务
Enable *bool `json:"enable" yaml:"enable" toml:"enable" env:"ENABLE"`
Host string `json:"host" yaml:"host" toml:"host" env:"HOST"`
Port int `json:"port" yaml:"port" toml:"port" env:"PORT"`
EnableSSL bool `json:"enable_ssl" yaml:"enable_ssl" toml:"enable_ssl" env:"ENABLE_SSL"`
CertFile string `json:"cert_file" yaml:"cert_file" toml:"cert_file" env:"CERT_FILE"`
KeyFile string `json:"key_file" yaml:"key_file" toml:"key_file" env:"KEY_FILE"`
// 开启recovery恢复
EnableRecovery bool `json:"enable_recovery" yaml:"enable_recovery" toml:"enable_recovery" env:"ENABLE_RECOVERY"`
// 开启Trace
EnableTrace bool `json:"enable_trace" yaml:"enable_trace" toml:"enable_trace" env:"ENABLE_TRACE"`
// 启动后执行
PostStart func(context.Context) error `json:"-" yaml:"-" toml:"-" env:"-"`
// 关闭前执行
PreStop func(context.Context) error `json:"-" yaml:"-" toml:"-" env:"-"`
// contains filtered or unexported fields
}
func NewDefaultGrpc ¶
func NewDefaultGrpc() *Grpc
func (*Grpc) AddInterceptors ¶
func (g *Grpc) AddInterceptors(interceptors ...grpc.UnaryServerInterceptor)
func (*Grpc) Interceptors ¶
func (g *Grpc) Interceptors() (interceptors []grpc.UnaryServerInterceptor)
func (*Grpc) ServerOpts ¶
func (g *Grpc) ServerOpts() []grpc.ServerOption
type HealthCheck ¶ added in v2.0.2
type HealthCheck struct {
Enabled bool `toml:"enabled" json:"enabled" yaml:"enabled" env:"ENABLED"`
}
type Http ¶
type Http struct {
// 默认根据
Enable *bool `json:"enable" yaml:"enable" toml:"enable" env:"ENABLE"`
// HTTP服务Host
Host string `json:"host" yaml:"host" toml:"host" env:"HOST"`
// HTTP服务端口
Port int `json:"port" yaml:"port" toml:"port" env:"PORT"`
// 接口前缀
PathPrefix string `json:"path_prefix" yaml:"path_prefix" toml:"path_prefix" env:"PATH_PREFIX"`
// 使用的http框架, 启用后会自动从ioc中加载 该框架的hanlder
WEB_FRAMEWORK WEB_FRAMEWORK `json:"web_framework" yaml:"web_framework" toml:"web_framework" env:"WEB_FRAMEWORK"`
// HTTP服务器参数
ReadHeaderTimeoutSecond int `json:"read_header_timeout" yaml:"read_header_timeout" toml:"read_header_timeout" env:"READ_HEADER_TIMEOUT"`
// 读取HTTP整个请求时的参数
ReadTimeoutSecond int `json:"read_timeout" yaml:"read_timeout" toml:"read_timeout" env:"READ_TIMEOUT"`
// 响应超时事件
WriteTimeoutSecond int `json:"write_timeout" yaml:"write_timeout" toml:"write_timeout" env:"WRITE_TIMEOUT"`
// 启用了KeepAlive时 复用TCP链接的超时时间
IdleTimeoutSecond int `json:"idle_timeout" yaml:"idle_timeout" toml:"idle_timeout" env:"IDLE_TIMEOUT"`
// header最大大小
MaxHeaderSize string `json:"max_header_size" yaml:"max_header_size" toml:"max_header_size" env:"MAX_HEADER_SIZE"`
// SSL启用参数
EnableSSL bool `json:"enable_ssl" yaml:"enable_ssl" toml:"enable_ssl" env:"ENABLE_SSL"`
CertFile string `json:"cert_file" yaml:"cert_file" toml:"cert_file" env:"CERT_FILE"`
KeyFile string `json:"key_file" yaml:"key_file" toml:"key_file" env:"KEY_FILE"`
// 开启Trace
EnableTrace bool `toml:"enable_trace" json:"enable_trace" yaml:"enable_trace" env:"ENABLE_TRACE"`
// 开启HTTP健康检查
HealthCheck HealthCheck `toml:"health_check" json:"health_check" yaml:"health_check" envPrefix:"HEALTH_CHECK_"`
// cors配置
Cors CORS `toml:"cors" json:"cors" yaml:"cors" envPrefix:"CORS_"`
// API Doc配置 swagger配置
ApiDoc ApiDoc `json:"api_doc" yaml:"api_doc" toml:"api_doc" envPrefix:"API_DOC_"`
RouterBuildConfig *BuildConfig `json:"-" yaml:"-" toml:"-" env:"-"`
// contains filtered or unexported fields
}
func NewDefaultHttp ¶
func NewDefaultHttp() *Http
func (*Http) BuildRouter ¶
func (*Http) DetectAndSetWebFramework ¶ added in v2.0.2
func (h *Http) DetectAndSetWebFramework()
func (*Http) GetRouterBuilder ¶
func (h *Http) GetRouterBuilder() RouterBuilder
type METRIC_PROVIDER ¶ added in v2.0.2
type METRIC_PROVIDER string
const (
METRIC_PROVIDER_PROMETHEUS METRIC_PROVIDER = "prometheus"
)
type Metric ¶ added in v2.0.2
type Metric struct {
Enable bool `json:"enable" yaml:"enable" toml:"enable" env:"ENABLE"`
Provider METRIC_PROVIDER `toml:"provider" json:"provider" yaml:"provider" env:"METRIC_PROVIDER"`
Endpoint string `toml:"endpoint" json:"endpoint" yaml:"endpoint" env:"ENDPOINT"`
}
func NewDefaultMetric ¶ added in v2.0.2
func NewDefaultMetric() *Metric
type RouterBuilder ¶
type RouterBuilder interface {
Config(*BuildConfig)
Build() (http.Handler, error)
}
type ServiceInfoCtxKey ¶
type ServiceInfoCtxKey struct{}
type TRACE_PROVIDER ¶ added in v2.0.2
type TRACE_PROVIDER string
const (
TRACE_PROVIDER_JAEGER TRACE_PROVIDER = "jaeger"
)
type Trace ¶ added in v2.0.2
type Trace struct {
Enable bool `json:"enable" yaml:"enable" toml:"enable" env:"ENABLE"`
Provider TRACE_PROVIDER `toml:"provider" json:"provider" yaml:"provider" env:"TRACE_PROVIDER"`
Endpoint string `toml:"endpoint" json:"endpoint" yaml:"endpoint" env:"TRACE_PROVIDER_ENDPOINT"`
}
func NewDefaultTrace ¶ added in v2.0.2
func NewDefaultTrace() *Trace
func (*Trace) SetDefaultEnv ¶ added in v2.0.2
func (t *Trace) SetDefaultEnv()
type WEB_FRAMEWORK ¶
type WEB_FRAMEWORK string
const ( // 根据ioc当前加载的对象自动判断使用那种框架 WEB_FRAMEWORK_AUTO WEB_FRAMEWORK = "" WEB_FRAMEWORK_GO_RESTFUL WEB_FRAMEWORK = "go-restful" WEB_FRAMEWORK_GIN WEB_FRAMEWORK = "gin" )
Click to show internal directories.
Click to hide internal directories.