web

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2018 License: GPL-3.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const CookieAuthName = "auth"

CookieAuthName is the name of the cookie that holds the Authentication Token

View Source
const CookieOAuthIdentifier = "__oauth_identifier"

CookieOAuthIdentifier is the name of the cookie that holds the temporary OAuth identifier string

View Source
const CookieSignUpAuthName = "__signup_auth"

CookieSignUpAuthName is the name of the cookie that holds the temporary Authentication Token

Variables

View Source
var (
	PlainContentType     = "text/plain"
	HTMLContentType      = "text/html"
	JSONContentType      = "application/json"
	UTF8PlainContentType = PlainContentType + "; charset=utf-8"
	UTF8HTMLContentType  = HTMLContentType + "; charset=utf-8"
	UTF8JSONContentType  = JSONContentType + "; charset=utf-8"
)

HTMLMimeType is the mimetype for HTML responses

View Source
var (

	//CspPolicyTemplate is the template used to generate the policy
	CspPolicyTemplate = fmt.Sprintf("%s; %s; %s; %s; %s; %s; %s; %s; %s", cspBase, cspDefault, cspStyle, cspScript, cspImage, cspFont, cspObject, cspMedia, cspConnect)
)
View Source
var (
	//ErrContentTypeNotAllowed is used when POSTing a body that is not json
	ErrContentTypeNotAllowed = stdErrors.New("Only Content-Type application/json is allowed")
)

Functions

func ParseCookie added in v0.15.0

func ParseCookie(s string) *http.Cookie

ParseCookie return a list of cookie parsed from raw Set-Cookie

Types

type CertificateManager added in v0.7.0

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

CertificateManager is used to manage SSL certificates

func NewCertificateManager added in v0.7.0

func NewCertificateManager(certFile, keyFile, cacheDir string) (*CertificateManager, error)

NewCertificateManager creates a new CertificateManager

func (*CertificateManager) GetCertificate added in v0.7.0

func (m *CertificateManager) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error)

GetCertificate decides which certificate to use It first tries to use loaded certificate for incoming request if it's compatible Otherwise fallsback to a automatically generated certificate by Let's Encrypt

func (*CertificateManager) StartHTTPServer added in v0.9.0

func (m *CertificateManager) StartHTTPServer()

StartHTTPServer creates a new HTTP server on port 80 that is used for the ACME HTTP Challenge

type Client added in v0.14.0

type Client interface {
	Do(req *http.Request) (*http.Response, error)
}

Client is an interface for HTTP Client

type Context

type Context struct {
	Response http.ResponseWriter
	Request  Request
	// contains filtered or unexported fields
}

Context shared between http pipeline

func (*Context) ActiveTransaction

func (ctx *Context) ActiveTransaction() *dbx.Trx

ActiveTransaction returns current active Database transaction

func (*Context) AddCookie added in v0.6.0

func (ctx *Context) AddCookie(name, value string, expires time.Time)

AddCookie adds a cookie

func (*Context) AddParam added in v0.7.0

func (ctx *Context) AddParam(name, value string)

AddParam add a single param to route parameters list

func (*Context) Attachment added in v0.12.0

func (ctx *Context) Attachment(fileName, contentType string, file []byte) error

Attachment returns an attached file

func (*Context) BadRequest

func (ctx *Context) BadRequest(dict Map) error

BadRequest returns 400 BadRequest with JSON result

func (*Context) BaseURL

func (ctx *Context) BaseURL() string

BaseURL returns base URL

func (*Context) BindTo added in v0.4.0

func (ctx *Context) BindTo(i actions.Actionable) *validate.Result

BindTo context values into given model

func (*Context) Blob added in v0.7.0

func (ctx *Context) Blob(code int, contentType string, b []byte) error

Blob sends a blob response with status code and content type.

func (*Context) Claims added in v0.15.0

func (ctx *Context) Claims() *jwt.FiderClaims

Claims returns current user claims

func (*Context) Commit added in v0.11.0

func (ctx *Context) Commit() error

Commit everything that is pending on current context

