web

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2020 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyFormatter

func EmptyFormatter(*Context, int, Headers, interface{}) error

func JSONFormatter

func JSONFormatter(m *Context, code int, headers Headers, body interface{}) error

func RpcFormatter

func RpcFormatter(m *Context, code int, headers Headers, body interface{}) error

func TextFormatter

func TextFormatter(m *Context, code int, headers Headers, body interface{}) error

Types

type CallFunc

type CallFunc func(*Context) error

type ConfigItem

type ConfigItem struct {
	Addr         string        `yaml:"addr" json:"addr"`
	ReadTimeout  time.Duration `yaml:"read_timeout" json:"read_timeout"`
	WriteTimeout time.Duration `yaml:"write_timeout" json:"write_timeout"`
	IdleTimeout  time.Duration `yaml:"idle_timeout" json:"idle_timeout"`
}

type Context

type Context struct {
	Writer    http.ResponseWriter
	Reader    *http.Request
	Formatter FormatterFunc
}

func (*Context) Decode

func (_ctx *Context) Decode(call func(http.Header, []byte) error) error

func (*Context) Empty

func (_ctx *Context) Empty(code int) error

func (*Context) Encode

func (_ctx *Context) Encode(call func() (int, Headers, interface{})) error

func (*Context) Error

func (_ctx *Context) Error(code int, err error) error

func (*Context) GetCookies

func (_ctx *Context) GetCookies() map[string]*http.Cookie

func (*Context) Redirect

func (_ctx *Context) Redirect(url string) error

func (*Context) SetCookie

func (_ctx *Context) SetCookie(key, value string, ttl time.Duration)

type Debug

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

func NewCustomDebug

func NewCustomDebug(conf ConfigItem, log logger.Logger) *Debug

func NewDebug

func NewDebug(conf *DebugConfig, log logger.Logger) *Debug

func (*Debug) Down

func (_debug *Debug) Down() error

func (*Debug) Handlers

func (_debug *Debug) Handlers() []Handler

func (*Debug) Up

func (_debug *Debug) Up() error

type DebugConfig

type DebugConfig struct {
	Debug ConfigItem `yaml:"debug" json:"debug"`
}

http server config

type FormatterFunc

type FormatterFunc func(m *Context, code int, headers Headers, body interface{}) error

type HTTPConfig

type HTTPConfig struct {
	HTTP ConfigItem `yaml:"http" json:"http"`
}

type Handler

type Handler struct {
	Method     string
	Path       string
	Call       CallFunc
	Middleware CallFunc
	Formatter  FormatterFunc
}

type Headers

type Headers map[string]string

type ModuleInjecter

type ModuleInjecter interface {
	Handlers() []Handler
}

type ResponseErrorModel

type ResponseErrorModel struct {
	Error string `json:"error"`
}

type ResponseModel

type ResponseModel struct {
	Data interface{} `json:"data"`
}

json model

type Route

type Route struct {
	Call       CallFunc
	Middleware CallFunc
	Formatter  FormatterFunc
}

type Router

type Router struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Router) AddRoutes

func (_rtr *Router) AddRoutes(handlers ...Handler)

func (*Router) InjectRoutes

func (_rtr *Router) InjectRoutes(mod ModuleInjecter)

func (*Router) ServeHTTP

func (_rtr *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RpcErrorBodyModel

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

type RpcRequestModel

type RpcRequestModel struct {
	ID     string      `json:"id"`
	Method string      `json:"method"`
	Params interface{} `json:"params,omitempty"`
}

json rpc model

type RpcResponseErrorModel

type RpcResponseErrorModel struct {
	ID    string            `json:"id"`
	Error RpcErrorBodyModel `json:"error"`
}

type RpcResponseModel

type RpcResponseModel struct {
	ID     string      `json:"id"`
	Result interface{} `json:"result"`
}

type Server

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

func NewCustomServer

func NewCustomServer(conf ConfigItem, log logger.Logger) *Server

func NewServer

func NewServer(conf *HTTPConfig, log logger.Logger) *Server

func (*Server) Down

func (_srv *Server) Down() error

func (*Server) Router

func (_srv *Server) Router() *Router

func (*Server) Up

func (_srv *Server) Up() error

Jump to

Keyboard shortcuts

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