server

package
v0.0.0-...-6879cb0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAAS1000001 = "MAAS-1000001"
	MAAS1000002 = "MAAS-1000002"
	MAAS1000003 = "MAAS-1000003"
	MAAS1000004 = "MAAS-1000004"
	MAAS1000005 = "MAAS-1000005"
	MAAS1000006 = "MAAS-1000006"
	MAAS1000007 = "MAAS-1000007"
	MAAS1000008 = "MAAS-1000008"
	MAAS1000009 = "MAAS-1000009"
	MAAS1000010 = "MAAS-1000010"
)

All error codes

Variables

This section is empty.

Functions

This section is empty.

Types

type CallCounter

type CallCounter interface {
	Increment(id string, inc int) error
	Lookup(id string) (int, error)
}

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:"-"`

	CallCounter CallCounter `json:"-" envvar:"-"`

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

	AstraConfig astra.Config `json:"-" envvar:">,prefix=ASTRA_"`
}

Config contains information necessary to set up a Server.

func (*Config) CfgBuildInit

func (cfg *Config) CfgBuildInit() error

CfgBuildInit initializes the Logger and CallCounter. 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).

Jump to

Keyboard shortcuts

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