application

package
v1.9.28 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APPLICATION = "app"
)

Variables

View Source
var (
	GIT_TAG    string
	GIT_COMMIT string
	GIT_BRANCH string
	BUILD_TIME string
	GO_VERSION string
)

编译时注入

Functions

func FullVersion added in v1.9.26

func FullVersion() string

FullVersion show the version info

func Short added in v1.9.26

func Short() string

Short 版本缩写

Types

type Application

type Application struct {
	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"`
	HTTP           *Http  `json:"http" yaml:"http"  toml:"http"`
	GRPC           *Grpc  `json:"grpc" yaml:"grpc"  toml:"grpc"`

	ioc.ObjectImpl
	// contains filtered or unexported fields
}

func App

func App() *Application

func (*Application) HTTPPrefix

func (a *Application) HTTPPrefix() string

func (*Application) HandleError added in v1.9.28

func (a *Application) HandleError(err error)

func (*Application) Init

func (a *Application) Init() error

func (*Application) Name

func (a *Application) Name() string

func (*Application) Start added in v1.9.28

func (a *Application) Start(ctx context.Context) error

func (*Application) String

func (a *Application) String() string

func (*Application) SwagerDocs added in v1.9.28

func (a *Application) SwagerDocs(swo *spec.Swagger)

func (*Application) UseGoRestful added in v1.9.28

func (a *Application) UseGoRestful()

type BuildConfig added in v1.9.28

type BuildConfig struct {
	// 装载Ioc路由之前
	BeforeLoad BuildHook `json:"-" yaml:"-" toml:"-" env:"-"`
	// 装载Ioc路由之后
	AfterLoad BuildHook `json:"-" yaml:"-" toml:"-" env:"-"`
}

type BuildHook added in v1.9.28

type BuildHook func(http.Handler)

type ErrHandler added in v1.9.28

type ErrHandler func(error)

type GinRouterBuilder added in v1.9.28

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

func NewGinRouterBuilder added in v1.9.28

func NewGinRouterBuilder() *GinRouterBuilder

func (*GinRouterBuilder) Build added in v1.9.28

func (b *GinRouterBuilder) Build() (http.Handler, error)

func (*GinRouterBuilder) Config added in v1.9.28

func (b *GinRouterBuilder) Config(c *BuildConfig)

type GoRestfulRouterBuilder added in v1.9.28

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

func NewGoRestfulRouterBuilder added in v1.9.28

func NewGoRestfulRouterBuilder() *GoRestfulRouterBuilder

func (*GoRestfulRouterBuilder) Build added in v1.9.28

func (b *GoRestfulRouterBuilder) Build() (http.Handler, error)

func (*GoRestfulRouterBuilder) Config added in v1.9.28

func (b *GoRestfulRouterBuilder) Config(c *BuildConfig)

type Grpc

