rpc

package
v1.5.1-testnet Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolHttp = "HTTP"
	ProtocolWS   = "WS"
)

Variables

View Source
var (
	// DefaultShutdownTimeout is default timeout to shutdown RPC server.
	DefaultShutdownTimeout = 3 * time.Second
)

Functions

func HookMiddlewares

func HookMiddlewares(provider *providers.MiddlewarableProvider, url, space string, flags ...MiddlewareHookFlag)

func HookRedirectHttpHeader

func HookRedirectHttpHeader()

HookRedirectHttpHeader registers an event handler before sending client HTTP request, which will forward HTTP headers to the requested RPC service.

func MustInit

func MustInit()

func MustNewCfxClient

func MustNewCfxClient(url string, options ...ClientOption) *sdk.Client

func MustNewCfxClientsFromViper

func MustNewCfxClientsFromViper(options ...ClientOption) (clients []*sdk.Client)

func MustNewEthClient

func MustNewEthClient(url string, options ...ClientOption) *web3go.Client

func MustNewEthClientsFromViper

func MustNewEthClientsFromViper(options ...ClientOption) (clients []*web3go.Client)

func NewCfxClient

func NewCfxClient(url string, options ...ClientOption) (*sdk.Client, error)

func NewEthClient

func NewEthClient(url string, options ...ClientOption) (*web3go.Client, error)

func Url2NodeName

func Url2NodeName(url string) string

Types

type ClientOption

type ClientOption func(opt ClientOptioner)

func WithCircuitBreaker

func WithCircuitBreaker(maxFail int, failTimeWindow, openColdTime time.Duration) ClientOption

func WithClientHookCache

func WithClientHookCache(hook bool) ClientOption

func WithClientHookMetrics

func WithClientHookMetrics(hook bool) ClientOption

func WithClientMaxConnsPerHost

func WithClientMaxConnsPerHost(maxConns int) ClientOption

func WithClientRequestTimeout

func WithClientRequestTimeout(reqTimeout time.Duration) ClientOption

func WithClientRetryCount

func WithClientRetryCount(retry int) ClientOption

func WithClientRetryInterval

func WithClientRetryInterval(retryInterval time.Duration) ClientOption

type ClientOptioner

type ClientOptioner interface {
	SetRetryCount(retry int)
	SetRetryInterval(retryInterval time.Duration)
	SetRequestTimeout(reqTimeout time.Duration)
	SetMaxConnsPerHost(maxConns int)
	SetHookMetrics(hook bool)
	SetHookCache(hook bool)
	SetCircuitBreaker(maxFail int, failTimeWindow, openColdTime time.Duration)
}

type MiddlewareHookFlag

type MiddlewareHookFlag int

MiddlewareHookFlag represents the type for middleware hook flags.

const (
	// MiddlewareHookNone represents no middleware hooks enabled.
	MiddlewareHookNone MiddlewareHookFlag = 0

	// MiddlewareHookAll enables all middleware hooks.
	MiddlewareHookAll MiddlewareHookFlag = ^MiddlewareHookFlag(0)

	// MiddlewareHookLog enables logging middleware hook.
	MiddlewareHookLog MiddlewareHookFlag = 1 << iota

	// MiddlewareHookLogMetrics enables metrics logging middleware hook.
	MiddlewareHookLogMetrics

	// MiddlewareHookCache enables cache middleware hook.
	MiddlewareHookCache
)

type Protocol

type Protocol string

type Server

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

Server serves JSON RPC services.

func MustNewServer

func MustNewServer(name string, rpcs map[string]interface{}, middlewares ...handlers.Middleware) *Server

MustNewServer creates an instance of Server with specified RPC services.

func (*Server) MustServe

func (s *Server) MustServe(endpoint string, protocol Protocol)

MustServe serves RPC server in blocking way or panics if failed.

func (*Server) MustServeGraceful

func (s *Server) MustServeGraceful(
	ctx context.Context, wg *sync.WaitGroup, endpoint string, protocol Protocol,
)

MustServeGraceful serves RPC server in a goroutine until graceful shutdown.

func (*Server) String

func (s *Server) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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