router

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DasMethods = [...]string{
	"getAsset",
	"searchAssets",
	"getAssetProof",
	"getAssetsByGroup",
	"getAssetsByOwner",
	"getAssetsByCreator",
	"getAssetsByAuthority",
}

Functions

This section is empty.

Types

type Balancer

type Balancer interface {
	NextServer() *url.URL
}

SIMPLE Balancer interface

type RPCRequest

type RPCRequest struct {
	Method  string      `json:"method"`
	Params  interface{} `json:"params,omitempty"`
	ID      any         `json:"id"`
	JSONRPC string      `json:"jsonrpc"`
}

func (*RPCRequest) IsDasRequest

func (r *RPCRequest) IsDasRequest() bool

func (*RPCRequest) RequestType

func (r *RPCRequest) RequestType() RPCRequestType

type RPCRequestType

type RPCRequestType uint8
const (
	RegularRPCRequest RPCRequestType = 1
	DasRPCRequest     RPCRequestType = 3
)

type RoundRobinBalancer

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

Regular RoundRobin implementation

func NewRoundRobinBalancer

func NewRoundRobinBalancer(servers []ServerEndpoint) (*RoundRobinBalancer, error)

func (*RoundRobinBalancer) NextServer

func (b *RoundRobinBalancer) NextServer() *url.URL

type Route

type Route struct {
	BalancerType string           `json:"balancerType"`
	Servers      []ServerEndpoint `json:"servers"`
}

func (Route) Balancer

func (r Route) Balancer() (Balancer, error)

type RouterHandler

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

func NewRouter

func NewRouter(regular Route, das Route) (*RouterHandler, error)

func (*RouterHandler) NextServer

func (h *RouterHandler) NextServer(rpcReq *RPCRequest) *url.URL

func (*RouterHandler) ServeHTTP

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

type RpcRoutes

type RpcRoutes map[RPCRequestType]Balancer

type ServerEndpoint

type ServerEndpoint struct {
	URL    url.URL `json:"url"`
	Weight uint64  `json:"weight,omitempty"`
}

func ConvertToEndpoint

func ConvertToEndpoint(rawUrl string, weight uint64) (ServerEndpoint, error)

func MustConvertToEndpoint

func MustConvertToEndpoint(rawUrl string, weight uint64) ServerEndpoint

func (*ServerEndpoint) UnmarshalJSON

func (s *ServerEndpoint) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface to fix url.URL

type WeightedRoundRobinBalancer

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

Weighted RoundRobin implementation

func NewWeightedRoundRobinBalancer

func NewWeightedRoundRobinBalancer(servers []ServerEndpoint) (*WeightedRoundRobinBalancer, error)

func (*WeightedRoundRobinBalancer) NextServer

func (b *WeightedRoundRobinBalancer) NextServer() *url.URL

Jump to

Keyboard shortcuts

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