Documentation
¶
Overview ¶
Package gateway provides a peer mesh for service discovery and HTTP forwarding. Its leases do not provide metadata consensus or leader election.
Index ¶
- Constants
- func Join(ctx context.Context, gateway, target, key string) error
- func ServiceEndpoint(gateway, kind, id string) (string, error)
- type AuthorityTerm
- type Config
- type Gateway
- func (g *Gateway) Close() error
- func (g *Gateway) Join(ctx context.Context, target string) error
- func (g *Gateway) Register(r Registration) (Service, error)
- func (g *Gateway) Run(ctx context.Context) error
- func (g *Gateway) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (g *Gateway) State() State
- func (g *Gateway) String() string
- type Registration
- type Service
- type State
Constants ¶
const ( ProtocolVersion = 1 ManagementPrefix = "/v1/gateway/" KeyHeader = "X-Cpfs-Mesh-Key" HopHeader = "X-Cpfs-Gateway-Hops" )
const ( ForwardTimeHeader = "X-Cpfs-Forward-Time" ForwardSignatureHeader = "X-Cpfs-Forward-Signature" )
const ServicePrefix = "/v1/services/"
Variables ¶
This section is empty.
Functions ¶
func ServiceEndpoint ¶
ServiceEndpoint addresses one physical service through a gateway. Append the existing service path (for example /v1/control) to this base. Exact routes may reach followers for authenticated Raft replication; they grant no authority.
Types ¶
type AuthorityTerm ¶
type Config ¶
type Config struct {
Advertise, StatePath, Upstream, ClusterID, Key string
Region string
Peers []string
// OnPeers persists an updated peer set before it becomes visible. It runs
// serially under the gateway lock and must not call back into the gateway.
// Use either this callback or StatePath, never both.
OnPeers func([]string) error
Lease, SyncInterval, Timeout time.Duration
MaxPeers, MaxServices int
}
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway owns its anti-entropy loop and HTTP transport. The enclosing HTTP server/listener (including upgraded sockets) remains the caller's property.
type Registration ¶
type Registration struct {
ID string `json:"id"`
Kind string `json:"kind"`
Endpoint string `json:"endpoint"`
ClusterID string `json:"cluster_id"`
Role string `json:"role,omitempty"`
Epoch uint64 `json:"epoch,omitempty"`
Term uint64 `json:"term,omitempty"`
Region string `json:"region,omitempty"`
TTL time.Duration `json:"ttl,omitempty"`
}
Registration contains a service's current address and authority role. Meta roles and epochs come from its existing authority, never a mesh election.
type Service ¶
type Service struct {
ID string `json:"id"`
Kind string `json:"kind"`
Endpoint string `json:"endpoint"`
ClusterID string `json:"cluster_id"`
Role string `json:"role,omitempty"`
Epoch uint64 `json:"epoch,omitempty"`
Term uint64 `json:"term,omitempty"`
Region string `json:"region,omitempty"`
Owner string `json:"owner"`
Version uint64 `json:"version"`
Expires time.Time `json:"expires"`
}
Service is an origin-stamped lease. Exchanging it never extends Expires.
type State ¶
type State struct {
Version int `json:"version"`
Address string `json:"address"`
ClusterID string `json:"cluster_id,omitempty"`
Region string `json:"region,omitempty"`
Peers []string `json:"peers"`
Services []Service `json:"services"`
// Authorities remembers observed leadership generations, independently of
// lease expiry. It suppresses routing to an older leader, not elects one.
Authorities map[string]AuthorityTerm `json:"authorities,omitempty"`
}