api_server

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

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

Go to latest
Published: Feb 1, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorBadRequestData = NewError(http.StatusBadRequest, "bad request data")
)

Functions

This section is empty.

Types

type Endpoint

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

func DELETE

func DELETE(path string, processor Processor) (r *Endpoint)

Returns DELETE route

func GET

func GET(path string, processor Processor) (r *Endpoint)

Returns GET route

func NewEndpoint

func NewEndpoint(method, path string, endpoint Processor) (r *Endpoint)

func PUT

func PUT(path string, processor Processor) (r *Endpoint)

Returns PUT route

func (*Endpoint) Processor

func (e *Endpoint) Processor() (p Processor)

type Error

type Error struct {
	Code   int
	Reason string
}

func NewError

func NewError(code int, reason string) (e *Error)

func UnwrapError

func UnwrapError(in error) (out *Error)

func (*Error) Error

func (e *Error) Error() string

type Processor

type Processor interface {

	// Empty returns empty structure for request unmarshal or <nil> if request doesn't send any data.
	Empty() interface{}

	// Process handles URL and ingest structure and returns data or error
	Process(ctx context.Context, u *url.URL, v interface{}) (res interface{}, err error)
}

Processor handles RPC path-method

type Router

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

func NewRouter

func NewRouter(log *logx.Log, endpoints ...*Endpoint) (r *Router)

func (*Router) ConsumeMessage

func (r *Router) ConsumeMessage(message bus.Message) (err error)

ConsumeMessage accepts message with proto.NodesInfo

func (*Router) GetEndpoint

func (r *Router) GetEndpoint(method, path string) (e *Endpoint, err error)

func (*Router) ServeHTTP

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

type Server

type Server struct {
	*supervisor.Control
	// contains filtered or unexported fields
}

func NewServer

func NewServer(ctx context.Context, log *logx.Log, addr string, router *Router) (s *Server)

func (*Server) Close

func (s *Server) Close() (err error)

func (*Server) Open

func (s *Server) Open() (err error)

Jump to

Keyboard shortcuts

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