server

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGetKey                = errors.New("server: failed to get the key")
	ErrConnStr               = errors.New("server: invalid connection string")
	ErrFetchingConfiguration = errors.New("server: error fetching configuration")
	ErrCreateKey             = errors.New("server: failed to create a key on the fly")
	ErrUnexpectedBody        = errors.New("server: unexpected configuration response body")
)
View Source
var ErrExecTmpl = &APIError{Err: "failed to exec tmpl", Status: http.StatusInternalServerError}

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Err    string
	Status int
}

func (*APIError) Error

func (e *APIError) Error() string

type DBParams

type DBParams struct {
	DBConnString string
	DBName       string
	DBCollName   string
}

type HandlerFuncErr

type HandlerFuncErr func(w http.ResponseWriter, r *http.Request) error

type Server

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

func New

func New(ctx context.Context, dbParams DBParams, tmpls templates.Map) (*Server, error)

New returns a *Server with all the required setup done.

func (*Server) Fill

func (s *Server) Fill(ctx context.Context, maxCount int64, sleepDuration time.Duration)

Fill fills the db to the maxCount.

func (*Server) GetKey

func (s *Server) GetKey(ctx context.Context) (*models.Account, error)

GetKey either returns a key that is already stored or creates a new one.

func (*Server) HandleGenerateKey

func (s *Server) HandleGenerateKey() http.HandlerFunc

func (*Server) HandleHomePage

func (s *Server) HandleHomePage() http.HandlerFunc

func (*Server) HandleUpdateConfig

func (s *Server) HandleUpdateConfig() http.HandlerFunc

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(listenAddr string) error

ListenAndServe is a wrapper around (*http.Server).ListenAndServe().

func (*Server) UpdateConfiguration

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

UpdateConfiguration fetches the most recent configuration and sets it.

func (*Server) WrapHandlerFuncErr

func (s *Server) WrapHandlerFuncErr(f HandlerFuncErr) http.HandlerFunc

func (*Server) WriteErr

func (s *Server) WriteErr(w http.ResponseWriter, e *APIError) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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