server

package module
v0.0.0-...-ca4c118 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrBadRequest

func ErrBadRequest(c echo.Context, err error) error

ErrBadRequest response.

func ErrConflict

func ErrConflict(c echo.Context, err error) error

ErrConflict response.

func ErrEntityTooLarge

func ErrEntityTooLarge(c echo.Context, err error) error

ErrEntityTooLarge response.

func ErrForbidden

func ErrForbidden(c echo.Context, err error) error

ErrForbidden response.

func ErrNotFound

func ErrNotFound(c echo.Context, err error) error

ErrNotFound response.

func ErrResponse

func ErrResponse(c echo.Context, status int, msg string) error

ErrResponse is a generate error response.

func ErrUnauthorized

func ErrUnauthorized(c echo.Context, err error) error

ErrUnauthorized response.

func ErrorHandler

func ErrorHandler(err error, c echo.Context)

ErrorHandler returns error handler that returns in the format: {"error": {"message": "error message", status: 500}}".

func JSON

func JSON(c echo.Context, status int, i interface{}) error

JSON response.

func NewHandler

func NewHandler(s *Server) http.Handler

NewHandler returns http.Handler for Server.

func NewPubSubHandler

func NewPubSubHandler(s *PubSubServer) http.Handler

NewPubSubHandler returns http.Handler for Server.

Types

type Access

type Access struct {
	Allow   bool
	Message string
	// StatusCode (optional) for custom HTTP status (if denied)
	StatusCode int
}

Access returns whether to allow or deny.

func AccessAllow

func AccessAllow() Access

AccessAllow allow access.

func AccessDeny

func AccessDeny(msg string) Access

AccessDeny deny access (bad request).

func AccessDenyErrored

func AccessDenyErrored(err error) Access

AccessDenyErrored deny access (an error occurred trying to determine access).

func AccessDenyTooManyRequests

func AccessDenyTooManyRequests(msg string) Access

AccessDenyTooManyRequests deny access (too many requests).

type AccessAction

type AccessAction string

AccessAction is action for access control.

const (
	// Put action.
	Put AccessAction = "put"
	// Post action.
	Post AccessAction = "post"
)

type AccessContext

type AccessContext interface {
	RealIP() string
	Request() *http.Request
}

AccessContext is context for request.

type AccessFn

type AccessFn func(c AccessContext, resource AccessResource, action AccessAction) Access

AccessFn returns access to resource. If error message begins with an integer, it will use that as the http status code. For example, "429: too many requests".

type AccessResource

type AccessResource string

AccessResource is resource for access control.

const (
	// SigchainResource for sigchain.
	SigchainResource AccessResource = "sigchain"
)

func (AccessResource) String

func (r AccessResource) String() string

type Fire

type Fire interface {
	ds.DocumentStore
	ds.Changes
}

Fire defines interface for remote store (like Firestore).

type LogLevel

type LogLevel int

LogLevel ...

const (
	// DebugLevel ...
	DebugLevel LogLevel = 3
	// InfoLevel ...
	InfoLevel LogLevel = 2
	// WarnLevel ...
	WarnLevel LogLevel = 1
	// ErrLevel ...
	ErrLevel LogLevel = 0
)

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Errorf(format string, args ...interface{})
}

Logger compatible with GCP.

func NewLogger

func NewLogger(lev LogLevel) Logger

NewLogger ...

type MemCache

type MemCache interface {
	// Get returns value at key.
	Get(ctx context.Context, k string) (string, error)
	// Put puts a value at key.
	Set(ctx context.Context, k string, v string) error
	// Delete key.
	Delete(ctx context.Context, k string) error
	// Expire key.
	Expire(ctx context.Context, k string, dt time.Duration) error
	// Increment value at key.
	Increment(ctx context.Context, k string) (int64, error)
}

MemCache defines interface for memcache. Used to prevent nonce re-use for authenticated requests.

func NewMemTestCache

func NewMemTestCache(nowFn func() time.Time) MemCache

NewMemTestCache returns in memory MemCache (for testing).

type PubSub

type PubSub interface {
	Publish(ctx context.Context, name string, b []byte) error
	Subscribe(ctx context.Context, name string, receiveFn func(b []byte)) error
}

PubSub ...

func NewPubSub

func NewPubSub() PubSub

NewPubSub is PubSub for testing.

type PubSubServer

type PubSubServer struct {
	URL string
	// contains filtered or unexported fields
}

PubSubServer implements PubSub.

func NewPubSubServer

func NewPubSubServer(pubSub PubSub, mc MemCache, logger Logger) *PubSubServer

NewPubSubServer creates a PubSubServer.

func (*PubSubServer) AddRoutes

func (s *PubSubServer) AddRoutes(e *echo.Echo)

AddRoutes adds routes to an Echo instance.

func (*PubSubServer) SetNowFn

func (s *PubSubServer) SetNowFn(nowFn func() time.Time)

SetNowFn sets clock Now function.

type Server

type Server struct {

	// URL (base) of form http(s)://host:port with no trailing slash to help
	// authorization checks in testing where the host is ambiguous.
	URL string
	// contains filtered or unexported fields
}

Server ...

func New

func New(fi Fire, mc MemCache, users *user.Store, logger Logger) *Server

New creates a Server.

func (*Server) AddRoutes

func (s *Server) AddRoutes(e *echo.Echo)

AddRoutes adds routes to an Echo instance.

func (*Server) SetAccessFn

func (s *Server) SetAccessFn(fn AccessFn)

SetAccessFn sets access control.

func (*Server) SetAdmins

func (s *Server) SetAdmins(admins []keys.ID)

SetAdmins sets authorized admins.

func (*Server) SetInternalAuth

func (s *Server) SetInternalAuth(internalAuth string)

SetInternalAuth for authorizing internal requests, like tasks.

func (*Server) SetNowFn

func (s *Server) SetNowFn(nowFn func() time.Time)

SetNowFn sets clock Now function.

func (*Server) SetTasks

func (s *Server) SetTasks(tasks Tasks)

SetTasks ...

type Tasks

type Tasks interface {
	// CreateTask ...
	CreateTask(ctx context.Context, method string, url string, authToken string) error
}

Tasks ..

func NewTestTasks

func NewTestTasks(svr *Server) Tasks

NewTestTasks returns Tasks for use in tests.

Jump to

Keyboard shortcuts

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