http

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultEncodeResponse

func DefaultEncodeResponse(ctx context.Context, writer http.ResponseWriter, response any) error

func DefaultErrorEncoder

func DefaultErrorEncoder(ctx context.Context, err error, writer http.ResponseWriter)

func NewResponse

func NewResponse(success bool, code int, message string, data any) error

NewResponse 实例化

Types

type Client

type Client struct {
	Config ClientConfig
	Nacos  *nacos.Nacos
}

func NewClient

func NewClient(n *nacos.Nacos) *Client

func (*Client) Do

func (c *Client) Do(ctx context.Context, serverName string, path string, method string, req []byte) (any, error)

func (*Client) Run

func (c *Client) Run(ctx context.Context, url string, method string, data []byte) ([]byte, error)

type ClientConfig

type ClientConfig struct {
	Retry   int64 `mapstructure:"retry"` // 重试次数
	Timeout int64 `mapstructure:"timeout"`
}

type DecodeRequestFunc

type DecodeRequestFunc func(ctx context.Context, r *http.Request) (req any, err error)

type EncodeResponseFunc

type EncodeResponseFunc func(ctx context.Context, w http.ResponseWriter, res any) error

type ErrorEncoder

type ErrorEncoder func(ctx context.Context, err error, w http.ResponseWriter)

type Handler

type Handler struct {
	DecodeRequest  DecodeRequestFunc
	EncodeResponse EncodeResponseFunc
	ErrorEncoder   ErrorEncoder
	Endpoint       endpoint.Endpoint
}

func NewHandler

func NewHandler(decode DecodeRequestFunc, endpoint endpoint.Endpoint) *Handler

NewHandler 实例化处理

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RequestFunc added in v1.0.2

type RequestFunc func(context.Context, *http.Request) context.Context

type Response

type Response struct {
	Success bool   `json:"success"`
	Code    int    `json:"code"`
	Message string `json:"message,omitempty"`
	Data    any    `json:"datas,omitempty"`
}

func (Response) Error

func (s Response) Error() string

type Server

type Server struct {
	Config  ServerConfig
	Handler http.Handler
	Limiter *limiter.Limiter
	Nacos   *nacos.Nacos
	// contains filtered or unexported fields
}

func NewServer

func NewServer(c ServerConfig, h http.Handler, l *limiter.Limiter, n *nacos.Nacos) *Server

NewServer http的服务端

func (*Server) After added in v1.0.2

func (s *Server) After(after ...ServerResponseFunc)

func (*Server) Before added in v1.0.2

func (s *Server) Before(before ...RequestFunc)

func (*Server) Run

func (s *Server) Run() error

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ServerConfig

type ServerConfig struct {
	Name         string `mapstructure:"name"`
	Host         string `mapstructure:"host"`
	Port         string `mapstructure:"port"`
	ReadTimeout  int64  `mapstructure:"readTimeout"`
	WriteTimeout int64  `mapstructure:"writeTimeout"`
	Metadata     map[string]string
}

type ServerResponseFunc added in v1.0.2

type ServerResponseFunc func(context.Context, http.ResponseWriter) context.Context

Jump to

Keyboard shortcuts

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