util

package
v0.0.0-...-cb950d2 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2020 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Bolt1 = "boltV1"
	Bolt2 = "boltV2"
)
View Source
const (
	XExample = "rpc-example"
)

support SubProtocol

Variables

View Source
var (
	MeshLogPath  = "stdout"
	MeshLogLevel = "WARN"
	StartRetry   = false
)

can set

Functions

func BuildBoltV1Request

func BuildBoltV1Request(requestID uint64) *sofarpc.BoltRequest

func BuildBoltV1RequestWithContent

func BuildBoltV1RequestWithContent(requestID uint64, data types.IoBuffer) *sofarpc.BoltRequest

func BuildBoltV1Response

func BuildBoltV1Response(req *sofarpc.BoltRequest) *sofarpc.BoltResponse

func BuildBoltV2Request

func BuildBoltV2Request(requestID uint64) *sofarpc.BoltRequestV2

func BuildBoltV2Response

func BuildBoltV2Response(req *sofarpc.BoltRequestV2) *sofarpc.BoltResponseV2

func CreateMeshToMeshConfig

func CreateMeshToMeshConfig(clientaddr string, serveraddr string, appproto types.Protocol, meshproto types.Protocol, hosts []string, tls bool) *config.MOSNConfig

Mesh to Mesh clientaddr and serveraddr is mesh's addr appproto is client and server (not mesh) protocol meshproto is mesh's protocol hosts is server's addresses

func CreateProxyMesh

func CreateProxyMesh(addr string, hosts []string, proto types.Protocol) *config.MOSNConfig

mesh as a proxy , client and servre have same protocol

func CreateTCPProxyConfig

func CreateTCPProxyConfig(meshaddr string, hosts []string, isRouteEntryMode bool) *config.MOSNConfig

TCP Proxy

func CreateTLSExtensionConfig

func CreateTLSExtensionConfig(clientaddr string, serveraddr string, appproto types.Protocol, meshproto types.Protocol, hosts []string, ext *ExtendVerifyConfig) *config.MOSNConfig

func CreateWeightProxyMesh

func CreateWeightProxyMesh(addr string, proto types.Protocol, clusters []*WeightCluster) *config.MOSNConfig

mesh as a proxy , client and servre have same protocol

func CreateXProtocolMesh

func CreateXProtocolMesh(clientaddr string, serveraddr string, subprotocol string, hosts []string) *config.MOSNConfig

XProtocol must be mesh to mesh currently, support Path/Prefix is "/" only

func CurrentMeshAddr

func CurrentMeshAddr() string

func IsMapEmpty

func IsMapEmpty(m *sync.Map) bool

func NewBasicCluster

func NewBasicCluster(name string, hosts []string) v2.Cluster

func NewFilterChain

func NewFilterChain(routerConfigName string, downstream, upstream types.Protocol, routers []v2.Router) v2.FilterChain

func NewHeaderRouter

func NewHeaderRouter(cluster string, value string) v2.Router

common case

func NewHeaderWeightedRouter

func NewHeaderWeightedRouter(clusters []v2.WeightedCluster, value string) v2.Router

weighted cluster case

func NewListener

func NewListener(name, addr string, chains []v2.FilterChain) v2.Listener

func NewMOSNConfig

func NewMOSNConfig(listeners []v2.Listener, clusterManager config.ClusterManagerConfig) *config.MOSNConfig

func NewPathRouter

func NewPathRouter(cluster string, path string) v2.Router

func NewPrefixRouter

func NewPrefixRouter(cluster string, prefix string) v2.Router

func NewProxyFilter

func NewProxyFilter(routerfgname string, downstream, upstream types.Protocol) *v2.Proxy

Create Mesh Config

func NewWeightedCluster

func NewWeightedCluster(name string, hosts []*WeightHost) v2.Cluster

func NewXProtocolFilterChain

func NewXProtocolFilterChain(name string, subproto string, routers []v2.Router) v2.FilterChain

func RandomDuration

func RandomDuration(min, max time.Duration) time.Duration

func ServeSofaRPC

func ServeSofaRPC(t *testing.T, conn net.Conn, responseHandler func(iobuf types.IoBuffer) ([]byte, bool))

func WaitMapEmpty

func WaitMapEmpty(m *sync.Map, timeout time.Duration) bool

Types

type ExtendVerifyConfig

