server

package module
Version: v0.0.0-...-93b26d4 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSON

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

JSON response.

func Msgpack

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

Msgpack response.

func NewHandler

func NewHandler(s *Server) http.Handler

NewHandler returns http.Handler for Server.

Types

type Emailer

type Emailer interface {
	SendVerificationEmail(email string, code string) error
}

Emailer sends emails.

type ErrHTTP

type ErrHTTP struct {
	Code    int    `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
	Err     error  `json:"-"`
}

ErrHTTP ...

func (ErrHTTP) Error

func (e ErrHTTP) Error() string

type Fire

type Fire interface {
	dstore.Documents
	events.Events
}

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
	// NoLevel ...
	NoLevel LogLevel = -1
)

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 Redis

type Redis 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)
	// Publish data to key.
	Publish(ctx context.Context, k string, b []byte) error
}

Redis defines interface for a distributed key value store. Used to prevent nonce re-use for authenticated requests.

func NewRedisTest

func NewRedisTest(clock tsutil.Clock) Redis

NewRedisTest returns Redis for testing.

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, rds Redis, client http.Client, clock tsutil.Clock, 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) ErrBadRequest

func (s *Server) ErrBadRequest(c echo.Context, err error) error

ErrBadRequest response.

func (*Server) ErrConflict

func (s *Server) ErrConflict(c echo.Context, err error) error

ErrConflict response.

func (*Server) ErrEntityTooLarge

func (s *Server) ErrEntityTooLarge(c echo.Context, err error) error

ErrEntityTooLarge response.

func (*Server) ErrForbidden

func (s *Server) ErrForbidden(c echo.Context, err error) error

ErrForbidden response.

func (*Server) ErrNotFound

func (s *Server) ErrNotFound(c echo.Context, err error) error

ErrNotFound response.

func (*Server) ErrResponse

func (s *Server) ErrResponse(c echo.Context, err error) error

ErrResponse is a generate error response. All errors come through here.

func (*Server) ErrTooManyRequests

func (s *Server) ErrTooManyRequests(c echo.Context, err error) error

ErrTooManyRequests response.

func (*Server) ErrorHandler

func (s *Server) ErrorHandler(err error, c echo.Context)

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

func (*Server) GenerateToken

func (s *Server) GenerateToken() (string, error)

func (*Server) SetAdmins

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

SetAdmins sets authorized admins.

func (*Server) SetClock

func (s *Server) SetClock(clock tsutil.Clock)

SetClock sets clock.

func (*Server) SetEmailer

func (s *Server) SetEmailer(emailer Emailer)

SetEmailer sets emailer.

func (*Server) SetInternalAuth

func (s *Server) SetInternalAuth(internalAuth string)

SetInternalAuth for authorizing internal requests, like tasks.

func (*Server) SetInternalKey

func (s *Server) SetInternalKey(internalKey string) error

SetInternalKey for encrypting between internal services.

func (*Server) SetTasks

func (s *Server) SetTasks(tasks Tasks)

SetTasks ...

func (*Server) SetTokenKey

func (s *Server) SetTokenKey(tokenKey string) error

SetTokenKey for setting token key.

func (*Server) ValidateToken

func (s *Server) ValidateToken(token string) error

type TaskPriority

type TaskPriority int

TaskPriority suggests a higher priority queue.

const (
	// HighPriority ...
	HighPriority TaskPriority = 1
	// LowPriority ...
	LowPriority TaskPriority = 100
)

type Tasks

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

Tasks ..

func NewTestTasks

func NewTestTasks(svr *Server) Tasks

NewTestTasks returns Tasks for use in tests.

type Vault

type Vault struct {
	ID keys.ID `json:"id" msgpack:"id"`

	Index     int64 `json:"idx,omitempty" msgpack:"idx,omitempty"`
	Timestamp int64 `json:"ts,omitempty" msgpack:"ts,omitempty"`
}

type VaultResponse

type VaultResponse struct {
	Vault     []*api.Event `json:"vault" msgpack:"vault"`
	Index     int64        `json:"idx" msgpack:"idx"`
	Truncated bool         `json:"truncated,omitempty" msgpack:"trunc,omitempty"`
}

VaultResponse ...

Jump to

Keyboard shortcuts

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