server

package
v0.0.0-...-92c3d43 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHandler

func GetHandler(s *store.Store) http.HandlerFunc

GetHandler get a value by the key.

func NewAPIError

func NewAPIError(internalErrorCode int, err error) error

NewAPIError return a new type of APIError.

func StatusHandler

func StatusHandler() http.HandlerFunc

StatusHandler a handler for a status endpoint, simply returns a "200 OK" response.

Types

type APIError

type APIError struct {
	Message  string `json:"error"`
	HTTPCode int    `json:"-"`
	// contains filtered or unexported fields
}

APIError a type of error that includes a friendly error message and a custom HTTP Status code.

func (APIError) Error

func (a APIError) Error() string

Error return the error

type Acknowledged

type Acknowledged struct {
	Acknowledged bool `json:"acknowledged"`
}

Acknowledged a simple response for acknowledging various operations.

type ErrResp

type ErrResp struct {
	Error string `json:"error"`
}

ErrResp a standard error response.

type JSONHandler

type JSONHandler func(w http.ResponseWriter, r *http.Request) (interface{}, error)

JSONHandler a handler for JSON responses.

func SetHandler

func SetHandler(s *store.Store) JSONHandler

SetHandler set a key/value pair in the store.

func (JSONHandler) Func

func (j JSONHandler) Func() http.HandlerFunc

Func the HandlerFunc

func (JSONHandler) SendErrorResponse

func (j JSONHandler) SendErrorResponse(w http.ResponseWriter, r *http.Request, apiError error)

SendErrorResponse send a JSON error response.

func (JSONHandler) ServeHTTP

func (j JSONHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP executes the handler to receive the response and error.

type Server

type Server struct {
	Ready chan struct{}
	// contains filtered or unexported fields
}

Server a HTTP server for interacting with cache stores.

func New

func New() *Server

New initialize a new server and setup routes/middleware.

func (*Server) Close

func (s *Server) Close() error

Close close the listener.

func (*Server) GetRouter

func (s *Server) GetRouter() chi.Router

GetRouter return the instance of chi router.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Serve start accepting requests, an empty struct will be sent to channel "Ready", this signals that the server is ready to accept requests.

This method should be called via a go routine to avoid blocking.

Jump to

Keyboard shortcuts

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