server

package
v0.0.0-...-3d067a8 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2022 License: MIT Imports: 12 Imported by: 10

Documentation

Index

Constants

View Source
const (
	ErrProcessingRequestCode = iota + 1000
	ErrNotFoundCode
	ErrNotAllowedCode
	ErrServiceUnavailableCode
	ErrRequiredParamCode
	ErrUnauthorizedCode
	ErrFailedConversionCode
)

Variables

This section is empty.

Functions

func JsonResponse

func JsonResponse(w http.ResponseWriter, data interface{}, status int)

JsonResponse encodes and writes a JSON response using the given data object.

Types

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Error represents a error response.

func (Error) Error

func (e Error) Error() string

Error formats an error response as a string.

type Handler

type Handler func(http.ResponseWriter, *http.Request, Parameters)

Handler represents an HTTP handler method.

func NewHandler

func NewHandler(handler http.HandlerFunc) Handler

NewHandler wraps the HandlerFunc and returns a Handler.

type Parameter

type Parameter struct {
	Key   string
	Value string
}

Parameter represents a single URL parameter's key-value pair.

type Parameters

type Parameters []Parameter

Parameters represents a list of URL parameters.

func GetParameters

func GetParameters(ctx context.Context) Parameters

GetParameters returns the context values as Parameters.

func (Parameters) Get

func (params Parameters) Get(key string) string

Get returns a parmeter value for the given key. If a key does not exist an empty string is returned.

type ResponseSetting

type ResponseSetting func(w http.ResponseWriter)

ResponseSetting can be used to configure a repsonse writer.

func SetResponseHeader

func SetResponseHeader(key, value string) ResponseSetting

SetResponseHeader is a header setting that sets the response header key-value pair.

type Route

type Route struct {
	Handler          Handler
	Method           string
	Path             string
	ResponseSettings []ResponseSetting
}

Route respresents a HTTP API route

type Server

type Server interface {
	Start() error
	Stop() error
	Reload() error
	Add(handler Handler, method, path string, settings ...ResponseSetting) error
	SetTlsConfiguration(enable bool, cfg *tls.Config)
}

Server is interface that represents an HTTP server.

func New

func New(addr string, readTimeoutSeconds, writeTimeoutSeconds int) Server

New returns a server at the given address.

Jump to

Keyboard shortcuts

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