pack

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2020 License: MIT Imports: 51 Imported by: 0

Documentation

Index

Constants

View Source
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

type Context struct {
	*gin.Context
}

Context contains the request information and is meant to be passed through the entire HTTP request.

func (*Context) CSRFAuthenticityTemplateField

func (c *Context) CSRFAuthenticityTemplateField() string

CSRFAuthenticityTemplateField is a template helper for html/template that provides an <input> field populated with a CSRF authenticity token.

func (*Context) CSRFAuthenticityToken

func (c *Context) CSRFAuthenticityToken() string

CSRFAuthenticityToken returns the CSRF authenticity token for the request.

func (*Context) Deliver

func (c *Context) Deliver(mail *mailer.Mail) error

Deliver sends out the email via SMTP immediately.

func (*Context) HTML

func (c *Context) HTML(code int, name string, obj interface{})

HTML renders the HTTP template with the HTTP code and the "text/html" Content-Type header.

func (*Context) IsAPIOnly

func (c *Context) IsAPIOnly() bool

IsAPIOnly checks if a request is API only based on `X-API-Only` request header.

func (*Context) Locale

func (c *Context) Locale() string

Locale returns the request context's locale.

func (*Context) Locales

func (c *Context) Locales() []string

Locales returns the request context's available locales.

func (*Context) Logger

func (c *Context) Logger() *support.Logger

Logger returns the request context's logger.

func (*Context) RequestID

func (c *Context) RequestID() string

RequestID returns the unique request ID.

func (*Context) Session

func (c *Context) Session() Sessioner

Session returns the session in the request context.

func (*Context) SetLocale

func (c *Context) SetLocale(locale string)

SetLocale sets the request's locale.

func (*Context) T

func (c *Context) T(key string, args ...interface{}) string

T translates a message based on the given key.

type ContextKey

type ContextKey string

ContextKey is the context key with appy namespace.

func (ContextKey) String

func (c ContextKey) String() string

type H

type H = support.H

H is a shortcut for map[string]interface{}.

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 HandlersChain

type HandlersChain []HandlerFunc

HandlersChain defines the HandlerFunc array.

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) Close

func (r *ResponseRecorder) Close()

Close close the notify channel.

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

type Router struct {
	*gin.Engine
	// contains filtered or unexported fields
}

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 Routes

type Routes []Route

Routes defines the array of Route.

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 NewServer

func NewServer(asset *support.Asset, config *support.Config, logger *support.Logger) *Server

NewServer initializes Server instance without 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) BasePath

func (s *Server) BasePath() string

BasePath returns the base path.

func (*Server) Config

func (s *Server) Config() *support.Config

Config returns the server's configuration.

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) HTTP

func (s *Server) HTTP() *http.Server

HTTP returns the HTTP server instance.

func (*Server) HTTPS

func (s *Server) HTTPS() *http.Server

HTTPS returns the HTTPS server instance.

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) Hosts

func (s *Server) Hosts() ([]string, error)

Hosts returns the server hosts list.

func (*Server) Info

func (s *Server) Info() []string

Info returns the server info.

func (*Server) IsSSLCertExisted

func (s *Server) IsSSLCertExisted() bool

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) Router

func (s *Server) Router() *Router

Router returns the router instance.

func (*Server) Routes

func (s *Server) Routes() []Route

Routes returns all the routes including those in middlewares.

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

func (s *Server) SetupMailerPreview(m *mailer.Engine, i18n *support.I18n)

SetupMailerPreview sets up the mailer preview for debugging purpose.

func (*Server) TestHTTPRequest

func (s *Server) TestHTTPRequest(method, path string, header H, body io.Reader) *ResponseRecorder

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

func (s *Session) AddFlash(value interface{}, vars ...string)

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) Clear

func (s *Session) Clear()

Clear deletes all values in the session.

func (*Session) Delete

func (s *Session) Delete(key interface{})

Delete removes the session value associated to the given key.

func (*Session) Flashes

func (s *Session) Flashes(vars ...string) []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.

func (*Session) Get

func (s *Session) Get(key interface{}) interface{}

Get returns the session value associated to the given key.

func (*Session) Key

func (s *Session) Key() string

Key returns the session key.

func (*Session) KeyPrefix

func (s *Session) KeyPrefix() string

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) Save

func (s *Session) Save() error

Save saves all sessions used during the current request.

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

func (s *Session) SetKeyPrefix(p string)

SetKeyPrefix sets the key prefix for the session, not available for CookieStore.

func (*Session) Values

func (s *Session) Values() map[interface{}]interface{}

Values returns all values in the session.

func (*Session) Written

func (s *Session) Written() bool

Written indicates if the session's key/value map had already been stored into the data store.

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.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL