http

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AppName = "http"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GinRouterBuilder

type GinRouterBuilder struct {
	*RouterBuilderHooks
}

func NewGinRouterBuilder

func NewGinRouterBuilder() *GinRouterBuilder

func (*GinRouterBuilder) Build

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

type GoRestfulRouterBuilder

type GoRestfulRouterBuilder struct {
	*RouterBuilderHooks
}

func NewGoRestfulRouterBuilder

func NewGoRestfulRouterBuilder() *GoRestfulRouterBuilder

func (*GoRestfulRouterBuilder) Build

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

type Http

type Http struct {
	ioc.ObjectImpl

	// 是否开启HTTP Server, 默认会根据是否有注册得有API对象来自动开启
	Enable *bool `json:"enable" yaml:"enable" toml:"enable" env:"HTTP_ENABLE"`
	// HTTP服务Host
	Host string `json:"host" yaml:"host" toml:"host" env:"HTTP_HOST"`
	// HTTP服务端口
	Port int `json:"port" yaml:"port" toml:"port" env:"HTTP_PORT"`
	// API接口前缀
	PathPrefix string `json:"path_prefix" yaml:"path_prefix" toml:"path_prefix" env:"HTTP_PATH_PREFIX"`

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

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

	// 开启Trace
	EnableTrace bool `toml:"enable_trace" json:"enable_trace" yaml:"enable_trace" env:"HTTP_ENABLE_TRACE"`
	// 开启Trace
	Debug bool `toml:"debug" json:"debug" yaml:"debug" env:"HTTP_DEBUG"`
	// contains filtered or unexported fields
}

func Get

func Get() *Http

func (*Http) Addr

func (h *Http) Addr() string

func (*Http) ApiObjectAddr

func (h *Http) ApiObjectAddr(obj ioc.Object) string

-----------------------给api-doc调用的--------------------------------

func (*Http) ApiObjectAddrCustom added in v1.2.6

func (h *Http) ApiObjectAddrCustom(obj ioc.Object) string

func (*Http) ApiObjectPathPrefix

func (h *Http) ApiObjectPathPrefix(obj ioc.Object) string

func (*Http) BuildRouter

func (h *Http) BuildRouter() error

func (*Http) DetectAndSetWebFramework

func (h *Http) DetectAndSetWebFramework()

func (*Http) GetRouterBuilder

func (h *Http) GetRouterBuilder() RouterBuilder

这个部分给cors用的

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 {
	BeforeLoadHooks(...RouterHook)
	AfterLoadHooks(...RouterHook)
	Build() (http.Handler, error)
}

type RouterBuilderHooks

type RouterBuilderHooks struct {
	Before []RouterHook
	After  []RouterHook
}

func NewRouterBuilderHooks

func NewRouterBuilderHooks() *RouterBuilderHooks

func (*RouterBuilderHooks) AfterLoadHooks

func (b *RouterBuilderHooks) AfterLoadHooks(hooks ...RouterHook)

func (*RouterBuilderHooks) BeforeLoadHooks

func (b *RouterBuilderHooks) BeforeLoadHooks(hooks ...RouterHook)

type RouterHook

type RouterHook func(http.Handler)

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