type ExtendVerifyConfig struct {
	ExtendType   string
	VerifyConfig map[string]interface{}
}

TLS Extension

type HTTP2Server

type HTTP2Server struct {
	Server  *http2.Server
	Handler http.Handler
	// contains filtered or unexported fields
}

func (*HTTP2Server) ServeConn

func (s *HTTP2Server) ServeConn(t *testing.T, conn net.Conn)

type HTTPHandler

type HTTPHandler struct{}

Server Implement

func (*HTTPHandler) ServeHTTP

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

type HTTPServer

type HTTPServer struct {
	Handler http.Handler
	// contains filtered or unexported fields
}

Http Server

func (*HTTPServer) Addr

func (s *HTTPServer) Addr() string

func (*HTTPServer) Close

func (s *HTTPServer) Close()

func (*HTTPServer) GoServe

func (s *HTTPServer) GoServe()

type RPCClient

type RPCClient struct {
	ClientID string
	Protocol string //bolt1, bolt2
	Codec    stream.Client
	Waits    sync.Map

	ExpectedStatus int16
	// contains filtered or unexported fields
}

func NewRPCClient

func NewRPCClient(t *testing.T, id string, proto string) *RPCClient

func (*RPCClient) Close

func (c *RPCClient) Close()

func (*RPCClient) Connect

func (c *RPCClient) Connect(addr string) error

func (*RPCClient) ConnectTLS

func (c *RPCClient) ConnectTLS(addr string, cfg *v2.TLSConfig) error

func (*RPCClient) OnDecodeError

func (c *RPCClient) OnDecodeError(context context.Context, err error, headers types.HeaderMap)

func (*RPCClient) OnReceive

func (c *RPCClient) OnReceive(ctx context.Context, headers types.HeaderMap, data types.IoBuffer, trailers types.HeaderMap)

func (*RPCClient) SendRequest

func (c *RPCClient) SendRequest()

func (*RPCClient) SendRequestWithData

func (c *RPCClient) SendRequestWithData(in string)

func (*RPCClient) Stats

func (c *RPCClient) Stats() bool

type RPCServer

type RPCServer struct {
	UpstreamServer
	Client *RPCClient
	// Statistic
	Name  string
	Count uint32
}

func (*RPCServer) ServeBoltV1

func (s *RPCServer) ServeBoltV1(t *testing.T, conn net.Conn)

func (*RPCServer) ServeBoltV2

func (s *RPCServer) ServeBoltV2(t *testing.T, conn net.Conn)

type ServeConn

type ServeConn func(t *testing.T, conn net.Conn)

type UpstreamServer

type UpstreamServer interface {
	GoServe()
	Close()
	Addr() string
}

func NewHTTPServer

func NewHTTPServer(t *testing.T, h http.Handler) UpstreamServer

func NewRPCServer

func NewRPCServer(t *testing.T, addr string, proto string) UpstreamServer

func NewUpstreamHTTP2

func NewUpstreamHTTP2(t *testing.T, addr string, h http.Handler) UpstreamServer

func NewUpstreamServer

func NewUpstreamServer(t *testing.T, addr string, serve ServeConn) UpstreamServer

func NewXProtocolServer

func NewXProtocolServer(t *testing.T, addr string, subproto string) UpstreamServer

type WeightCluster

type WeightCluster struct {
	Name   string
	Hosts  []*WeightHost
	Weight uint32
}

type WeightHost

type WeightHost struct {
	Addr   string
	Weight uint32
}

type XProtocolClient

type XProtocolClient struct {
	ClientID    string
	SubProtocol xprotocol.SubProtocol
	Codec       xprotocol.Multiplexing
	// contains filtered or unexported fields
}

XProtocol needs subprotocol for rpc is different from other protocol (extension)

func NewXClient

func NewXClient(t *testing.T, id string, subproto string) *XProtocolClient

func (*XProtocolClient) Close

func (c *XProtocolClient) Close()

func (*XProtocolClient) Connect

func (c *XProtocolClient) Connect(addr string) error

func (*XProtocolClient) RequestAndWaitReponse

func (c *XProtocolClient) RequestAndWaitReponse() error

type XProtocolServer

type XProtocolServer struct {
	UpstreamServer
	Client *XProtocolClient
}

func (*XProtocolServer) ServeXExample

func (s *XProtocolServer) ServeXExample(t *testing.T, conn net.Conn)

Jump to

Keyboard shortcuts

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