dojo

package module
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: MIT Imports: 28 Imported by: 0

README

Dojo | Framework

Documentation

Index

Constants

This section is empty.

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 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"`
	Version     string `json:"version"`
	Port        int    `json:"port"`
	Environment string `json:"environment"`
	Domain      string `json:"domain"`
}

type Application

type Application struct {
	Configuration      DefaultConfiguration
	MiddlewareRegistry *MiddlewareRegistry `json:"-"`
	Logger             *logrus.Logger
	SessionStore       *sessions.CookieStore
	Auth               *Authentication
	Route              *Router
}

func New

New creates a new instance of Application

func (*Application) Assets added in v0.0.6

func (app *Application) Assets() []Asset

func (Application) JSON added in v0.0.15

func (app Application) JSON(ctx Context, data interface{}) error

func (Application) NewContext added in v0.0.4

func (app Application) NewContext(rc RouteConfig, w http.ResponseWriter, r *http.Request) Context

func (*Application) Serve

func (app *Application) Serve()

func (Application) View added in v0.0.4

func (app Application) View(ctx Context, viewName string, data ViewData) error

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"`
}

type AuthUser added in v0.0.15

type AuthUser struct {
	Type AuthUserType
	Data interface{}
}

type AuthUserType added in v0.0.15

type AuthUserType string
const (
	GuestUserType AuthUserType = "guest"
	UserUserType  AuthUserType = "user"
)

type Authentication added in v0.0.15

type Authentication struct {
	// contains filtered or unexported fields
}

func NewAuthentication added in v0.0.15

func NewAuthentication(app *Application) *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

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"`
	ClientID     string   `json:"clientId"`
	ClientSecret string   `json:"clientSecret"`
	Scopes       []string `json:"scopes"`
	RedirectPath string   `json:"redirectPath"`
}

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
	Params() ParamValues
	Param(string) string
	Bind(interface{}) error
	Data() map[string]interface{}
}

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"`
	Port     int    `json:"port"`
	User     string `json:"user"`
	Password string `json:"password"`
	Database string `json:"database"`
}

type DefaultConfiguration

type DefaultConfiguration struct {
	App     AppConfig            `yaml:"app"`
	DB      DatabaseConfig       `yaml:"db"`
	View    ViewConfig           `yaml:"view"`
	Assets  AssetsConfigs        `yaml:"assets"`
	Session SessionConfig        `yaml:"session"`
	Auth    AuthenticationConfig `yaml:"auth"`
}

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 (d *DefaultContext) Bind(dst interface{}) error

func (*DefaultContext) Cookies added in v0.0.20

func (d *DefaultContext) Cookies() *Cookies

Cookies for the associated request and response.

func (*DefaultContext) Data added in v0.0.20

func (d *DefaultContext) Data() map[string]interface{}

func (*DefaultContext) Flash added in v0.0.20

func (d *DefaultContext) Flash() *Flash

Flash messages for the associated Request.

func (*DefaultContext) Param added in v0.0.20

func (d *DefaultContext) Param(key string) string

func (*DefaultContext) Params added in v0.0.4

func (d *DefaultContext) Params() ParamValues

func (*DefaultContext) Request added in v0.0.4

func (d *DefaultContext) Request() *http.Request

Request returns the original Request.

func (*DefaultContext) Response added in v0.0.4

func (d *DefaultContext) Response() http.ResponseWriter

Response returns the original Response for the request.

func (*DefaultContext) Session added in v0.0.20

func (d *DefaultContext) Session() *Session

func (*DefaultContext) Set added in v0.0.20

func (d *DefaultContext) Set(key string, value interface{})

func (*DefaultContext) Value added in v0.0.20

func (d *DefaultContext) Value(key interface{}) interface{}

Value that has previously stored on the context.

type ExchangeAuthorisationCodeRequest added in v0.0.15

type ExchangeAuthorisationCodeRequest struct {
	GrantType    string
	ClientId     string
	ClientSecret string
	RedirectUri  string
	Code         string
}

type FileExtension added in v0.0.6

type FileExtension string
const (
	Javascript FileExtension = "js"
	Stylesheet FileExtension = "css"
)

type Flash added in v0.0.20

type Flash struct {
	// contains filtered or unexported fields
}

Flash is a struct that helps with the operations over flash messages.

func (Flash) Add added in v0.0.20

func (f Flash) Add(key, value string)

Add adds a flash value for a flash key, if the key already has values the list for that value grows.

func (*Flash) Clear added in v0.0.20

func (f *Flash) Clear()

Clear removes all keys from the Flash.

func (Flash) Delete added in v0.0.20

func (f Flash) Delete(key string)

Delete removes a particular key from the Flash.

func (Flash) Set added in v0.0.20

func (f Flash) Set(key string, values []string)

Set allows to set a list of values into a particular key.

type Handler

type Handler func(Context, *Application) error

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 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 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:"-"`
	App          *Application    `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(app *Application) *Router

func (*Router) Connect added in v0.0.16

func (r *Router) Connect(path string, handler Handler)

func (*Router) Delete added in v0.0.16

func (r *Router) Delete(path string, handler Handler)

func (*Router) Get added in v0.0.15

func (r *Router) Get(path string, handler Handler)

func (*Router) GetMux added in v0.0.15

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

func (*Router) Options added in v0.0.16

func (r *Router) Options(path string, handler Handler)

func (*Router) Patch added in v0.0.16

func (r *Router) Patch(path string, handler Handler)

func (*Router) Post added in v0.0.16

func (r *Router) Post(path string, handler Handler)

func (*Router) Put added in v0.0.16

func (r *Router) Put(path string, handler Handler)

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)

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

func (s *Session) Get(name interface{}) 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{})

type SessionConfig added in v0.0.15

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

type ViewConfig added in v0.0.4

type ViewConfig struct {
	Path string `json:"path"`
}

type ViewData added in v0.0.4

type ViewData 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