rest

package
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTPMethodGet    = http.MethodGet
	HTTPMethodPut    = http.MethodPut
	HTTPMethodPost   = http.MethodPost
	HTTPMethodDelete = http.MethodDelete

	CtxResponse       = "_server_response"
	CtxRequest        = "_server_request"
	CtxMatchPattern   = "_server_match_pattern"
	CtxMatchFunc      = "_server_match_func"
	CtxResponseObject = "_server_response_object"

	ServerChainName = "_server_chain"

	HeaderResponseStatus = "X-Response-Status"

	HeaderAllow           = "Allow"
	HeaderHost            = "Host"
	HeaderServer          = "Server"
	HeaderContentType     = "Content-Type"
	HeaderContentEncoding = "Content-Encoding"
	HeaderAccept          = "Accept"
	HeaderAcceptEncoding  = "Accept-Encoding"

	AcceptAny = "*/*"

	ContentTypeJSON = "application/json; charset=UTF-8"
	ContentTypeText = "text/plain; charset=UTF-8"

	DefaultConnPoolPerHostSize = 5
)

Variables

This section is empty.

Functions

func DumpRequestOut

func DumpRequestOut(req *http.Request)

func DumpResponse

func DumpResponse(resp *http.Response)

func GetRouter

func GetRouter() http.Handler

GetRouter return the router fo REST service

func NewGZipBodyReader

func NewGZipBodyReader(body io.ReadCloser) (io.ReadCloser, error)

func RegisterServant

func RegisterServant(servant interface{})

RegisterServant registers a ROAServantService into serverHandler servant must be an pointer to service object

Types

type ROAServantService

type ROAServantService interface {
	URLPatterns() []Route
}

ROAServantService defines a group of Routes

type ROAServerHandler

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

ROAServerHandler is a HTTP request multiplexer Attention:

  1. not thread-safe, must be initialized completely before serve http request
  2. redirect not supported

func NewROAServerHander

func NewROAServerHander() *ROAServerHandler

NewROAServerHander news an ROAServerHandler

func (*ROAServerHandler) RegisterServant

func (roa *ROAServerHandler) RegisterServant(servant interface{})

RegisterServant registers a ROAServantService servant must be an pointer to service object

func (*ROAServerHandler) ServeHTTP

func (roa *ROAServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler

type Route

type Route struct {
	// Method is one of the following: GET,PUT,POST,DELETE
	Method string
	// Path contains a path pattern
	Path string
	// rest callback function for the specified Method and Path
	Func func(w http.ResponseWriter, r *http.Request)
}

Route is a http route

type Server

type Server struct {
	*http.Server

	Network          string
	KeepaliveTimeout time.Duration
	GraceTimeout     time.Duration

	Listener net.Listener
	// contains filtered or unexported fields
}

func NewServer

func NewServer(srvCfg *ServerConfig) *Server

func (*Server) AcceptOne

func (srv *Server) AcceptOne()

func (*Server) CloseOne

func (srv *Server) CloseOne() bool

func (*Server) File

func (srv *Server) File() *os.File

func (*Server) Listen

func (srv *Server) Listen() error

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() (err error)

func (*Server) ListenAndServeTLS

func (srv *Server) ListenAndServeTLS(certFile, keyFile string) (err error)

func (*Server) ListenTLS

func (srv *Server) ListenTLS() error

func (*Server) RegisterListener

func (srv *Server) RegisterListener(l net.Listener)

RegisterListener register the instance created outside by net.Listen() in server

func (*Server) Serve

func (srv *Server) Serve() (err error)

func (*Server) Shutdown

func (srv *Server) Shutdown()

type ServerConfig

type ServerConfig struct {
	Addr              string
	Handler           http.Handler
	ReadTimeout       time.Duration
	ReadHeaderTimeout time.Duration
	IdleTimeout       time.Duration
	WriteTimeout      time.Duration
	KeepAliveTimeout  time.Duration
	GraceTimeout      time.Duration
	MaxHeaderBytes    int
	TLSConfig         *tls.Config
	Compressed        bool
	CompressMinBytes  int
}

func DefaultServerConfig

func DefaultServerConfig() *ServerConfig

type TCPListener

type TCPListener struct {
	net.Listener
	// contains filtered or unexported fields
}

func NewTCPListener

func NewTCPListener(l net.Listener, srv *Server) (el *TCPListener)

func (*TCPListener) Accept

func (rl *TCPListener) Accept() (c net.Conn, err error)

func (*TCPListener) Close

func (rl *TCPListener) Close() error

func (*TCPListener) File

func (rl *TCPListener) File() *os.File

type URLClient

type URLClient struct {
	*http.Client

	TLS *tls.Config

	Cfg URLClientOption
}

func GetURLClient

func GetURLClient(o URLClientOption) (client *URLClient, err error)

func (*URLClient) HTTPDo

func (client *URLClient) HTTPDo(method string, rawURL string, headers http.Header, body []byte) (resp *http.Response, err error)

func (*URLClient) HTTPDoWithContext

func (client *URLClient) HTTPDoWithContext(ctx context.Context, method string, rawURL string, headers http.Header, body []byte) (resp *http.Response, err error)

type URLClientOption

type URLClientOption struct {
	SSLEnabled            bool
	Compressed            bool
	VerifyPeer            bool
	CAFile                string
	CertFile              string
	CertKeyFile           string
	CertKeyPWD            string
	SSLVersion            uint16
	HandshakeTimeout      time.Duration
	ResponseHeaderTimeout time.Duration
	RequestTimeout        time.Duration
	ConnsPerHost          int
}

func DefaultURLClientOption

func DefaultURLClientOption() URLClientOption

type URLPattern

type URLPattern struct {
	Method string
	Path   string
}

URLPattern defines an uri pattern

Jump to

Keyboard shortcuts

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