restserver

package
v0.0.0-...-1401454 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bootstrap

func Bootstrap(c []*Config)

TODO secure server

func GracefulShutdown

func GracefulShutdown()

GracefulShutdown shutdowns the rest server.

func ParseRequest

func ParseRequest(r *http.Request, i Request) error

func ParseRequestBodyJSON

func ParseRequestBodyJSON(r *http.Request, v interface{}) error

func ParseRequestParams

func ParseRequestParams(r *http.Request) map[string]string

func ParseToll

func ParseToll(r *http.Request) *toll.Toll

func RespondErrorJSON

func RespondErrorJSON(t *toll.Toll, w http.ResponseWriter, response interface{})

func RespondJSON

func RespondJSON(t *toll.Toll, w http.ResponseWriter, response Response) error

Types

type Config

type Config struct {
	Addr string `json:"addr"`

	Pprof  string `json:"pprof"`
	Health bool   `json:"health"`

	MaxRequestBodyByte int64 `json:"maxRequestBodyByte"`

	ReadHeaderTimeoutSecond uint `json:"readHeaderTimeoutSecond"`
	ReadTimeoutSecond       uint `json:"readTimeoutSecond"`
	WriteTimeoutSecond      uint `json:"writeTimeoutSecod"`
	IdleTimeoutSecond       uint `json:"idleTimeoutSecond"`

	CORSDomains []string `json:"corsDomains"`

	CORSHeaders []string `json:"corsHeaders"`
	// contains filtered or unexported fields
}

type Request

type Request interface {
	Parse(*http.Request) error
	Validate() error
}

type Response

type Response interface {
	Format() error
}

type Rest

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

Rest represents rest server

func Get

func Get() []*Rest

func (*Rest) AddHandler

func (rest *Rest) AddHandler(method, path string, handler http.Handler)

func (*Rest) Handler

func (rest *Rest) Handler(h http.HandlerFunc) http.HandlerFunc

func (*Rest) HandlerWithMaxBodySize

func (rest *Rest) HandlerWithMaxBodySize(h http.HandlerFunc, maxBodySize int64) http.HandlerFunc

func (*Rest) ListenAndServe

func (rest *Rest) ListenAndServe()

ListenAndServe starts rest server.

func (*Rest) MethodNotAllowed

func (rest *Rest) MethodNotAllowed(handler http.HandlerFunc)

func (*Rest) NotFound

func (rest *Rest) NotFound(handler http.HandlerFunc)

func (*Rest) Options

func (rest *Rest) Options(handler http.HandlerFunc)

func (*Rest) Panic

func (rest *Rest) Panic(handler func(http.ResponseWriter, *http.Request, interface{}))

Jump to

Keyboard shortcuts

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