type Grpc struct {
	// 开启GRPC服务
	Enable *bool  `json:"enable" yaml:"enable" toml:"enable" env:"GRPC_ENABLE"`
	Host   string `json:"host" yaml:"host" toml:"host" env:"GRPC_HOST"`
	Port   int    `json:"port" yaml:"port" toml:"port" env:"GRPC_PORT"`

	EnableSSL bool   `json:"enable_ssl" yaml:"enable_ssl" toml:"enable_ssl" env:"GRPC_ENABLE_SSL"`
	CertFile  string `json:"cert_file" yaml:"cert_file" toml:"cert_file" env:"GRPC_CERT_FILE"`
	KeyFile   string `json:"key_file" yaml:"key_file" toml:"key_file" env:"GRPC_KEY_FILE"`

	// 开启recovery恢复
	EnableRecovery bool `json:"enable_recovery" yaml:"enable_recovery" toml:"enable_recovery" env:"GRPC_ENABLE_RECOVERY"`
	// 开启Trace
	EnableTrace bool `json:"enable_trace" yaml:"enable_trace" toml:"enable_trace" env:"GRPC_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 added in v1.9.28

func NewDefaultGrpc() *Grpc

func (*Grpc) AddInterceptors added in v1.9.28

func (g *Grpc) AddInterceptors(interceptors ...grpc.UnaryServerInterceptor)

func (*Grpc) Addr

func (g *Grpc) Addr() string

func (*Grpc) Interceptors added in v1.9.28

func (g *Grpc) Interceptors() (interceptors []grpc.UnaryServerInterceptor)

func (*Grpc) Parse added in v1.9.28

func (g *Grpc) Parse() error

func (*Grpc) Start added in v1.9.28

func (g *Grpc) Start(ctx context.Context, cb ErrHandler)

func (*Grpc) Stop added in v1.9.28

func (g *Grpc) Stop(ctx context.Context) error

type Http

type Http struct {
	// 默认根据
	Enable *bool `json:"enable" yaml:"enable" toml:"enable" env:"HTTP_ENABLE"`
	// HTTP服务Host
	Host string `json:"size" yaml:"size" toml:"size" env:"HTTP_HOST"`
	// HTTP服务端口
	Port int `json:"port" yaml:"port" toml:"port" env:"HTTP_PORT"`

	// 使用的http框架, 启用后会自动从ioc中加载 该框架的hanlder
	WEB_FRAMEWORK WEB_FRAMEWORK `json:"web_framework" yaml:"web_framework" toml:"web_framework" env:"HTTP_WEB_FRAMEWORK"`

	// HTTP服务器参数
	ReadHeaderTimeoutSecond int `json:"read_header_timeout" yaml:"read_header_timeout" toml:"read_header_timeout" env:"HTTP_READ_HEADER_TIMEOUT"`
	// 读取HTTP整个请求时的参数
	ReadTimeoutSecond int `json:"read_timeout" yaml:"read_timeout" toml:"read_timeout" env:"HTTP_READ_TIMEOUT"`
	// 响应超时事件
	WriteTimeoutSecond int `json:"write_timeout" yaml:"write_timeout" toml:"write_timeout" env:"HTTP_WRITE_TIMEOUT"`
	// 启用了KeepAlive时 复用TCP链接的超时时间
	IdleTimeoutSecond int `json:"idle_timeout" yaml:"idle_timeout" toml:"idle_timeout" env:"HTTP_IDLE_TIMEOUT"`
	// header最大大小
	MaxHeaderSize string `json:"max_header_size" yaml:"max_header_size" toml:"max_header_size" env:"HTTP_MAX_HEADER_SIZE"`

	// SSL启用参数
	EnableSSL bool   `json:"enable_ssl" yaml:"enable_ssl" toml:"enable_ssl" env:"HTTP_ENABLE_SSL"`
	CertFile  string `json:"cert_file" yaml:"cert_file" toml:"cert_file" env:"HTTP_CERT_FILE"`
	KeyFile   string `json:"key_file" yaml:"key_file" toml:"key_file" env:"HTTP_KEY_FILE"`

	// 开启Trace
	EnableTrace bool `toml:"enable_trace" json:"enable_trace" yaml:"enable_trace"  env:"HTTP_ENABLE_TRACE"`
	// 开启HTTP健康检查
	EnableHealthCheck bool `toml:"enable_health_check" json:"enable_health_check" yaml:"enable_health_check"  env:"HTTP_ENABLE_HEALTH_CHECK"`
	// 开启跨越允许
	EnableCors bool `toml:"enable_cors" json:"enable_cors" yaml:"enable_cors"  env:"HTTP_ENABLE_CORS"`

	// 是否开启API Doc
	EnableApiDoc bool   `json:"enable_api_doc" yaml:"enable_api_doc" toml:"enable_api_doc" env:"HTTP_ENABLE_API_DOC"`
	ApiDocPath   string `json:"api_doc_path" yaml:"api_doc_path" toml:"api_doc_path" env:"HTTP_API_DOC_PATH"`

	RouterBuildConfig *BuildConfig
	// contains filtered or unexported fields
}

func NewDefaultHttp added in v1.9.28

func NewDefaultHttp() *Http

func (*Http) Addr

func (h *Http) Addr() string

func (*Http) BuildRouter added in v1.9.28

func (h *Http) BuildRouter() error

func (*Http) GetRouterBuilder added in v1.9.28

func (h *Http) GetRouterBuilder() RouterBuilder

func (*Http) Parse added in v1.9.28

func (h *Http) Parse() error

配置数据解析

func (*Http) Start added in v1.9.28

func (h *Http) Start(ctx context.Context, cb ErrHandler)

Start 启动服务

func (*Http) Stop added in v1.9.28

func (h *Http) Stop(ctx context.Context) error

Stop 停止server

type RouterBuilder added in v1.9.28

type RouterBuilder interface {
	Config(*BuildConfig)
	Build() (http.Handler, error)
}

type ServiceInfoCtxKey added in v1.9.28

type ServiceInfoCtxKey struct{}

type WEB_FRAMEWORK added in v1.9.28

type WEB_FRAMEWORK string
const (
	WEB_FRAMEWORK_GO_RESTFUL WEB_FRAMEWORK = "go-restful"
	WEB_FRAMEWORK_GIN        WEB_FRAMEWORK = "gin"
)

Jump to

Keyboard shortcuts

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