func (*Context) ContextID added in v0.12.0

func (ctx *Context) ContextID() string

ContextID returns the unique id for this context

func (*Context) Engine added in v0.10.0

func (ctx *Context) Engine() *Engine

Engine returns main HTTP engine

func (*Context) Enqueue added in v0.10.0

func (ctx *Context) Enqueue(task worker.Task)

Enqueue given task to be processed in background

func (*Context) Failure

func (ctx *Context) Failure(err error) error

Failure returns a 500 page

func (Context) FaviconURL added in v0.15.0

func (ctx Context) FaviconURL() string

FaviconURL return the full URL to the tenant-specific favicon URL

func (*Context) Get added in v0.7.0

func (ctx *Context) Get(key string) interface{}

Get retrieves data from the context.

func (*Context) GlobalAssetsURL added in v0.14.0

func (ctx *Context) GlobalAssetsURL(path string, a ...interface{}) string

GlobalAssetsURL return the full URL to a globally shared static asset

func (*Context) Gone added in v0.12.0

func (ctx *Context) Gone() error

Gone returns a 410 page

func (*Context) HandleValidation added in v0.4.0

func (ctx *Context) HandleValidation(result *validate.Result) error

HandleValidation handles given validation result property to return 400 or 500

func (*Context) IsAjax

func (ctx *Context) IsAjax() bool

IsAjax returns true if request is AJAX

func (*Context) IsAuthenticated

func (ctx *Context) IsAuthenticated() bool

IsAuthenticated returns true if user is authenticated

func (*Context) JSON added in v0.7.0

func (ctx *Context) JSON(code int, i interface{}) error

JSON returns a JSON response with status code.

func (*Context) Logger added in v0.7.0

func (ctx *Context) Logger() log.Logger

Logger returns current logger

func (Context) LogoURL added in v0.15.0

func (ctx Context) LogoURL() string

LogoURL return the full URL to the tenant-specific logo URL

func (*Context) NoContent added in v0.7.0

func (ctx *Context) NoContent(code int) error

NoContent sends a response with no body and a status code.

func (*Context) NotFound

func (ctx *Context) NotFound() error

NotFound returns a 404 page

func (*Context) Ok

func (ctx *Context) Ok(data interface{}) error

Ok returns 200 OK with JSON result

func (*Context) Page

func (ctx *Context) Page(props Props) error

Page returns a page with given variables

func (*Context) Param added in v0.7.0

func (ctx *Context) Param(name string) string

Param returns parameter as string

func (*Context) ParamAsInt

func (ctx *Context) ParamAsInt(name string) (int, error)

ParamAsInt returns parameter as int

func (*Context) QueryParam added in v0.7.0

func (ctx *Context) QueryParam(key string) string

QueryParam returns querystring parameter for given key

func (*Context) QueryParamAsArray added in v0.10.0

func (ctx *Context) QueryParamAsArray(key string) []string

QueryParamAsArray returns querystring parameter for given key as an array

func (*Context) Redirect added in v0.7.0

func (ctx *Context) Redirect(url string) error

Redirect the request to a provided URL

func (*Context) RemoveCookie added in v0.6.0

func (ctx *Context) RemoveCookie(name string)

RemoveCookie removes a cookie

func (*Context) Render added in v0.7.0

func (ctx *Context) Render(code int, template string, props Props) error

Render renders a template with data and sends a text/html response with status

func (*Context) Rollback added in v0.11.0

func (ctx *Context) Rollback() error

Rollback everything that is pending on current context

func (*Context) Services

func (ctx *Context) Services() *app.Services

Services returns current app.Services from context

func (*Context) Set added in v0.7.0

func (ctx *Context) Set(key string, val interface{})

Set saves data in the context.

func (*Context) SetActiveTransaction

func (ctx *Context) SetActiveTransaction(trx *dbx.Trx)

SetActiveTransaction adds transaction to context

func (*Context) SetClaims added in v0.15.0

func (ctx *Context) SetClaims(claims *jwt.FiderClaims)

SetClaims update HTTP context with current user claims

func (*Context) SetServices

