Documentation ¶
Index ¶
- Variables
- func ExtractRequestID(ctx Context) string
- func NewTemplateRenderer(root string) echo.Renderer
- func RequestIsAJAX(req *http.Request) bool
- func RequestRawURL(r *http.Request) string
- func RequestRemoteAddr(req *http.Request) string
- func RequestScheme(r *http.Request) string
- type App
- type AppContext
- type Context
- type Controller
- type HandlerFunc
- type Logger
- type MiddlewareFunc
- type Server
- type ServerOptions
- type StaticOptions
- type TemplateRenderer
Constants ¶
This section is empty.
Variables ¶
var ( // RequestHeaderProtocol header for identifying the protocol (HTTP or HTTPS) that a client used to connect to your proxy or load balancer. RequestHeaderProtocol = "X-Forwarded-Proto" // RequestHeaderForwarded header for identifying the originating IP address of a client connecting to a web server through an HTTP proxy or a load balancer. RequestHeaderForwarded = "X-Forwarded-For" // RequestHeaderRequestedWith header for JavaScript libraries sending requests from browser. RequestHeaderRequestedWith = "X-Requested-With" )
var ContextLogger = log.Extract
ContextLogger returns logger entry for current request context
var ContextRequestID = ExtractRequestID
Functions ¶
func ExtractRequestID ¶
ExtractRequestID returns ID for current request
func NewTemplateRenderer ¶
func NewTemplateRenderer(root string) echo.Renderer
NewTemplateRenderer 创建新的模板渲染器 root是模板文件的根路径
func RequestIsAJAX ¶ added in v1.0.1
RequestIsAJAX check request header to see if the request is a XMLHttpRequest.
func RequestRawURL ¶
RequestRawURL returns request original URL.
func RequestRemoteAddr ¶
RequestRemoteAddr finds the real remote address from request.
If the web server is behind an HTTP proxy or a load balancer, http.Request.RemoteAddr is IP of the proxy or load balancer. But most HTTP proxies and load balancers will attach a header to tell the web server request's real IP.
func RequestScheme ¶
RequestScheme try to parses request scheme.
If the web server is behind an HTTP proxy or a load balancer, it's hard to known if original request's scheme by http.Request.TLS property. Most HTTP proxies and load balancers will attach a header to tell upstream server the request's real scheme. So check if the header is set first.
Types ¶
type AppContext ¶
type AppContext struct { echo.Context // contains filtered or unexported fields }
AppContext is wrapper of echo.Context. It holds App instance of server.
func NewAppContext ¶
func NewAppContext(c echo.Context, app *App, logger *logrus.Entry) *AppContext
type Controller ¶
type Controller interface { // RegisterRoutes 注册控制器路由 RegisterRoutes(app *App) }
Controller 控制器接口
type MiddlewareFunc ¶
type MiddlewareFunc = echo.MiddlewareFunc
MiddlewareFunc is alias of echo.MiddlewareFunc
func NewAppContextMiddleware ¶
func NewAppContextMiddleware(app *App) MiddlewareFunc
NewAppContextMiddleware returns a middleware which extends echo.Context
type Server ¶
type Server struct { Logger *Logger // contains filtered or unexported fields }
Server HTTP服务器
func (*Server) RegisterControllers ¶
func (s *Server) RegisterControllers(cs ...Controller)
RegisterControllers 注册控制器列表
func (*Server) RegisterGlobalMiddlewares ¶
func (s *Server) RegisterGlobalMiddlewares(middlewares ...MiddlewareFunc)
RegisterGlobalMiddlewares 注册全局中间件
type ServerOptions ¶
type ServerOptions struct { Host string `yaml:"host" mapstructure:"path"` Port int `yaml:"port" mapstructure:"port"` Views string `yaml:"views" mapstructure:"views"` Static StaticOptions `yaml:"static" mapstructure:"static"` }
ServerOptions 服务器配置
type StaticOptions ¶
type StaticOptions struct { Path string `yaml:"path" mapstructure:"path"` Root string `yaml:"root" mapstructure:"root"` }
StaticOptions 静态文件配置
type TemplateRenderer ¶
type TemplateRenderer struct {
// contains filtered or unexported fields
}
TemplateRenderer 自定义模板渲染器