Documentation
¶
Index ¶
- func Init(config Config) error
- func Run() error
- func Start() error
- func Stop() error
- func Use(servlets ...Servlet) error
- type App
- type CORSConfig
- type Config
- type Controller
- type ControllerFunc
- type LoggingConfig
- type PrefixedController
- type RoutingConfig
- type ServerConfig
- type Servlet
- type ServletInitContext
- type TCPKeepAliveListener
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CORSConfig ¶
type CORSConfig struct { // AllowOrigin defines a list of origins that may access the resource. // Optional. Default value []string{"*"}. AllowOrigins []string // AllowOriginFunc is a custom function to validate the origin. It takes the // origin as an argument and returns true if allowed or false otherwise. If // an error is returned, it is returned by the handler. If this option is // set, AllowOrigins is ignored. // Optional. AllowOriginFunc func(origin string) (bool, error) // AllowMethods defines a list methods allowed when accessing the resource. // This is used in response to a preflight request. // Optional. Default value DefaultCORSConfig.AllowMethods. AllowMethods []string // AllowHeaders defines a list of request headers that can be used when // making the actual request. This is in response to a preflight request. // Optional. Default value []string{}. AllowHeaders []string // AllowCredentials indicates whether or not the response to the request // can be exposed when the credential flag is true. When used as part of // a response to a preflight request, this indicates whether or not the // actual request can be made using credentials. // Optional. Default value is false. AllowCredentials bool // ExposeHeaders defines the whitelist headers that clients are allowed to // access. // Optional. Default value []string{}. ExposeHeaders []string // MaxAge indicates how long (in seconds) the results of a preflight request // can be cached. // Optional. Default value 0. MaxAge int }
CORSConfig defines the config for CORS middleware.
type Config ¶
type Config struct { // Server 服务器配置 Server ServerConfig // Logging 日志配置 Logging LoggingConfig // CORS 跨域配置 CORS CORSConfig // Recover 错误拦截配置 Recover slim.RecoveryConfig // Routing 路由配置 Routing RoutingConfig // Logger 日志打印接口 Logger *slim.Logger }
type Controller ¶
type Controller interface {
InitRoutes(r slim.RouteCollector)
}
type ControllerFunc ¶
type ControllerFunc func(r slim.RouteCollector)
func (ControllerFunc) InitRoutes ¶
func (f ControllerFunc) InitRoutes(r slim.RouteCollector)
type LoggingConfig ¶
type LoggingConfig = slim.LoggingConfig
type PrefixedController ¶
type PrefixedController interface {
RoutePrefix() string
}
type RoutingConfig ¶
type RoutingConfig struct { ErrorHandler slim.ErrorHandlerFunc Validator slim.Validator Renderer slim.Renderer Filesystem fs.FS JSONSerializer slim.Serializer XMLSerializer slim.Serializer MultipartMemoryLimit int64 // 文件上传大小限制 PrettyIndent string // json/xml 格式化缩进 JSONPCallbacks []string RouterCreator func(s *slim.Slim) slim.Router Middleware []slim.MiddlewareFunc Negotiator *slim.Negotiator }
RoutingConfig 路由配置
type ServerConfig ¶
type ServerConfig struct { Addr net.Addr // MaxHeaderBytes is used by the http server to limit the size of request headers. // This may need to be increased if accepting cookies from the public. MaxHeaderBytes int // ReadTimeout is used by the http server to set a maximum duration before // timing out read of the request. The default timeout is 10 seconds. ReadTimeout time.Duration // WriteTimeout is used by the http server to set a maximum duration before // timing out write of the response. The default timeout is 10 seconds. WriteTimeout time.Duration // IdleTimeout is used by the http server to set a maximum duration for // keep-alive connections. IdleTimeout time.Duration // TLSConfig optionally provides a TLS configuration for use // by ServeTLS and ListenAndServeTLS. Note that this value is // cloned by ServeTLS and ListenAndServeTLS, so it's not // possible to modify the configuration with methods like // tls.Config.SetSessionTicketKeys. To use // SetSessionTicketKeys, use Server.Serve with a TLS Listener // instead. TLSConfig *tls.Config // MultipartMemoryLimit 文件上传大小限制 MultipartMemoryLimit int64 }
ServerConfig 服务器配置 TODO(hupeh): 支持 HTTP2
type Servlet ¶
type Servlet interface { // Name 返回服务组件名称 Name() string // Priority 返回服务组件优先级 Priority() int // Init 初始化服务组件 Init(c ServletInitContext) error // Bootstrap 启动服务组件 Bootstrap() error // Destroy 销毁服务组件 Destroy() error }
Servlet 服务组件
type ServletInitContext ¶
type ServletInitContext interface { // Use 注册中间件 Use(middleware ...slim.MiddlewareFunc) // Routes 注册路由,会共享 Use 方法注册的中间件 Routes(controllers ...Controller) // Hosts 注册与指定 host 相关的路由,会共享 Use 方法注册的中间件 Hosts(host string, controllers ...Controller) }
func NewServletInitContext ¶
func NewServletInitContext() ServletInitContext
type TCPKeepAliveListener ¶
type TCPKeepAliveListener struct {
*net.TCPListener
}
TCPKeepAliveListener sets TCP keep-alive timeouts on accepted connections. It's used by ListenAndServe and ListenAndServeTLS so dead TCP connections (e.g., closing laptop mid-download) eventually go away.
This is here because it is not exposed in the stdlib and we'd prefer to have a hold of the http.Server's net.Listener so we can close it on shutdown.
Taken from here: https://golang.org/src/net/http/server.go?s=63121:63175#L2120
Source Files
¶
Click to show internal directories.
Click to hide internal directories.