func (ctx *Context) SetServices(services *app.Services)

SetServices update current context with app.Services

func (*Context) SetTenant

func (ctx *Context) SetTenant(tenant *models.Tenant)

SetTenant update HTTP context with current tenant

func (*Context) SetUser

func (ctx *Context) SetUser(user *models.User)

SetUser update HTTP context with current user

func (*Context) String added in v0.7.0

func (ctx *Context) String(code int, text string) error

String returns a text response with status code.

func (Context) Tenant

func (ctx Context) Tenant() *models.Tenant

Tenant returns current tenant

func (*Context) TenantAssetsURL added in v0.14.0

func (ctx *Context) TenantAssetsURL(path string, a ...interface{}) string

TenantAssetsURL return the full URL to a tenant-specific static asset

func (*Context) TenantBaseURL added in v0.6.0

func (ctx *Context) TenantBaseURL(tenant *models.Tenant) string

TenantBaseURL returns base URL for a given tenant

func (*Context) Unauthorized added in v0.4.0

func (ctx *Context) Unauthorized() error

Unauthorized returns a 403 response

func (*Context) User

func (ctx *Context) User() *models.User

User returns authenticated user

type DefaultBinder added in v0.7.0

type DefaultBinder struct {
}

DefaultBinder is the default HTTP binder

func NewDefaultBinder added in v0.7.0

func NewDefaultBinder() *DefaultBinder

NewDefaultBinder creates a new default binder

func (*DefaultBinder) Bind added in v0.7.0

func (b *DefaultBinder) Bind(target interface{}, c *Context) error

Bind request data to object i

type Engine

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

Engine is our web engine wrapper

func New

func New(settings *models.SystemSettings) *Engine

New creates a new Engine

func (*Engine) Database added in v0.14.0

func (e *Engine) Database() *dbx.Database

Database returns current database

func (*Engine) Delete added in v0.15.0

func (e *Engine) Delete(path string, handler HandlerFunc)

Delete handles HTTP DELETE requests

func (*Engine) Get added in v0.15.0

func (e *Engine) Get(path string, handler HandlerFunc)

Get handles HTTP GET requests

func (*Engine) Group

func (e *Engine) Group() *Group

Group creates a new route group

func (*Engine) Logger

func (e *Engine) Logger() log.Logger

Logger returns current logger

func (*Engine) NewContext

func (e *Engine) NewContext(res http.ResponseWriter, req *http.Request, params StringMap) Context

NewContext creates and return a new context

func (*Engine) Post added in v0.15.0

func (e *Engine) Post(path string, handler HandlerFunc)

Post handles HTTP POST requests

func (*Engine) Put added in v0.15.0

func (e *Engine) Put(path string, handler HandlerFunc)

Put handles HTTP PUT requests

func (*Engine) Start

func (e *Engine) Start(address string)

Start the server.

func (*Engine) Stop added in v0.13.0

func (e *Engine) Stop() error

Stop the server.

func (*Engine) Use

func (e *Engine) Use(middleware MiddlewareFunc)

Use adds a middleware to the root engine

func (*Engine) Worker added in v0.10.0

func (e *Engine) Worker() worker.Worker

Worker returns current worker referenc

type Group

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

Group is our router group wrapper

func (*Group) Delete added in v0.8.0

func (g *Group) Delete(path string, handler HandlerFunc)

Delete handles HTTP DELETE requests

func (*Group) Get

func (g *Group) Get(path string, handler HandlerFunc)

Get handles HTTP GET requests

func (*Group) Group

func (g *Group) Group() *Group

Group creates a new route group

func (*Group) Post

func (g *Group) Post(path string, handler HandlerFunc)

Post handles HTTP POST requests

func (*Group) Put added in v0.15.0

func (g *Group) Put(path string, handler HandlerFunc)

Put handles HTTP PUT requests

func (*Group) Static

func (g *Group) Static(prefix, root string)

Static return files from given folder

func (*Group) Use

func (g *Group) Use(middleware MiddlewareFunc)

Use adds a middleware to current route stack

type HTTPClient added in v0.14.0

