v1.2.0 Latest Latest

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 20 Imported by: 0




View Source
const (
	MediaTypeJSON              = "application/json"
	MediaTypeXML               = "application/xml"
	MediaTypeFormUrlEncoded    = "application/x-www-form-urlencoded"
	MediaTypeMultipartFormData = "multipart/form-data"
	MediaTypePlainText         = "text/plain"
	MediaTypeHTML              = "text/html"


This section is empty.


func ContentSubtype

func ContentSubtype(contentType string) string

func DefaultRequestEncoder

func DefaultRequestEncoder(_ context.Context, contentType string, in interface{}) ([]byte, error)


  • 默认编码器

func DefaultResponseDecoder

func DefaultResponseDecoder(_ context.Context, res *http.Response, v interface{}) error


  • 默认解码器


type Client

type Client struct {
	// contains filtered or unexported fields

func NewClient

func NewClient(ctx context.Context, opts ...ClientOption) (*Client, error)

func (*Client) Invoke

func (c *Client) Invoke(ctx context.Context, method, contentType, path string, args interface{}, reply interface{}) error


  • 调用这个方法要注意编解码

type ClientOption

type ClientOption func(*clientOptions)

func WithBlock

func WithBlock() ClientOption

func WithDecodeResponseFunc

func WithDecodeResponseFunc(d DecodeResponseFunc) ClientOption


func WithDiscovery

func WithDiscovery(d registry.Discovery) ClientOption

func WithEncodeRequestFunc

func WithEncodeRequestFunc(e EncodeRequestFunc) ClientOption


func WithEndpoint

func WithEndpoint(endpoint string) ClientOption

WithEndpoint with client addr.

func WithMiddleware

func WithMiddleware(m ...middleware.Middleware) ClientOption

WithMiddleware with client middleware.

func WithTLSConfig

func WithTLSConfig(c *tls.Config) ClientOption

WithTLSConfig with tls config.

func WithTimeout

func WithTimeout(d time.Duration) ClientOption

WithTimeout with client request timeout.

func WithTransport

func WithTransport(t *http.Transport) ClientOption

type DecodeErrorFunc

type DecodeErrorFunc func(ctx context.Context, res *http.Response) error

type DecodeResponseFunc

type DecodeResponseFunc func(ctx context.Context, res *http.Response, out interface{}) error

DecodeResponseFunc is response decode func.

type EncodeRequestFunc

type EncodeRequestFunc func(ctx context.Context, contentType string, in interface{}) (body []byte, err error)

EncodeRequestFunc is request encode func.

type Resolver

type Resolver struct {
	Target *target.Target

	Selector selector.Selector
	Insecure bool
	// contains filtered or unexported fields

func NewResolver

func NewResolver(ctx context.Context, discovery registry.Discovery, target *target.Target, block, insecure bool, selector selector.Selector) (*Resolver, error)

func (*Resolver) Close

func (r *Resolver) Close() error

type Server

type Server struct {
	// contains filtered or unexported fields

Server is an HTTP server wrapper.

func NewServer

func NewServer(opts ...ServerOption) *Server

新建http server

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

start the HTTP server.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop stop the HTTP server.

type ServerOption

type ServerOption func(*Server)

func WithRouter

func WithRouter(g *gin.Engine) ServerOption


  • 路由处理器

func WithServerAddress

func WithServerAddress(addr string) ServerOption

func WithServerTLSConfig

func WithServerTLSConfig(t *tls.Config) ServerOption

func WithServerTimeout

func WithServerTimeout(timeout time.Duration) ServerOption

Jump to

Keyboard shortcuts

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