dojo

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2021 License: MIT Imports: 33 Imported by: 0

README

Dojo | Framework

Documentation

Index

Constants

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

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

View Source
const FlashOldKey = "_old_inputs"

Variables

View Source
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")
)
View Source
var (
	ErrUnsupportedMediaType        = NewHTTPError(http.StatusUnsupportedMediaType)
	ErrNotFound                    = NewHTTPError(http.StatusNotFound)
	ErrUnauthorized                = NewHTTPError(http.StatusUnauthorized)
	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)
	ErrServiceUnavailable          = NewHTTPError(http.StatusServiceUnavailable)
	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")
)
View Source
var DefaultConfigs = &PasswordConfig{
	Memory:      64 * 1024,
	Iterations:  1,
	Parallelism: 2,
	SaltLength:  16,
	KeyLength:   32,
}

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	Name        string      `json:"name" yaml:"name"`
	Version     string      `json:"version" yaml:"version"`
	Port        int         `json:"port" yaml:"port"`
	Environment Environment `json:"environment" yaml:"environment"`
	Domain      string      `json:"domain" yaml:"domain"`
	Debug       bool        `json:"debug" yaml:"debug"`
}

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

type AuthUser struct {
	ID   uuid.UUID
	Data interface{}
}

func (*AuthUser) GetAuthData added in v0.0.25

func (u *AuthUser) GetAuthData() interface{}

func (*AuthUser) GetAuthID added in v0.0.25

func (u *AuthUser) GetAuthID() uuid.UUID

func (*AuthUser) GetAuthType added in v0.0.25

func (u *AuthUser) GetAuthType() AuthUserType

func (*AuthUser) IsGuest added in v0.0.30

func (u *AuthUser) IsGuest() bool

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

func (c *Cookies) Delete(name string)

Delete sets a header that tells the browser to remove the cookie with the given name.

func (*Cookies) Get added in v0.0.20

func (c *Cookies) Get(name string) (string, error)

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

func (c *Cookies) Set(name, value string, maxAge time.Duration)

Set a cookie on the response, which will expire after the given duration.

func (*Cookies) SetWithExpirationTime added in v0.0.20

func (c *Cookies) SetWithExpirationTime(name, value string, expires time.Time)

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

func (c *Cookies) SetWithPath(name, value, path string)

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

type DefaultContext added in v0.0.4

type DefaultContext struct {
	context.Context
	// contains filtered or unexported fields
}

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 New

func New(conf DefaultConfiguration) *Dojo

New creates a new instance of Application

func (*Dojo) Assets added in v1.0.1

func (dojo *Dojo) Assets() []Asset

func (*Dojo) DefaultHTTPErrorHandler added in v1.0.1

func (dojo *Dojo) DefaultHTTPErrorHandler(err error, c Context)

func (*Dojo) NewContext added in v1.0.1

func (dojo *Dojo) NewContext(rc RouteConfig, w http.ResponseWriter, r *http.Request) Context

func (*Dojo) Serve added in v1.0.1

func (dojo *Dojo) Serve()

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 ExchangeAuthorisationCodeRequest struct {
	GrantType    string `json:"grant_type"`
	ClientId     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	RedirectUri  string `json:"redirect_uri"`
	Code         string `json:"code"`
}

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

func NewHTTPError(code int, message ...interface{}) *HTTPError

func (*HTTPError) Error added in v1.0.1

func (e *HTTPError) Error() string

type HTTPErrorHandler added in v1.0.1

type HTTPErrorHandler func(error, Context)

type Handler

type Handler func(Context) error

type JsonResponseBody added in v0.0.15

type JsonResponseBody struct {
	Data interface{} `json:"data"`
}

type Map added in v1.0.1

type Map map[string]interface{}

type Middleware added in v0.0.15

type Middleware struct {
	Name    string
	Handler MiddlewareFunc
}

type MiddlewareFunc added in v0.0.4

type MiddlewareFunc func(Handler) Handler

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 OAuthResult struct {
	TokenType    string `json:"token_type"`
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int    `json:"expires_at"`
	Scope        string `json:"scope"`
}

type ParamValues added in v0.0.4

type ParamValues interface {
	Get(string) string
}

type PasswordConfig added in v0.0.15

type PasswordConfig struct {
	Memory      uint32
	Iterations  uint32
	Parallelism uint8
	SaltLength  uint32
	KeyLength   uint32
}

type RedisConfig added in v1.0.2

type RedisConfig struct {
	Host     string `json:"host" yaml:"host"`
	Password string `json:"password" yaml:"password"`
	Database int    `json:"database" yaml:"database"`
	Port     int    `json:"port" yaml:"port"`
}

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 NewRouter added in v0.0.15

func NewRouter(dojo *Dojo) *Router

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) GetMux added in v0.0.15

func (r *Router) GetMux() *mux.Router

func (*Router) GetWithName added in v1.0.1

func (r *Router) GetWithName(path string, name string, handler Handler, middlewares ...MiddlewareFunc)

func (*Router) Host added in v1.0.5

func (r *Router) Host(tpl string, cb func(router *Router))

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) Redirect added in v0.0.25

func (r Router) Redirect(ctx Context, url string)

func (*Router) RouteGroup added in v0.0.15

func (r *Router) RouteGroup(prefix string, cb func(router *Router))

func (*Router) Trace added in v0.0.16

func (r *Router) Trace(path string, handler Handler, middlewares ...MiddlewareFunc)

func (*Router) Use added in v0.0.15

func (r *Router) Use(name string)

Use a registered middleware on that router

func (*Router) UseStack added in v0.0.15

func (r *Router) UseStack(name string)

type Session added in v0.0.15

type Session struct {
	Session *sessions.Session
	// contains filtered or unexported fields
}

func (*Session) Clear added in v0.0.15

func (s *Session) Clear()

func (*Session) Delete added in v0.0.15

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

func (*Session) Flash added in v1.0.1

func (s *Session) Flash(key string, value interface{})

func (*Session) Get added in v0.0.15

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

func (*Session) GetFlash added in v1.0.1

func (s *Session) GetFlash(key string) []interface{}

func (*Session) GetOnce added in v0.0.15

func (s *Session) GetOnce(name interface{}) interface{}

func (*Session) Save added in v0.0.15

func (s *Session) Save() error

func (*Session) Set added in v0.0.15

func (s *Session) Set(name, value interface{})

func (*Session) WithOld added in v1.0.1

func (s *Session) WithOld(data map[string]interface{})

type SessionConfig added in v0.0.15

type SessionConfig struct {
	Name   string `json:"name" yaml:"name"`
	Secret string `json:"secret" yaml:"secret"`
}

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{}
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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