http

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
const (
	AppName = "http"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiDoc

type ApiDoc struct {
	// 是否开启API Doc
	Enabled bool `json:"enabled" yaml:"enabled" toml:"enabled" env:"HTTP_API_DOC_ENABLED"`
	// Swagger API Doc URL路径
	DocPath string `json:"doc_path" yaml:"doc_path" toml:"doc_path" env:"HTTP_API_DOC_PATH"`
}

type BuildConfig

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

type BuildHook

type BuildHook func(http.Handler)

type CORS

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 GinRouterBuilder

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

func NewGinRouterBuilder

func NewGinRouterBuilder() *GinRouterBuilder

func (*GinRouterBuilder) Build

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

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 HealthCheck

type HealthCheck struct {
	Enabled bool `toml:"enabled" json:"enabled" yaml:"enabled"  env:"ENABLED"`
}

type Http

type Http struct {
	ioc.ObjectImpl

	// 是否开启HTTP Server, 默认会根据是否有注册得有API对象来自动开启
	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"`
	// API接口前缀
	PathPrefix string `json:"path_prefix" yaml:"path_prefix" toml:"path_prefix" env:"PATH_PREFIX"`

	// 使用的http框架, 默认会根据当前注册的API对象,自动选择合适的框架
	WEB_FRAMEWORK WEB_FRAMEWORK `json:"web_framework" yaml:"web_framework" toml:"web_framework" env:"WEB_FRAMEWORK"`

	// HTTP服务器参数
	// HTTP Header读取超时时间
	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 Get

func Get() *Http

func (*Http) Addr

func (h *Http) Addr() string

func (*Http) BuildRouter

func (h *Http) BuildRouter() error

func (*Http) DetectAndSetWebFramework

func (h *Http) DetectAndSetWebFramework()

func (*Http) GetRouterBuilder

func (h *Http) GetRouterBuilder() RouterBuilder

func (*Http) HTTPPrefix

func (h *Http) HTTPPrefix() string

func (*Http) Init

func (h *Http) Init() error

配置数据解析

func (*Http) Name

func (h *Http) Name() string

func (*Http) Start

func (h *Http) Start(ctx context.Context)

Start 启动服务

func (*Http) Stop

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

Stop 停止server

func (*Http) SwagerDocs

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

type RouterBuilder

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

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"
)

Jump to

Keyboard shortcuts

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