server

package
v0.0.0-...-961a5eb Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WS1000001 = "WS-1000001"
	WS1000002 = "WS-1000002"
	WS1000003 = "WS-1000003"
	WS1000004 = "WS-1000004"
	WS1000005 = "WS-1000005"
	WS1000006 = "WS-1000006"
	WS1000007 = "WS-1000007"
	WS1000008 = "WS-1000008"
	WS1000009 = "WS-1000009"
	WS1000010 = "WS-1000010"
)

All error codes

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Port         int           `json:"port" envvar:"PORT,required"`
	ReadTimeout  time.Duration `json:"readTimeout" envvar:"READ_TIMEOUT,default=3s"`
	WriteTimeout time.Duration `json:"writeTimeout" envvar:"WRITE_TIMEOUT,default=3s"`

	Logger Logger `json:"-" envvar:"-"`

	IncludeStatusCodeInMessages bool `json:"-" envvar:"-"`

	Storage Storage `json:"-" envvar:"-"`
}

Config contains information necessary to set up a Server.

func (*Config) CfgBuildInit

func (cfg *Config) CfgBuildInit() error

CfgBuildInit initializes the Logger. It should only be called by a cfgbuild.Builder.

func (*Config) CfgBuildValidate

func (cfg *Config) CfgBuildValidate() error

CfgBuildValidate checks the specified values. It should only be called by a cfgbuild.Builder.

type Logger

type Logger interface {
	Debug(msg string)
	Info(msg string)
	Warning(msg string)
	Error(msg string)
}

The Logger interface defines the methods required by the Server for logging.

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

A Route describes a rest endpoint.

type Server

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

A Server is a web server that extends http.Server. It should be created with the New() function, started with the Server.ListenAndServe() function, and can be cleanly closed with the Server.Shutdown() function.

func New

func New(cfg Config) (*Server, error)

New creates, configures, and returns a new server instance.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

func (*Server) RespondWithError

func (s *Server) RespondWithError(ctx context.Context, w http.ResponseWriter, r *http.Request,
	httpStatus int, errCode errorCode, message string, err error)

func (*Server) RespondWithJSON

func (s *Server) RespondWithJSON(ctx context.Context, w http.ResponseWriter, httpStatus int, body interface{})

func (*Server) RespondWithMessage

func (s *Server) RespondWithMessage(ctx context.Context, w http.ResponseWriter, httpStatus int, msg string)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHttp routes and handles a request. It is typically used for testing purposes.

func (*Server) Shutdown

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

Shutdown cleanly shutsdown the server and blocks until complete (or timing out).

type Storage

type Storage interface {
	Get(string) (widget.Widget, bool, error)
	Set(string, widget.Widget) error
	Delete(string) (widget.Widget, bool, error)
	Keys() ([]string, error)
}

The Storage interface defines the methods required to access backing Widget storage.

Jump to

Keyboard shortcuts

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