gateway

package
v3.1.32 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHTTPRoute added in v3.1.22

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

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

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
}

ConnectionPool 连接池管理器

func NewConnectionPool added in v3.1.16

func NewConnectionPool() *ConnectionPool

NewConnectionPool 创建连接池管理器

func (*ConnectionPool) Close added in v3.1.16

func (cp *ConnectionPool) Close()

Close 关闭所有连接池

func (*ConnectionPool) Get added in v3.1.16

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

Get 获取服务连接池

func (*ConnectionPool) GetOrCreate added in v3.1.16

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

GetOrCreate 获取或创建服务连接池

func (*ConnectionPool) Remove added in v3.1.16

func (cp *ConnectionPool) Remove(serviceName string)

Remove 移除服务连接池

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 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 Route

type Route struct {
	ID           string            `json:"id"`
	Protocol     RouteProtocol     `json:"protocol,omitempty"`
	Method       string            `json:"method"`
	Path         string            `json:"path"`
	ServiceName  string            `json:"service_name"`
	GRPCMethod   string            `json:"grpc_method"`
	UpstreamPath string            `json:"upstream_path,omitempty"`
	Description  string            `json:"description"`
	Headers      map[string]string `json:"headers,omitempty"`
	Enabled      bool              `json:"enabled"`
	CreatedAt    time.Time         `json:"created_at"`
	UpdatedAt    time.Time         `json:"updated_at"`
}

type RouteProtocol added in v3.1.22

type RouteProtocol string
const (
	RouteProtocolGRPC RouteProtocol = "grpc"
	RouteProtocolHTTP RouteProtocol = "http"
)

type ServicePool added in v3.1.16

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

ServicePool 服务连接池(按 instanceID 管理多个实例连接)

func NewServicePool added in v3.1.16

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

NewServicePool 创建服务连接池

func (*ServicePool) AddOrUpdateInstance added in v3.1.16

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

AddOrUpdateInstance 添加或更新一个实例连接 返回 changed=true 表示是新增或重建了 proxy

func (*ServicePool) Close added in v3.1.16

func (p *ServicePool) Close()

Close 关闭所有连接

func (*ServicePool) Get added in v3.1.16

func (p *ServicePool) Get() *ReflectionProxy

Get 获取一个可用的 proxy(round-robin + 健康检查)

func (*ServicePool) RemoveInstance added in v3.1.16

func (p *ServicePool) RemoveInstance(instanceID string)

RemoveInstance 移除一个实例连接

func (*ServicePool) Size added in v3.1.16

func (p *ServicePool) Size() int

Size 返回实例数量

Jump to

Keyboard shortcuts

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