http

package
v0.1.92 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const ContentTypeJSON = "application/json"

ContentTypeJSON the json content type of request

Variables

This section is empty.

Functions

func HandleResponse added in v0.1.15

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

HandleResponse handles response

func Respond added in v0.1.44

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

Respond Respond

func RespondMsg added in v0.1.44

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

RespondMsg RespondMsg

func RespondStream added in v0.1.52

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 added in v0.1.21

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

GetJSON get data with json content type

func (*Client) GetURL added in v0.1.70

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

func (*Client) PostJSON added in v0.1.21

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

PostJSON post data with json content type

func (*Client) PostURL added in v0.1.70

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

func (*Client) SendUrl added in v0.1.81

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

type ClientConfig added in v0.1.13

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 added in v0.1.13

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 added in v0.1.43

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

Response Response

func NewResponse added in v0.1.43

func NewResponse(code, msg string) Response

NewResponse NewResponse

type Server added in v0.1.50

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

func NewServer added in v0.1.43

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

NewServer new server

func (*Server) Close added in v0.1.50

func (s *Server) Close()

func (*Server) Start added in v0.1.50

func (s *Server) Start()

type ServerConfig added in v0.1.43

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