gateway

package
v3.1.36 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RouteProtocolGRPC = route.ProtocolGRPC
	RouteProtocolHTTP = route.ProtocolHTTP
)

Variables

This section is empty.

Functions

func RegisterHTTPRoute added in v3.1.22

func RegisterHTTPRoute(app *core.Core, value *Route, routePrefix ...string) error

RegisterHTTPRoute explicitly publishes an HTTP route definition to etcd. The service must already have enabled etcd registry/discovery.

func RegisterHTTPRoutes added in v3.1.35

func RegisterHTTPRoutes(app *core.Core, routes ...*Route) error

RegisterHTTPRoutes validates and publishes a complete batch of manual HTTP routes. It performs no periodic republishing and starts no worker.

Types

type CircuitBreaker added in v3.1.16

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

CircuitBreaker 熔断器

type Config

type Config struct {
	EtcdEndpoints       []string      `yaml:"etcd_endpoints"`
	EtcdDialTimeout     time.Duration `yaml:"etcd_dial_timeout"`
	Namespace           string        `yaml:"namespace"`
	RoutePrefix         string        `yaml:"route_prefix"`
	HTTPAddr            string        `yaml:"http_addr"`
	GRPCServiceExcludes []string      `yaml:"grpc_service_excludes"`
	MaxRequestBodyBytes int64         `yaml:"max_request_body_bytes"`
}

type ConnectionPool added in v3.1.16

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

func NewConnectionPool added in v3.1.16

func NewConnectionPool() *ConnectionPool

func (*ConnectionPool) Close added in v3.1.16

func (cp *ConnectionPool) Close()

func (*ConnectionPool) Get added in v3.1.16

func (cp *ConnectionPool) Get(serviceName string) *ServicePool

func (*ConnectionPool) GetOrCreate added in v3.1.16

func (cp *ConnectionPool) GetOrCreate(app *core.Core, serviceName string) *ServicePool

func (*ConnectionPool) Remove added in v3.1.16

func (cp *ConnectionPool) Remove(serviceName string)

func (*ConnectionPool) RemoveIfEmpty added in v3.1.35

func (cp *ConnectionPool) RemoveIfEmpty(serviceName string, expected *ServicePool) bool

func (*ConnectionPool) ServiceNames added in v3.1.35

func (cp *ConnectionPool) ServiceNames() []string

func (*ConnectionPool) SetDesiredInstance added in v3.1.35

func (cp *ConnectionPool) SetDesiredInstance(app *core.Core, serviceName, instanceID, addr string) *ServicePool

type EtcdGateway

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

EtcdGateway etcd 网关

func NewEtcdGateway

func NewEtcdGateway(app *core.Core, conf ...*Config) (*EtcdGateway, error)

func (*EtcdGateway) Close

func (gw *EtcdGateway) Close() error

type HTTPInstance added in v3.1.35

type HTTPInstance struct {
	ID     string
	Addr   string
	Target *url.URL
}

HTTPInstance is an immutable HTTP service target prepared from a registry event. Target is parsed once and reused by the request hot path.

type MethodDescriptor

type MethodDescriptor struct {
	FullMethod  string
	Package     string // proto package, e.g. "v1.auth"
	Service     string // service name, e.g. "UserService"
	Method      string // method name, e.g. "PostLogin"
	NewRequest  func() proto.Message
	NewResponse func() proto.Message
	Resolver    interface {
		protoregistry.MessageTypeResolver
		protoregistry.ExtensionTypeResolver
	}
}

type ReflectionProxy

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

func NewReflectionProxy

func NewReflectionProxy(app *core.Core, addr string) (*ReflectionProxy, error)

func (*ReflectionProxy) Close

func (p *ReflectionProxy) Close() error

func (*ReflectionProxy) Invoke

func (p *ReflectionProxy) Invoke(ctx context.Context, fullMethod string, jsonReq []byte) ([]byte, error)

func (*ReflectionProxy) Methods

func (p *ReflectionProxy) Methods() map[string]*MethodDescriptor

Methods 返回所有已注册的方法

type ReflectionSchema added in v3.1.35

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

ReflectionSchema is the immutable reflected method set shared by all connections for one logical service. The map is built completely before the schema is published to a ServicePool.

type Route

type Route = route.Definition

type RouteProtocol added in v3.1.22

type RouteProtocol = route.Protocol

type ServicePool added in v3.1.16

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

ServicePool owns the connection-bearing proxies and the one immutable reflection schema for a logical service. The request hot path reads a sorted copy-on-write snapshot without taking locks or allocating.

func NewServicePool added in v3.1.16

func NewServicePool(app *core.Core, name string) *ServicePool

NewServicePool creates a service connection pool.

func (*ServicePool) AddOrUpdateInstance added in v3.1.16

func (p *ServicePool) AddOrUpdateInstance(instanceID, addr string) (*ReflectionProxy, bool, error)

AddOrUpdateInstance preserves the historical API for direct users. Gateway lifecycle code uses AddOrUpdateInstanceContext with its owned context.

func (*ServicePool) AddOrUpdateInstanceContext added in v3.1.35

func (p *ServicePool) AddOrUpdateInstanceContext(ctx context.Context, instanceID, addr string) (*ReflectionProxy, bool, error)

AddOrUpdateInstanceContext builds at most one schema per service and keeps candidate construction off the request hot path. Connections for a service are serialized only during connect/update; Get remains lock-free.

func (*ServicePool) Close added in v3.1.16

func (p *ServicePool) Close()

func (*ServicePool) DesiredAddress added in v3.1.35

func (p *ServicePool) DesiredAddress(instanceID string) (string, bool)

func (*ServicePool) Get added in v3.1.16

func (p *ServicePool) Get() *ReflectionProxy

Get returns a proxy using deterministic round-robin over the pre-sorted snapshot. It performs no sorting, reflection, dialing, or allocation.

func (*ServicePool) GetExcept added in v3.1.35

func (p *ServicePool) GetExcept(excluded *ReflectionProxy) *ReflectionProxy

GetExcept returns a ready proxy other than excluded. It is used for one alternate-instance retry and never falls back to an unready connection.

func (*ServicePool) InstanceAddress added in v3.1.35

func (p *ServicePool) InstanceAddress(instanceID string) (string, bool)

func (*ServicePool) InstanceIDs added in v3.1.35

func (p *ServicePool) InstanceIDs() []string

func (*ServicePool) MarkInstanceUndesired added in v3.1.35

func (p *ServicePool) MarkInstanceUndesired(instanceID string)

func (*ServicePool) RemoveInstance added in v3.1.16

func (p *ServicePool) RemoveInstance(instanceID string)

RemoveInstance removes the desired marker and the installed connection.

func (*ServicePool) RemoveInstanceIfUndesired added in v3.1.35

func (p *ServicePool) RemoveInstanceIfUndesired(instanceID string) bool

RemoveInstanceIfUndesired makes delayed delete tasks safe when a newer PUT for the same service ID has already arrived.

func (*ServicePool) Schema added in v3.1.35

func (p *ServicePool) Schema() *ReflectionSchema

func (*ServicePool) SetDesiredInstance added in v3.1.35

func (p *ServicePool) SetDesiredInstance(instanceID, addr string) bool

SetDesiredInstance must happen before a connect is launched. A candidate is installed only if this exact ID/address is still desired when it completes.

func (*ServicePool) Size added in v3.1.16

func (p *ServicePool) Size() int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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