Documentation ¶
Index ¶
- Constants
- Variables
- type AppConfig
- type Asset
- type AssetsConfigs
- type AuthUser
- type AuthUserType
- type Authenticable
- type Authentication
- func (auth Authentication) CompareOAuthState(ctx Context, state string) error
- func (auth Authentication) ComparePasswordAndHash(password, hash string) (match bool, err error)
- func (auth *Authentication) ExchangeAuthorisationCode(ctx Context, authorisationCode string) (OAuthResult, error)
- func (auth Authentication) GeneratePasswordHash(c *PasswordConfig, password string) (string, error)
- func (auth *Authentication) GetAuthUser(ctx Context) AuthUser
- func (auth *Authentication) GetAuthorizationUri(ctx Context) string
- func (auth *Authentication) Login(ctx Context, user Authenticable) error
- func (auth *Authentication) Logout(ctx Context) error
- type AuthenticationConfig
- type AuthenticationProvider
- type Context
- type Cookies
- type DatabaseConfig
- type DefaultConfiguration
- type DefaultContext
- func (ctx *DefaultContext) Bind(dst interface{}) error
- func (ctx *DefaultContext) Cookies() *Cookies
- func (ctx *DefaultContext) Data() map[string]interface{}
- func (ctx *DefaultContext) Dojo() *Dojo
- func (ctx *DefaultContext) JSON(code int, data interface{}) error
- func (ctx *DefaultContext) NoContent(code int) error
- func (ctx *DefaultContext) Param(key string) string
- func (ctx *DefaultContext) Params() ParamValues
- func (ctx *DefaultContext) RealIP() string
- func (ctx *DefaultContext) Request() *http.Request
- func (ctx *DefaultContext) Response() http.ResponseWriter
- func (ctx *DefaultContext) Session() *Session
- func (ctx *DefaultContext) Set(key string, value interface{})
- func (ctx *DefaultContext) Value(key interface{}) interface{}
- func (ctx *DefaultContext) View(viewName string, data ViewAdditionalData) error
- type Dojo
- type Environment
- type ExchangeAuthorisationCodeRequest
- type FileExtension
- type HTTPError
- type HTTPErrorHandler
- type Handler
- type JsonResponseBody
- type Map
- type Middleware
- type MiddlewareFunc
- type MiddlewareRegistry
- type MiddlewareStack
- type OAuthResult
- type ParamValues
- type PasswordConfig
- type RedisConfig
- type RouteConfig
- type Router
- func (r *Router) Connect(path string, handler Handler, middlewares ...MiddlewareFunc)
- func (r *Router) Delete(path string, handler Handler, middlewares ...MiddlewareFunc)
- func (r *Router) DeleteWithName(path string, name string, handler Handler, middlewares ...MiddlewareFunc)
- func (r *Router) Get(path string, handler Handler, middlewares ...MiddlewareFunc)
- func (r *Router) GetMux() *mux.Router
- func (r *Router) GetWithName(path string, name string, handler Handler, middlewares ...MiddlewareFunc)
- func (r *Router) Host(tpl string, cb func(router *Router))
- func (r *Router) Options(path string, handler Handler, middlewares ...MiddlewareFunc)
- func (r *Router) Patch(path string, handler Handler, middlewares ...MiddlewareFunc)
- func (r *Router) PatchWithName(path string, name string, handler Handler, middlewares ...MiddlewareFunc)
- func (r *Router) Post(path string, handler Handler, middlewares ...MiddlewareFunc)
- func (r *Router) PostWithName(path string, name string, handler Handler, middlewares ...MiddlewareFunc)
- func (r *Router) Put(path string, handler Handler, middlewares ...MiddlewareFunc)
- func (r *Router) PutWithName(path string, name string, handler Handler, middlewares ...MiddlewareFunc)
- func (r Router) Redirect(ctx Context, url string)
- func (r *Router) RouteGroup(prefix string, cb func(router *Router))
- func (r *Router) Trace(path string, handler Handler, middlewares ...MiddlewareFunc)
- func (r *Router) Use(name string)
- func (r *Router) UseStack(name string)
- type Session
- func (s *Session) Clear()
- func (s *Session) Delete(name interface{})
- func (s *Session) Flash(key string, value interface{})
- func (s *Session) Get(name interface{}) interface{}
- func (s *Session) GetFlash(key string) []interface{}
- func (s *Session) GetOnce(name interface{}) interface{}
- func (s *Session) Save() error
- func (s *Session) Set(name, value interface{})
- func (s *Session) WithOld(data map[string]interface{})
- type SessionConfig
- type ViewAdditionalData
- type ViewConfig
- type ViewData
Constants ¶
const ( // PROPFIND Method can be used on collection and property resources. PROPFIND = "PROPFIND" // REPORT Method can be used to get information about a resource, see rfc 3253 REPORT = "REPORT" )
const ( MIMEApplicationJSON = "application/json" MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8 MIMECloudEventJSONCharsetUTF8 = "application/cloudevents+json" + "; " + charsetUTF8 MIMEApplicationJavaScript = "application/javascript" MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8 MIMEApplicationXML = "application/xml" MIMEApplicationXMLCharsetUTF8 = MIMEApplicationXML + "; " + charsetUTF8 MIMETextXML = "text/xml" MIMETextXMLCharsetUTF8 = MIMETextXML + "; " + charsetUTF8 MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEApplicationProtobuf = "application/protobuf" MIMEApplicationMsgpack = "application/msgpack" MIMETextHTML = "text/html" MIMETextHTMLCharsetUTF8 = MIMETextHTML + "; " + charsetUTF8 MIMETextPlain = "text/plain" MIMETextPlainCharsetUTF8 = MIMETextPlain + "; " + charsetUTF8 MIMEMultipartForm = "multipart/form-data" MIMEOctetStream = "application/octet-stream" )
MIME types
const ( HeaderAccept = "Accept" HeaderAcceptEncoding = "Accept-Encoding" HeaderAllow = "Allow" HeaderAuthorization = "Authorization" HeaderContentDisposition = "Content-Disposition" HeaderContentEncoding = "Content-Encoding" HeaderContentLength = "Content-Length" HeaderContentType = "Content-Type" HeaderCookie = "Cookie" HeaderSetCookie = "Set-Cookie" HeaderIfModifiedSince = "If-Modified-Since" HeaderLastModified = "Last-Modified" HeaderLocation = "Location" HeaderUpgrade = "Upgrade" HeaderVary = "Vary" HeaderWWWAuthenticate = "WWW-Authenticate" HeaderXForwardedFor = "X-Forwarded-For" HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXForwardedProtocol = "X-Forwarded-Protocol" HeaderXForwardedSsl = "X-Forwarded-Ssl" HeaderXUrlScheme = "X-Url-Scheme" HeaderXHTTPMethodOverride = "X-HTTP-Method-Override" HeaderXRealIP = "X-Real-IP" HeaderXRequestID = "X-Request-ID" HeaderXRequestedWith = "X-Requested-With" HeaderServer = "Server" HeaderOrigin = "Origin" // Access control HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers" HeaderAccessControlMaxAge = "Access-Control-Max-Age" // Security HeaderStrictTransportSecurity = "Strict-Transport-Security" HeaderXContentTypeOptions = "X-Content-Type-Options" HeaderXXSSProtection = "X-XSS-Protection" HeaderXFrameOptions = "X-Frame-Options" HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only" HeaderXCSRFToken = "X-CSRF-Token" HeaderReferrerPolicy = "Referrer-Policy" )
Headers
const FlashOldKey = "_old_inputs"
Variables ¶
var ( // ErrInvalidHash in returned by ComparePasswordAndHash if the provided // hash isn't in the expected format. ErrInvalidHash = errors.New("argon2id: hash is not in the correct format") // ErrIncompatibleVersion in returned by ComparePasswordAndHash if the // provided hash was created using a different version of Argon2. ErrIncompatibleVersion = errors.New("argon2id: incompatible version of argon2") )
var ( ErrUnsupportedMediaType = NewHTTPError(http.StatusUnsupportedMediaType) ErrNotFound = NewHTTPError(http.StatusNotFound) ErrForbidden = NewHTTPError(http.StatusForbidden) ErrMethodNotAllowed = NewHTTPError(http.StatusMethodNotAllowed) ErrStatusRequestEntityTooLarge = NewHTTPError(http.StatusRequestEntityTooLarge) ErrTooManyRequests = NewHTTPError(http.StatusTooManyRequests) ErrBadRequest = NewHTTPError(http.StatusBadRequest) ErrBadGateway = NewHTTPError(http.StatusBadGateway) ErrInternalServerError = NewHTTPError(http.StatusInternalServerError) ErrRequestTimeout = NewHTTPError(http.StatusRequestTimeout) ErrValidatorNotRegistered = errors.New("validator not registered") ErrRendererNotRegistered = errors.New("renderer not registered") ErrInvalidRedirectCode = errors.New("invalid redirect status code") ErrCookieNotFound = errors.New("cookie not found") ErrInvalidCertOrKeyType = errors.New("invalid cert or key type, must be string or []byte") ErrInvalidListenerNetwork = errors.New("invalid listener network") )
var DefaultConfigs = &PasswordConfig{
Memory: 64 * 1024,
Iterations: 1,
Parallelism: 2,
SaltLength: 16,
KeyLength: 32,
}
Functions ¶
This section is empty.
Types ¶
type Asset ¶ added in v0.0.6
type Asset struct { Name string Extension FileExtension Path string }
type AssetsConfigs ¶ added in v0.0.6
type AssetsConfigs struct {
Path string `json:"path" yaml:"path"`
}
type AuthUser ¶ added in v0.0.15
func (*AuthUser) GetAuthData ¶ added in v0.0.25
func (u *AuthUser) GetAuthData() interface{}
func (*AuthUser) GetAuthType ¶ added in v0.0.25
func (u *AuthUser) GetAuthType() AuthUserType
type AuthUserType ¶ added in v0.0.15
type AuthUserType string
const ( GuestUserType AuthUserType = "guest" UserUserType AuthUserType = "user" )
type Authenticable ¶ added in v0.0.25
type Authenticable interface { GetAuthType() AuthUserType GetAuthID() uuid.UUID GetAuthData() interface{} IsGuest() bool }
type Authentication ¶ added in v0.0.15
type Authentication struct {
// contains filtered or unexported fields
}
func NewAuthentication ¶ added in v0.0.15
func NewAuthentication(dojo *Dojo) *Authentication
func (Authentication) CompareOAuthState ¶ added in v0.0.15
func (auth Authentication) CompareOAuthState(ctx Context, state string) error
func (Authentication) ComparePasswordAndHash ¶ added in v0.0.15
func (auth Authentication) ComparePasswordAndHash(password, hash string) (match bool, err error)
func (*Authentication) ExchangeAuthorisationCode ¶ added in v0.0.15
func (auth *Authentication) ExchangeAuthorisationCode(ctx Context, authorisationCode string) (OAuthResult, error)
func (Authentication) GeneratePasswordHash ¶ added in v0.0.15
func (auth Authentication) GeneratePasswordHash(c *PasswordConfig, password string) (string, error)
func (*Authentication) GetAuthUser ¶ added in v0.0.15
func (auth *Authentication) GetAuthUser(ctx Context) AuthUser
func (*Authentication) GetAuthorizationUri ¶ added in v0.0.15
func (auth *Authentication) GetAuthorizationUri(ctx Context) string
func (*Authentication) Login ¶ added in v0.0.25
func (auth *Authentication) Login(ctx Context, user Authenticable) error
func (*Authentication) Logout ¶ added in v0.0.32
func (auth *Authentication) Logout(ctx Context) error
type AuthenticationConfig ¶ added in v0.0.15
type AuthenticationConfig struct { Provider AuthenticationProvider // The Configuration for the database provider Table string `json:"table"` // The Configuration for the oauth provider Endpoint string `json:"endpoint" yaml:"endpoint"` ClientID string `json:"clientId" yaml:"client_id"` ClientSecret string `json:"clientSecret" yaml:"client_secret"` Scopes []string `json:"scopes" yaml:"scopes"` RedirectPath string `json:"redirectPath" yaml:"redirect_path"` }
type AuthenticationProvider ¶ added in v0.0.15
type AuthenticationProvider string
const ( OAuthAuthenticationProvider AuthenticationProvider = "oauth" DatabaseAuthenticationProvider AuthenticationProvider = "database" )
type Context ¶
type Context interface { context.Context Response() http.ResponseWriter Request() *http.Request Session() *Session Cookies() *Cookies Dojo() *Dojo Params() ParamValues Param(string) string Set(string, interface{}) Bind(interface{}) error Data() map[string]interface{} JSON(code int, data interface{}) error NoContent(code int) error View(view string, data ViewAdditionalData) error RealIP() string }
type Cookies ¶ added in v0.0.20
type Cookies struct {
// contains filtered or unexported fields
}
Cookies allows you to easily get cookies from the request, and set cookies on the response.
func (*Cookies) Delete ¶ added in v0.0.20
Delete sets a header that tells the browser to remove the cookie with the given name.
func (*Cookies) Get ¶ added in v0.0.20
Get returns the value of the cookie with the given name. Returns http.ErrNoCookie if there's no cookie with that name in the request.
func (*Cookies) Set ¶ added in v0.0.20
Set a cookie on the response, which will expire after the given duration.
func (*Cookies) SetWithExpirationTime ¶ added in v0.0.20
SetWithExpirationTime sets a cookie that will expire at a specific time. Note that the time is determined by the client's browser, so it might not expire at the expected time, for example if the client has changed the time on their computer.
func (*Cookies) SetWithPath ¶ added in v0.0.20
SetWithPath sets a cookie path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain.
type DatabaseConfig ¶
type DatabaseConfig struct { Host string `json:"host" yaml:"host"` Port int `json:"port" yaml:"port"` User string `json:"user" yaml:"user"` Password string `json:"password" yaml:"password"` Database string `json:"database" yaml:"database"` SSLMode string `json:"ssl_mode" yaml:"ssl_mode"` }
func (DatabaseConfig) DSN ¶ added in v0.0.21
func (c DatabaseConfig) DSN() string
type DefaultConfiguration ¶
type DefaultConfiguration struct { App AppConfig `json:"dojo" yaml:"dojo"` DB DatabaseConfig `json:"db" yaml:"db"` View ViewConfig `json:"view" yaml:"view"` Assets AssetsConfigs `json:"assets" yaml:"assets"` Session SessionConfig `json:"session" yaml:"session"` Auth AuthenticationConfig `json:"auth" yaml:"auth"` Redis RedisConfig `json:"redis" yaml:"redis"` }
func GetConfig ¶ added in v0.0.21
func GetConfig() *DefaultConfiguration
func LoadConfigs ¶
func LoadConfigs(cfg *DefaultConfiguration) *DefaultConfiguration
type DefaultContext ¶ added in v0.0.4
func (*DefaultContext) Bind ¶ added in v0.0.20
func (ctx *DefaultContext) Bind(dst interface{}) error
func (*DefaultContext) Cookies ¶ added in v0.0.20
func (ctx *DefaultContext) Cookies() *Cookies
Cookies for the associated request and response.
func (*DefaultContext) Data ¶ added in v0.0.20
func (ctx *DefaultContext) Data() map[string]interface{}
func (*DefaultContext) Dojo ¶ added in v1.0.1
func (ctx *DefaultContext) Dojo() *Dojo
func (*DefaultContext) JSON ¶ added in v1.0.1
func (ctx *DefaultContext) JSON(code int, data interface{}) error
func (*DefaultContext) NoContent ¶ added in v1.0.1
func (ctx *DefaultContext) NoContent(code int) error
func (*DefaultContext) Param ¶ added in v0.0.20
func (ctx *DefaultContext) Param(key string) string
func (*DefaultContext) Params ¶ added in v0.0.4
func (ctx *DefaultContext) Params() ParamValues
func (*DefaultContext) RealIP ¶ added in v1.0.1
func (ctx *DefaultContext) RealIP() string
func (*DefaultContext) Request ¶ added in v0.0.4
func (ctx *DefaultContext) Request() *http.Request
Request returns the original Request.
func (*DefaultContext) Response ¶ added in v0.0.4
func (ctx *DefaultContext) Response() http.ResponseWriter
Response returns the original Response for the request.
func (*DefaultContext) Session ¶ added in v0.0.20
func (ctx *DefaultContext) Session() *Session
func (*DefaultContext) Set ¶ added in v0.0.20
func (ctx *DefaultContext) Set(key string, value interface{})
func (*DefaultContext) Value ¶ added in v0.0.20
func (ctx *DefaultContext) Value(key interface{}) interface{}
Value that has previously stored on the context.
func (*DefaultContext) View ¶ added in v1.0.1
func (ctx *DefaultContext) View(viewName string, data ViewAdditionalData) error
type Dojo ¶ added in v1.0.1
type Dojo struct { Configuration DefaultConfiguration MiddlewareRegistry *MiddlewareRegistry `json:"-"` Logger *logrus.Logger SessionStore *sessions.CookieStore HTTPErrorHandler HTTPErrorHandler Auth *Authentication Route *Router Debug bool }
func (*Dojo) DefaultHTTPErrorHandler ¶ added in v1.0.1
func (*Dojo) NewContext ¶ added in v1.0.1
func (dojo *Dojo) NewContext(rc RouteConfig, w http.ResponseWriter, r *http.Request) Context
type Environment ¶ added in v0.0.21
type Environment string
const ( Production Environment = "production" Development Environment = "development" Testing Environment = "testing" Staging Environment = "staging" )
type ExchangeAuthorisationCodeRequest ¶ added in v0.0.15
type FileExtension ¶ added in v0.0.6
type FileExtension string
const ( Javascript FileExtension = "js" Stylesheet FileExtension = "css" )
type HTTPError ¶ added in v1.0.1
type HTTPError struct { Code int `json:"-"` Message interface{} `json:"message"` Internal error `json:"-"` }
HTTPError represents an error that occurred while handling a request.
func NewHTTPError ¶ added in v1.0.1
type HTTPErrorHandler ¶ added in v1.0.1
type JsonResponseBody ¶ added in v0.0.15
type JsonResponseBody struct {
Data interface{} `json:"data"`
}
type Middleware ¶ added in v0.0.15
type Middleware struct { Name string Handler MiddlewareFunc }
type MiddlewareFunc ¶ added in v0.0.4
type MiddlewareRegistry ¶ added in v0.0.15
type MiddlewareRegistry struct {
// contains filtered or unexported fields
}
func NewMiddlewareRegistry ¶ added in v0.0.15
func NewMiddlewareRegistry() *MiddlewareRegistry
func (*MiddlewareRegistry) Register ¶ added in v0.0.15
func (registry *MiddlewareRegistry) Register(name string, fn MiddlewareFunc)
func (*MiddlewareRegistry) RegisterStack ¶ added in v0.0.15
func (registry *MiddlewareRegistry) RegisterStack(name string, middlewares []string)
type MiddlewareStack ¶ added in v0.0.4
type MiddlewareStack struct {
// contains filtered or unexported fields
}
func (*MiddlewareStack) Use ¶ added in v0.0.4
func (ms *MiddlewareStack) Use(mw ...MiddlewareFunc)
type OAuthResult ¶ added in v0.0.15
type ParamValues ¶ added in v0.0.4
type PasswordConfig ¶ added in v0.0.15
type RedisConfig ¶ added in v1.0.2
type RouteConfig ¶ added in v0.0.4
type RouteConfig struct { Method string `json:"method"` Path string `json:"path"` HandlerName string `json:"handler"` ResourceName string `json:"resourceName,omitempty"` PathName string `json:"pathName"` Aliases []string `json:"aliases"` MuxRoute *mux.Route `json:"-"` Handler Handler `json:"-"` Dojo *Dojo `json:"-"` Middlewares MiddlewareStack `json:"-"` }
func (RouteConfig) ServeHTTP ¶ added in v0.0.4
func (r RouteConfig) ServeHTTP(res http.ResponseWriter, req *http.Request)
type Router ¶ added in v0.0.15
type Router struct {
// contains filtered or unexported fields
}
func (*Router) Connect ¶ added in v0.0.16
func (r *Router) Connect(path string, handler Handler, middlewares ...MiddlewareFunc)
func (*Router) Delete ¶ added in v0.0.16
func (r *Router) Delete(path string, handler Handler, middlewares ...MiddlewareFunc)
func (*Router) DeleteWithName ¶ added in v1.0.1
func (r *Router) DeleteWithName(path string, name string, handler Handler, middlewares ...MiddlewareFunc)
func (*Router) Get ¶ added in v0.0.15
func (r *Router) Get(path string, handler Handler, middlewares ...MiddlewareFunc)
func (*Router) GetWithName ¶ added in v1.0.1
func (r *Router) GetWithName(path string, name string, handler Handler, middlewares ...MiddlewareFunc)
func (*Router) Options ¶ added in v0.0.16
func (r *Router) Options(path string, handler Handler, middlewares ...MiddlewareFunc)
func (*Router) Patch ¶ added in v0.0.16
func (r *Router) Patch(path string, handler Handler, middlewares ...MiddlewareFunc)
func (*Router) PatchWithName ¶ added in v1.0.1
func (r *Router) PatchWithName(path string, name string, handler Handler, middlewares ...MiddlewareFunc)
func (*Router) Post ¶ added in v0.0.16
func (r *Router) Post(path string, handler Handler, middlewares ...MiddlewareFunc)
func (*Router) PostWithName ¶ added in v1.0.1
func (r *Router) PostWithName(path string, name string, handler Handler, middlewares ...MiddlewareFunc)
func (*Router) Put ¶ added in v0.0.16
func (r *Router) Put(path string, handler Handler, middlewares ...MiddlewareFunc)
func (*Router) PutWithName ¶ added in v1.0.1
func (r *Router) PutWithName(path string, name string, handler Handler, middlewares ...MiddlewareFunc)
func (*Router) RouteGroup ¶ added in v0.0.15
func (*Router) Trace ¶ added in v0.0.16
func (r *Router) Trace(path string, handler Handler, middlewares ...MiddlewareFunc)
type SessionConfig ¶ added in v0.0.15
type ViewAdditionalData ¶ added in v0.0.30
type ViewAdditionalData map[string]interface{}
type ViewConfig ¶ added in v0.0.4
type ViewConfig struct {
Path string `json:"path" yaml:"path"`
}
type ViewData ¶ added in v0.0.4
type ViewData struct { Assets []Asset User Authenticable Data map[string]interface{} }