type HTTPClient struct {
}

HTTPClient is an implementation of HTTP Client

func NewHTTPClient added in v0.14.0

func NewHTTPClient() *HTTPClient

NewHTTPClient creates a new HTTPClient

func (*HTTPClient) Do added in v0.14.0

func (client *HTTPClient) Do(req *http.Request) (*http.Response, error)

Do sends the request using http.DefaultClient

type HandlerFunc

type HandlerFunc func(Context) error

HandlerFunc represents an HTTP handler

type Map added in v0.4.0

type Map map[string]interface{}

Map defines a generic map of type `map[string]interface{}`

type MiddlewareFunc

type MiddlewareFunc func(HandlerFunc) HandlerFunc

MiddlewareFunc represents an HTTP middleware

type OAuthService added in v0.15.0

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

OAuthService implements real OAuth operations using Golang's oauth2 package

func NewOAuthService added in v0.15.0

func NewOAuthService(oauthBaseURL string, tenantStorage storage.Tenant) *OAuthService

NewOAuthService creates a new OAuthService

func (*OAuthService) GetAuthURL added in v0.15.0

func (s *OAuthService) GetAuthURL(provider, redirect, identifier string) (string, error)

GetAuthURL returns authentication url for given provider

func (*OAuthService) GetProfile added in v0.15.0

func (s *OAuthService) GetProfile(provider string, code string) (*oauth.UserProfile, error)

GetProfile returns user profile based on provider (only if enabled) and code

func (*OAuthService) GetRawProfile added in v0.15.0

func (s *OAuthService) GetRawProfile(provider string, code string) (string, error)

GetRawProfile returns raw JSON response from Profile API

func (*OAuthService) ListActiveProviders added in v0.15.0

func (s *OAuthService) ListActiveProviders() ([]*oauth.ProviderOption, error)

ListActiveProviders returns a list of all enabled providers for current tenant

func (*OAuthService) ListAllProviders added in v0.15.0

func (s *OAuthService) ListAllProviders() ([]*oauth.ProviderOption, error)

ListAllProviders returns a list of all providers for current tenant

func (*OAuthService) ParseRawProfile added in v0.15.0

func (s *OAuthService) ParseRawProfile(provider, body string) (*oauth.UserProfile, error)

ParseRawProfile parses raw profile response into UserProfile model

type Props added in v0.13.0

type Props struct {
	Title       string
	Description string
	Data        Map
}

Props defines the data required to rende rages

type Renderer added in v0.7.0

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

Renderer is the default HTML Render

func NewRenderer added in v0.7.0

func NewRenderer(settings *models.SystemSettings, logger log.Logger) *Renderer

NewRenderer creates a new Renderer

func (*Renderer) Render added in v0.7.0

func (r *Renderer) Render(w io.Writer, name string, props Props, ctx *Context)

Render a template based on parameters

type Request added in v0.14.0

type Request struct {
	Method        string
	ContentLength int64
	Body          string
	IsSecure      bool
	URL           *url.URL
	// contains filtered or unexported fields
}

Request wraps the http request object

func WrapRequest added in v0.14.0

func WrapRequest(request *http.Request) Request

WrapRequest returns Fider wrapper of HTTP Request

func (*Request) AddCookie added in v0.14.0

func (r *Request) AddCookie(cookie *http.Cookie)

AddCookie adds a cookie

func (*Request) Cookie added in v0.14.0

func (r *Request) Cookie(name string) (*http.Cookie, error)

Cookie returns the named cookie provided in the request.

func (*Request) GetHeader added in v0.14.0

func (r *Request) GetHeader(key string) string

GetHeader returns the value of HTTP header from given key

func (*Request) IsAPI added in v0.15.0

func (r *Request) IsAPI() bool

IsAPI returns true if its a request for an API resource

func (*Request) SetHeader added in v0.14.0

func (r *Request) SetHeader(key, value string)

SetHeader updates the value of HTTP header of given key

type StringMap added in v0.7.0

type StringMap map[string]string

StringMap defines a map of type `map[string]string`

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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