http

package
v2.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2020 License: Apache-2.0 Imports: 15 Imported by: 27

Documentation

Index

Constants

View Source
const ContentTypeJSON = "application/json"

ContentTypeJSON the json content type of request

Variables

This section is empty.

Functions

func HandleResponse

func HandleResponse(r *gohttp.Response) ([]byte, error)

HandleResponse handles response

func Respond

func Respond(c *routing.Context, httpCode int, obj []byte)

Respond Respond

func RespondMsg

func RespondMsg(c *routing.Context, httpCode int, code, msg string)

RespondMsg RespondMsg

func RespondStream

func RespondStream(c *routing.Context, httpCode int, bodyStream io.Reader, bodySize int)

RespondStream RespondStream If bodySize < 0, then bodyStream is read until io.EOF.

Types

type Client

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

Client client of http server

func NewClient

func NewClient(ops *ClientOptions) *Client

NewClient creates a new http client

func (*Client) Call

func (c *Client) Call(service, function string, payload []byte) ([]byte, error)

Call calls the function of service via HTTP POST

func (*Client) GetJSON

func (c *Client) GetJSON(url string) ([]byte, error)

GetJSON get data with json content type

func (*Client) GetURL

func (c *Client) GetURL(url string, header ...map[string]string) (*gohttp.Response, error)

func (*Client) PostJSON

func (c *Client) PostJSON(url string, payload []byte) ([]byte, error)

PostJSON post data with json content type

func (*Client) PostURL

func (c *Client) PostURL(url string, body io.Reader, header ...map[string]string) (*gohttp.Response, error)

func (*Client) SendUrl

func (c *Client) SendUrl(method, url string, body io.Reader, header ...map[string]string) (*gohttp.Response, error)

type ClientConfig

type ClientConfig struct {
	Address               string        `yaml:"address" json:"address"`
	Timeout               time.Duration `yaml:"timeout" json:"timeout" default:"30s"`
	KeepAlive             time.Duration `yaml:"keepalive" json:"keepalive" default:"30s"`
	MaxIdleConns          int           `yaml:"maxIdleConns" json:"maxIdleConns" default:"100"`
	IdleConnTimeout       time.Duration `yaml:"idleConnTimeout" json:"idleConnTimeout" default:"90s"`
	TLSHandshakeTimeout   time.Duration `yaml:"tlsHandshakeTimeout" json:"tlsHandshakeTimeout" default:"10s"`
	ExpectContinueTimeout time.Duration `yaml:"expectContinueTimeout" json:"expectContinueTimeout" default:"1s"`
	utils.Certificate     `yaml:",inline" json:",inline"`
}

ClientConfig client config

func (ClientConfig) ToClientOptions

func (cc ClientConfig) ToClientOptions() (*ClientOptions, error)

ToClientOptions converts client config to client options

type ClientOptions

type ClientOptions struct {
	Address               string
	TLSConfig             *tls.Config
	Timeout               time.Duration
	KeepAlive             time.Duration
	MaxIdleConns          int
	IdleConnTimeout       time.Duration
	TLSHandshakeTimeout   time.Duration
	ExpectContinueTimeout time.Duration
}

ClientOptions client options

func NewClientOptions

func NewClientOptions() *ClientOptions

NewClientOptions creates client options with default values

type Response

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

Response Response

func NewResponse

func NewResponse(code, msg string) Response

NewResponse NewResponse

type Server

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

func NewServer

func NewServer(cfg ServerConfig, handler fasthttp.RequestHandler) *Server

NewServer new server

func (*Server) Close

func (s *Server) Close()

func (*Server) Start

func (s *Server) Start()

type ServerConfig

type ServerConfig struct {
	Address            string        `yaml:"address" json:"address" default:":80"`
	Concurrency        int           `yaml:"concurrency" json:"concurrency"`
	DisableKeepalive   bool          `yaml:"disableKeepalive" json:"disableKeepalive"`
	TCPKeepalive       bool          `yaml:"tcpKeepalive" json:"tcpKeepalive"`
	MaxRequestBodySize int           `yaml:"maxRequestBodySize" json:"maxRequestBodySize"`
	ReadTimeout        time.Duration `yaml:"readTimeout" json:"readTimeout"`
	WriteTimeout       time.Duration `yaml:"writeTimeout" json:"writeTimeout"`
	IdleTimeout        time.Duration `yaml:"idleTimeout" json:"idleTimeout"`
	utils.Certificate  `yaml:",inline" json:",inline"`
}

ServerConfig server config

Jump to

Keyboard shortcuts

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