api

package
v2.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package api provides common api functionality

Index

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

func StripPrefix added in v2.0.37

func StripPrefix(prefix string, h http.Handler) http.Handler

StripPrefix works like go http.StripPrefix, but update the RequestURI as well

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

type Interface added in v2.0.34

type Interface interface {
	// Handler initializes and returns the http handler for the api
	Handler() http.Handler

	// Name returns the api name
	Name() string
}

Interface is the common api interface

Jump to

Keyboard shortcuts

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