Documentation
¶
Index ¶
- Constants
- func NewTestContext(w http.ResponseWriter) (*Context, *Router)
- type Context
- func (c *Context) CSRFAuthenticityTemplateField() string
- func (c *Context) CSRFAuthenticityToken() string
- func (c *Context) Deliver(mail *mailer.Mail) error
- func (c *Context) HTML(code int, name string, obj interface{})
- func (c *Context) IsAPIOnly() bool
- func (c *Context) Locale() string
- func (c *Context) Locales() []string
- func (c *Context) Logger() *support.Logger
- func (c *Context) RequestID() string
- func (c *Context) Session() Sessioner
- func (c *Context) SetLocale(locale string)
- func (c *Context) T(key string, args ...interface{}) string
- type ContextKey
- type H
- type HandlerFunc
- type HandlersChain
- type ResponseRecorder
- type Route
- type RouteGroup
- func (rg *RouteGroup) Any(path string, handlers ...HandlerFunc)
- func (rg *RouteGroup) DELETE(path string, handlers ...HandlerFunc)
- func (rg *RouteGroup) GET(path string, handlers ...HandlerFunc)
- func (rg *RouteGroup) Group(path string, handlers ...HandlerFunc) *RouteGroup
- func (rg *RouteGroup) HEAD(path string, handlers ...HandlerFunc)
- func (rg *RouteGroup) Handle(method, path string, handlers ...HandlerFunc)
- func (rg *RouteGroup) OPTIONS(path string, handlers ...HandlerFunc)
- func (rg *RouteGroup) PATCH(path string, handlers ...HandlerFunc)
- func (rg *RouteGroup) POST(path string, handlers ...HandlerFunc)
- func (rg *RouteGroup) PUT(path string, handlers ...HandlerFunc)
- func (rg *RouteGroup) Use(handlers ...HandlerFunc)
- type Router
- func (r *Router) Any(path string, handlers ...HandlerFunc)
- func (r *Router) DELETE(path string, handlers ...HandlerFunc)
- func (r *Router) GET(path string, handlers ...HandlerFunc)
- func (r *Router) Group(path string, handlers ...HandlerFunc) *RouteGroup
- func (r *Router) HEAD(path string, handlers ...HandlerFunc)
- func (r *Router) Handle(method, path string, handlers ...HandlerFunc)
- func (r *Router) NoRoute(handlers ...HandlerFunc)
- func (r *Router) OPTIONS(path string, handlers ...HandlerFunc)
- func (r *Router) PATCH(path string, handlers ...HandlerFunc)
- func (r *Router) POST(path string, handlers ...HandlerFunc)
- func (r *Router) PUT(path string, handlers ...HandlerFunc)
- func (r *Router) Use(handlers ...HandlerFunc)
- type Routes
- type Server
- func (s *Server) Any(path string, handlers ...HandlerFunc)
- func (s *Server) BasePath() string
- func (s *Server) Config() *support.Config
- func (s *Server) DELETE(path string, handlers ...HandlerFunc)
- func (s *Server) GET(path string, handlers ...HandlerFunc)
- func (s *Server) Group(path string, handlers ...HandlerFunc) *RouteGroup
- func (s *Server) HEAD(path string, handlers ...HandlerFunc)
- func (s *Server) HTTP() *http.Server
- func (s *Server) HTTPS() *http.Server
- func (s *Server) Handle(method, path string, handlers ...HandlerFunc)
- func (s *Server) Hosts() ([]string, error)
- func (s *Server) Info() []string
- func (s *Server) IsSSLCertExisted() bool
- func (s *Server) Middleware() []HandlerFunc
- func (s *Server) OPTIONS(path string, handlers ...HandlerFunc)
- func (s *Server) PATCH(path string, handlers ...HandlerFunc)
- func (s *Server) POST(path string, handlers ...HandlerFunc)
- func (s *Server) PUT(path string, handlers ...HandlerFunc)
- func (s *Server) Router() *Router
- func (s *Server) Routes() []Route
- func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (s *Server) ServeNoRoute()
- func (s *Server) ServeSPA(prefix string, fs http.FileSystem)
- func (s *Server) SetupGraphQL(path string, es graphql.ExecutableSchema, exts []graphql.HandlerExtension)
- func (s *Server) SetupMailerPreview(m *mailer.Engine, i18n *support.I18n)
- func (s *Server) TestHTTPRequest(method, path string, header H, body io.Reader) *ResponseRecorder
- func (s *Server) Use(handlers ...HandlerFunc)
- type Session
- func (s *Session) AddFlash(value interface{}, vars ...string)
- func (s *Session) Clear()
- func (s *Session) Delete(key interface{})
- func (s *Session) Flashes(vars ...string) []interface{}
- func (s *Session) Get(key interface{}) interface{}
- func (s *Session) Key() string
- func (s *Session) KeyPrefix() string
- func (s *Session) Options(options SessionOptions)
- func (s *Session) Save() error
- func (s *Session) Session() *gorsessions.Session
- func (s *Session) Set(key interface{}, val interface{})
- func (s *Session) SetKeyPrefix(p string)
- func (s *Session) Values() map[interface{}]interface{}
- func (s *Session) Written() bool
- type SessionOptions
- type SessionStore
- type Sessioner
Constants ¶
const ( // LiveReloadWSPort is the websocket port for the SSR live reload server. LiveReloadWSPort = "12450" // LiveReloadWSSPort is the websocket SSL port for the SSR live reload // server. LiveReloadWSSPort = "12451" // LiveReloadPath is the websocket path for the SSR live reload server. LiveReloadPath = "/reload" )
Variables ¶
This section is empty.
Functions ¶
func NewTestContext ¶
func NewTestContext(w http.ResponseWriter) (*Context, *Router)
NewTestContext returns a fresh router w/ context for testing purposes.
Types ¶
type Context ¶
Context contains the request information and is meant to be passed through the entire HTTP request.
func (*Context) CSRFAuthenticityTemplateField ¶
CSRFAuthenticityTemplateField is a template helper for html/template that provides an <input> field populated with a CSRF authenticity token.
func (*Context) CSRFAuthenticityToken ¶
CSRFAuthenticityToken returns the CSRF authenticity token for the request.
func (*Context) HTML ¶
HTML renders the HTTP template with the HTTP code and the "text/html" Content-Type header.
func (*Context) IsAPIOnly ¶
IsAPIOnly checks if a request is API only based on `X-API-Only` request header.
type ContextKey ¶
type ContextKey string
ContextKey is the context key with appy namespace.
func (ContextKey) String ¶
func (c ContextKey) String() string
type HandlerFunc ¶
type HandlerFunc func(*Context)
HandlerFunc defines the handler used by middleware as return value.
func CSRFSkipCheck ¶
func CSRFSkipCheck() HandlerFunc
CSRFSkipCheck skips the CSRF check for the request.
type ResponseRecorder ¶
type ResponseRecorder struct { *httptest.ResponseRecorder // contains filtered or unexported fields }
ResponseRecorder is an implementation of http.ResponseWriter that records its mutations for later inspection in tests.
func NewResponseRecorder ¶
func NewResponseRecorder() *ResponseRecorder
NewResponseRecorder returns an initialized ResponseRecorder for testing purpose.
func (*ResponseRecorder) CloseNotify ¶
func (r *ResponseRecorder) CloseNotify() <-chan bool
CloseNotify implements http.CloseNotifier.
type Route ¶
type Route struct { Method string Path string Handler string HandlerFunc HandlerFunc }
Route represents a request route's specification which contains method and path and its handler.
type RouteGroup ¶
type RouteGroup struct { *gin.RouterGroup // contains filtered or unexported fields }
RouteGroup is associated with a prefix and an array of handlers.
func (*RouteGroup) Any ¶
func (rg *RouteGroup) Any(path string, handlers ...HandlerFunc)
Any registers a route that matches all the HTTP methods, i.e. GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE.
func (*RouteGroup) DELETE ¶
func (rg *RouteGroup) DELETE(path string, handlers ...HandlerFunc)
DELETE is a shortcut for Handle("DELETE", path, handlers).
func (*RouteGroup) GET ¶
func (rg *RouteGroup) GET(path string, handlers ...HandlerFunc)
GET is a shortcut for Handle("GET", path, handlers).
func (*RouteGroup) Group ¶
func (rg *RouteGroup) Group(path string, handlers ...HandlerFunc) *RouteGroup
Group creates a new route group. You should add all the routes that have common middlewares or the same path prefix.
func (*RouteGroup) HEAD ¶
func (rg *RouteGroup) HEAD(path string, handlers ...HandlerFunc)
HEAD is a shortcut for Handle("HEAD", path, handlers).
func (*RouteGroup) Handle ¶
func (rg *RouteGroup) Handle(method, path string, handlers ...HandlerFunc)
Handle registers a new request handle with the method, given path and middleware.
func (*RouteGroup) OPTIONS ¶
func (rg *RouteGroup) OPTIONS(path string, handlers ...HandlerFunc)
OPTIONS is a shortcut for Handle("OPTIONS", path, handlers).
func (*RouteGroup) PATCH ¶
func (rg *RouteGroup) PATCH(path string, handlers ...HandlerFunc)
PATCH is a shortcut for Handle("PATCH", path, handlers).
func (*RouteGroup) POST ¶
func (rg *RouteGroup) POST(path string, handlers ...HandlerFunc)
POST is a shortcut for Handle("POST", path, handlers).
func (*RouteGroup) PUT ¶
func (rg *RouteGroup) PUT(path string, handlers ...HandlerFunc)
PUT is a shortcut for Handle("PUT", path, handlers).
func (*RouteGroup) Use ¶
func (rg *RouteGroup) Use(handlers ...HandlerFunc)
Use attaches a global middleware to the router.
type Router ¶
Router maintains the routing logic.
func (*Router) Any ¶
func (r *Router) Any(path string, handlers ...HandlerFunc)
Any registers a route that matches all the HTTP methods, i.e. GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE.
func (*Router) DELETE ¶
func (r *Router) DELETE(path string, handlers ...HandlerFunc)
DELETE is a shortcut for Handle("DELETE", path, handlers).
func (*Router) GET ¶
func (r *Router) GET(path string, handlers ...HandlerFunc)
GET is a shortcut for Handle("GET", path, handlers).
func (*Router) Group ¶
func (r *Router) Group(path string, handlers ...HandlerFunc) *RouteGroup
Group creates a new route group. You should add all the routes that have common middlewares or the same path prefix.
func (*Router) HEAD ¶
func (r *Router) HEAD(path string, handlers ...HandlerFunc)
HEAD is a shortcut for Handle("HEAD", path, handlers).
func (*Router) Handle ¶
func (r *Router) Handle(method, path string, handlers ...HandlerFunc)
Handle registers a new request handle with the method, given path and middleware.
func (*Router) NoRoute ¶
func (r *Router) NoRoute(handlers ...HandlerFunc)
NoRoute adds handlers for NoRoute which returns a 404 code by default.
func (*Router) OPTIONS ¶
func (r *Router) OPTIONS(path string, handlers ...HandlerFunc)
OPTIONS is a shortcut for Handle("OPTIONS", path, handlers).
func (*Router) PATCH ¶
func (r *Router) PATCH(path string, handlers ...HandlerFunc)
PATCH is a shortcut for Handle("PATCH", path, handlers).
func (*Router) POST ¶
func (r *Router) POST(path string, handlers ...HandlerFunc)
POST is a shortcut for Handle("POST", path, handlers).
func (*Router) PUT ¶
func (r *Router) PUT(path string, handlers ...HandlerFunc)
PUT is a shortcut for Handle("PUT", path, handlers).
func (*Router) Use ¶
func (r *Router) Use(handlers ...HandlerFunc)
Use attaches a global middleware to the router.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server processes the HTTP requests.
func NewAppServer ¶
func NewAppServer(asset *support.Asset, config *support.Config, i18n *support.I18n, ml *mailer.Engine, logger *support.Logger, viewFuncs map[string]interface{}) *Server
NewAppServer initializes Server instance with built-in middleware.
func (*Server) Any ¶
func (s *Server) Any(path string, handlers ...HandlerFunc)
Any registers a route that matches all the HTTP methods, i.e. GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE.
func (*Server) DELETE ¶
func (s *Server) DELETE(path string, handlers ...HandlerFunc)
DELETE is a shortcut for Handle("DELETE", path, handlers).
func (*Server) GET ¶
func (s *Server) GET(path string, handlers ...HandlerFunc)
GET is a shortcut for Handle("GET", path, handlers).
func (*Server) Group ¶
func (s *Server) Group(path string, handlers ...HandlerFunc) *RouteGroup
Group creates a new route group. You should add all the routes that have common middlewares or the same path prefix.
func (*Server) HEAD ¶
func (s *Server) HEAD(path string, handlers ...HandlerFunc)
HEAD is a shortcut for Handle("HEAD", path, handlers).
func (*Server) Handle ¶
func (s *Server) Handle(method, path string, handlers ...HandlerFunc)
Handle registers a new request handle with the method, given path and middleware.
func (*Server) IsSSLCertExisted ¶
IsSSLCertExisted checks if `./tmp/ssl` exists and contains the locally trusted SSL certificates.
func (*Server) Middleware ¶
func (s *Server) Middleware() []HandlerFunc
Middleware returns the global middleware list.
func (*Server) OPTIONS ¶
func (s *Server) OPTIONS(path string, handlers ...HandlerFunc)
OPTIONS is a shortcut for Handle("OPTIONS", path, handlers).
func (*Server) PATCH ¶
func (s *Server) PATCH(path string, handlers ...HandlerFunc)
PATCH is a shortcut for Handle("PATCH", path, handlers).
func (*Server) POST ¶
func (s *Server) POST(path string, handlers ...HandlerFunc)
POST is a shortcut for Handle("POST", path, handlers).
func (*Server) PUT ¶
func (s *Server) PUT(path string, handlers ...HandlerFunc)
PUT is a shortcut for Handle("PUT", path, handlers).
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP conforms to the http.Handler interface.
func (*Server) ServeNoRoute ¶
func (s *Server) ServeNoRoute()
ServeNoRoute handles custom 404 not found error.
func (*Server) ServeSPA ¶
func (s *Server) ServeSPA(prefix string, fs http.FileSystem)
ServeSPA serves the SPA at the specified prefix path.
func (*Server) SetupGraphQL ¶
func (s *Server) SetupGraphQL(path string, es graphql.ExecutableSchema, exts []graphql.HandlerExtension)
SetupGraphQL sets up the GraphQL stack.
func (*Server) SetupMailerPreview ¶
SetupMailerPreview sets up the mailer preview for debugging purpose.
func (*Server) TestHTTPRequest ¶
TestHTTPRequest provides a simple way to fire HTTP request to the server.
func (*Server) Use ¶
func (s *Server) Use(handlers ...HandlerFunc)
Use attaches a global middleware to the router.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session provides the session functionality for a single HTTP request.
func (*Session) AddFlash ¶
AddFlash adds a flash message to the session. A single variadic argument is accepted, and it is optional: it defines the flash key. If not defined "_flash" is used by default.
func (*Session) Delete ¶
func (s *Session) Delete(key interface{})
Delete removes the session value associated to the given key.
func (*Session) Flashes ¶
Flashes returns a slice of flash messages from the session. A single variadic argument is accepted, and it is optional: it defines the flash key. If not defined "_flash" is used by default.
func (*Session) Get ¶
func (s *Session) Get(key interface{}) interface{}
Get returns the session value associated to the given key.
func (*Session) KeyPrefix ¶
KeyPrefix returns the key prefix for the session, not available for CookieStore.
func (*Session) Options ¶
func (s *Session) Options(options SessionOptions)
Options sets configuration for a session.
func (*Session) Session ¶
func (s *Session) Session() *gorsessions.Session
Session retrieves the data for the specific HTTP request.
func (*Session) Set ¶
func (s *Session) Set(key interface{}, val interface{})
Set sets the session value associated to the given key.
func (*Session) SetKeyPrefix ¶
SetKeyPrefix sets the key prefix for the session, not available for CookieStore.
type SessionOptions ¶ added in v0.1.1
type SessionOptions = ginsessions.Options
SessionOptions defines the session cookie's configuration.
type SessionStore ¶
type SessionStore interface { gorsessions.Store // Options sets the cookie configuration for a session. Options(SessionOptions) // KeyPrefix returns the prefix for the store key, not available for CookieStore. KeyPrefix() string // SetKeyPrefix sets the prefix for the store key, not available for CookieStore. SetKeyPrefix(p string) }
SessionStore is an interface for custom session stores.
type Sessioner ¶
type Sessioner interface { // AddFlash adds a flash message to the session. // A single variadic argument is accepted, and it is optional: it defines the flash key. // If not defined "_flash" is used by default. AddFlash(value interface{}, vars ...string) // Clear deletes all values in the session. Clear() // Delete removes the session value associated to the given key. Delete(key interface{}) // Flashes returns a slice of flash messages from the session. // A single variadic argument is accepted, and it is optional: it defines the flash key. // If not defined "_flash" is used by default. Flashes(vars ...string) []interface{} // Get returns the session value associated to the given key. Get(key interface{}) interface{} // Key returns the session key. Key() string // Options sets the cookie configuration for a session. Options(SessionOptions) // Set sets the session value associated to the given key. Set(key interface{}, val interface{}) // Save saves all sessions used during the current request. Save() error // KeyPrefix returns the key prefix for the session, not available for CookieStore. KeyPrefix() string // SetKeyPrefix sets the key prefix for the session, not available for CookieStore. SetKeyPrefix(p string) // Values returns all values in the session. Values() map[interface{}]interface{} }
Sessioner stores the values and optional configuration for a session.