Documentation
¶
Overview ¶
Package pilot
Index ¶
- type Config
- type ConsistentHash
- type Context
- func (c *Context) Abort()
- func (c *Context) AddError(err error)
- func (c *Context) ClientIP() string
- func (c *Context) Duration() time.Duration
- func (c *Context) Get(key string) (any, bool)
- func (c *Context) GetMethodName() string
- func (c *Context) GetService() string
- func (c *Context) IsAborted() bool
- func (c *Context) Next()
- func (c *Context) Param(key string) string
- func (c *Context) Set(key string, value any)
- func (c *Context) SetMethodName(methodName string)
- func (c *Context) SetParams(key, value string)
- func (c *Context) SetService(service string)
- type Engine
- type EngineOption
- type EtcdRegistryConfig
- type GRPCInvoker
- type HandlerFunc
- type InvokerFunc
- type MethodInfo
- type NodeType
- type RegisterOption
- type Route
- type RouteTree
- type Router
- type ServerConfig
- type ServiceDiscoveryConfig
- type ServiceEndpoint
- type ServiceRegistrar
- type ServiceRegistry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Server *ServerConfig `json:"server" yaml:"server"`
Discovery *ServiceDiscoveryConfig `json:"discovery" yaml:"discovery"`
}
type ConsistentHash ¶
type ConsistentHash struct {
// contains filtered or unexported fields
}
ConsistentHash implements a consistent hashing mechanism for load balancing.
func NewConsistentHash ¶
func NewConsistentHash(replicas int) *ConsistentHash
type Context ¶
type Context struct {
Request *http.Request
Writer *responseWriter
// contains filtered or unexported fields
}
func NewContext ¶
func NewContext(w http.ResponseWriter, r *http.Request) *Context
func (*Context) GetMethodName ¶
func (*Context) GetService ¶
func (*Context) SetMethodName ¶
func (*Context) SetService ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) Use ¶
func (e *Engine) Use(mw ...HandlerFunc)
type EngineOption ¶
type EngineOption func(*Engine)
func WithContext ¶
func WithContext(ctx context.Context) EngineOption
func WithWatcher ¶
func WithWatcher(w discovery.Watcher) EngineOption
type EtcdRegistryConfig ¶ added in v1.0.4
type GRPCInvoker ¶
type GRPCInvoker struct {
// contains filtered or unexported fields
}
GRPCInvoker is a dynamic gRPC client that can invoke methods based on protobuf descriptors.
func NewGRPCInvoker ¶
func NewGRPCInvoker(addr string, fds *descriptorpb.FileDescriptorSet) (*GRPCInvoker, error)
func (*GRPCInvoker) Close ¶
func (inv *GRPCInvoker) Close() error
Close closes the underlying gRPC connection.
type HandlerFunc ¶
type HandlerFunc func(ctx *Context)
func Log ¶
func Log() HandlerFunc
func Recovery ¶
func Recovery() HandlerFunc
type MethodInfo ¶
type MethodInfo struct {
MethodDesc protoreflect.MethodDescriptor
InputDesc protoreflect.MessageDescriptor
OutputDesc protoreflect.MessageDescriptor
FullMethod string
// contains filtered or unexported fields
}
MethodInfo holds information about a gRPC method, including its descriptors and message pools.
type RegisterOption ¶
type RegisterOption func(registrar *ServiceRegistrar)
RegisterOption defines options for service registration
func WithFile ¶
func WithFile(filePath string) RegisterOption
WithFile adds a proto file to be compiled for service registration
func WithProtoPath ¶
func WithProtoPath(protoPath string) RegisterOption
WithProtoPath adds a proto import path for the compiler to resolve imports
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route represents an Server-to-gRPC routing configuration
type RouteTree ¶
type RouteTree[T any] struct { // contains filtered or unexported fields }
func NewRouteTree ¶
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router manages Server-to-gRPC routing with service discovery and load balancing
type ServerConfig ¶ added in v1.0.4
type ServerConfig struct {
Addr string `json:"addr" yaml:"addr"`
ReadTimeout time.Duration `json:"readTimeout" yaml:"readTimeout"`
WriteTimeout time.Duration `json:"writeTimeout" yaml:"writeTimeout"`
MaxHeaderBytes int `json:"maxHeaderBytes" yaml:"maxHeaderBytes"`
MaxBodyBytes int `json:"maxBodyBytes" yaml:"maxBodyBytes"`
}
type ServiceDiscoveryConfig ¶ added in v1.0.4
type ServiceDiscoveryConfig struct {
Mode discovery.Mode `json:"mode" yaml:"mode"`
Etcd *EtcdRegistryConfig `json:"etcd" yaml:"etcd"`
}
type ServiceEndpoint ¶
type ServiceEndpoint struct {
// contains filtered or unexported fields
}
ServiceEndpoint manages multiple instances of a service with load balancing
func (*ServiceEndpoint) Close ¶
func (se *ServiceEndpoint) Close()
func (*ServiceEndpoint) GetInvoker ¶
func (se *ServiceEndpoint) GetInvoker(service, method string) InvokerFunc
GetInvoker returns an InvokerFunc that uses consistent hashing to select the appropriate service instance.
type ServiceRegistrar ¶
type ServiceRegistrar struct {
// contains filtered or unexported fields
}
func NewServiceRegistrar ¶
func NewServiceRegistrar(serviceName, listenOn string, registry discovery.Registry) *ServiceRegistrar
func (*ServiceRegistrar) Deregister ¶
func (sr *ServiceRegistrar) Deregister(ctx context.Context) error
Deregister removes the service registration
func (*ServiceRegistrar) Register ¶
func (sr *ServiceRegistrar) Register(ctx context.Context, opts ...RegisterOption) error
Register compiles the proto files, extracts Server rules, and registers the service
type ServiceRegistry ¶
type ServiceRegistry map[string]*ServiceEndpoint
ServiceRegistry maps service names to their corresponding endpoints