Documentation ¶
Overview ¶
Package api provides common api functionality
Index ¶
- Variables
- func StripPrefix(prefix string, h http.Handler) http.Handler
- type Authorizer
- type Controller
- type DefaultController
- func (c *DefaultController) Authorizer() Authorizer
- func (c *DefaultController) DB() *sql.DB
- func (c *DefaultController) Log() *logrus.Logger
- func (c *DefaultController) Options() *jsondb.DB
- func (c *DefaultController) SetAuthorizer(a Authorizer) *DefaultController
- func (c *DefaultController) SetLog(log *logrus.Logger)
- type Interface
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrAccessDenied is a common api error with HTTP 404 and access denied reason ErrAccessDenied = types.ErrNotAuthorized.Reason(keychain.ErrAccessDenied) )
Functions ¶
Types ¶
type Authorizer ¶
type Authorizer interface { // AuthBasic handles basic authentication AuthBasic(user string, pass string) (interface{}, error) // AuthToken handles simple token or api key or token authentication AuthToken(token string) (interface{}, error) // AuthOauth handles Oauth 2.0 token authorization AuthOauth(token string, scopes []string) (interface{}, error) }
Authorizer is an api authorization interface
func AllowAuthorizer ¶ added in v2.0.38
func AllowAuthorizer() Authorizer
AllowAuthorizer allows all traffic by default, but will perform weak validation of tokens
func DenyAuthorizer ¶ added in v2.0.38
func DenyAuthorizer() Authorizer
DenyAuthorizer denies all traffic
type Controller ¶
type Controller interface { // DB returns the application database instance DB() *sql.DB // Options returns the application kvdb Options() *jsondb.DB // Authorizer returns the application api method authorizer Authorizer() Authorizer // Log returns the logger for the api Log() *logrus.Logger }
Controller provides basic functions to an api library
type DefaultController ¶ added in v2.0.38
type DefaultController struct {
// contains filtered or unexported fields
}
DefaultController provides basic default function for apis
func NewDefaultController ¶ added in v2.0.38
func NewDefaultController(db *sql.DB, options *jsondb.DB, auth ...Authorizer) *DefaultController
NewDefaultController returns a default controller
func (*DefaultController) Authorizer ¶ added in v2.0.38
func (c *DefaultController) Authorizer() Authorizer
Authorizer implements the Controller.Authorizer method
func (*DefaultController) DB ¶ added in v2.0.38
func (c *DefaultController) DB() *sql.DB
DB implements the Controller.DB method
func (*DefaultController) Log ¶ added in v2.1.2
func (c *DefaultController) Log() *logrus.Logger
Log implements the Controller.Log method
func (*DefaultController) Options ¶ added in v2.0.38
func (c *DefaultController) Options() *jsondb.DB
Options implements the Controller.Options method
func (*DefaultController) SetAuthorizer ¶ added in v2.0.38
func (c *DefaultController) SetAuthorizer(a Authorizer) *DefaultController
SetAuthorizer sets the Authorizer for the controller
func (*DefaultController) SetLog ¶ added in v2.1.2
func (c *DefaultController) SetLog(log *logrus.Logger)
SetLog sets the logger
Click to show internal directories.
Click to hide internal directories.