Back to

Package gopress

Latest Go to latest

The highest tagged major version is .

Published: Aug 29, 2019 | License: MIT | Module:



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

func ExtractRequestID

func ExtractRequestID(ctx Context) string

ExtractRequestID returns ID for current request

func NewTemplateRenderer

func NewTemplateRenderer(root string) echo.Renderer

NewTemplateRenderer 创建新的模板渲染器 root是模板文件的根路径

func RequestIsAJAX

func RequestIsAJAX(req *http.Request) bool

RequestIsAJAX check request header to see if the request is a XMLHttpRequest.

func RequestRawURL

func RequestRawURL(r *http.Request) string

RequestRawURL returns request original URL.

func RequestRemoteAddr

func RequestRemoteAddr(req *http.Request) string

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

func RequestScheme(r *http.Request) string

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.

type App

type App struct {

	Logger *Logger

App wrapper of echo.Echo and Container

func ContextApp

func ContextApp(ctx Context) *App

ContextApp try to get App instance from Context

type AppContext

type AppContext struct {
	// 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

func (*AppContext) App

func (c *AppContext) App() *App

App returns the App instance

type Context

type Context = echo.Context

Context is alias of echo.Context

type Controller

type Controller interface {

	// RegisterRoutes 注册控制器路由
	RegisterRoutes(app *App)

Controller 控制器接口

type HandlerFunc

type HandlerFunc = echo.HandlerFunc

HandlerFunc is alias of echo.HandlerFunc

type Logger

type Logger = log.Logger

Logger wraps logrus.Logger

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 NewServer

func NewServer(options ServerOptions) *Server

NewServer 创建HTTP服务器

func (*Server) App

func (s *Server) App() *App

App returns App instance of server

func (*Server) RegisterControllers

func (s *Server) RegisterControllers(cs ...Controller)

RegisterControllers 注册控制器列表

func (*Server) RegisterGlobalMiddlewares

func (s *Server) RegisterGlobalMiddlewares(middlewares ...MiddlewareFunc)

RegisterGlobalMiddlewares 注册全局中间件

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown 关闭服务器

func (*Server) Start

func (s *Server) Start() error

Start 启动HTTP服务器

func (*Server) StartTLS

func (s *Server) StartTLS(cert, key string) error

StartTLS 启动HTTPS服务器

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 自定义模板渲染器

func (*TemplateRenderer) Parse

func (t *TemplateRenderer) Parse(name string) (*raymond.Template, error)

Parse 根据name获取解析后的模板 模板解析成功后缓存在Map中,下次使用时直接从Map读取

func (*TemplateRenderer) Render

func (t *TemplateRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error

Render 渲染模板 实现 echo.Renderer 接口

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier