server

package module
v0.0.0-...-050e4c4 Latest Latest
Warning

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

Go to latest
Published: May 25, 2021 License: MIT Imports: 24 Imported by: 1

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 Channel

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

	Index     int64  `json:"idx,omitempty"`
	Timestamp int64  `json:"ts,omitempty"`
	Token     string `json:"token,omitempty"`

	Usage   int64 `json:"usage,omitempty"`
	Deleted bool  `json:"del,omitempty"`

	CreatedBy keys.ID   `json:"createdBy,omitempty"`
	Info      Encrypted `json:"info,omitempty"`

	Team    keys.ID   `json:"team,omitempty"`
	TeamKey Encrypted `json:"teamKey,omitempty"`
}

type ChannelUser

type ChannelUser struct {
	User    keys.ID   `json:"user"`
	Key     Encrypted `json:"key"`
	Channel keys.ID   `json:"channel"`
}

type Emailer

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

Emailer sends emails.

type Encrypted

type Encrypted = api.Encrypted

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, config api.Config, 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

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.

Jump to

Keyboard shortcuts

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