gateway

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultSchemaCacheSize = 1024

DefaultSchemaCacheSize is the number of verified schemas a Client keeps when no explicit size is configured.

Variables

View Source
var ErrSchemaHashMismatch = errors.New("farp gateway: schema content does not match descriptor hash")

ErrSchemaHashMismatch is returned when a schema's content does not hash to the value its descriptor claims.

Functions

func VerifySchemaHash added in v1.14.0

func VerifySchemaHash(schema any, expected string) error

VerifySchemaHash recomputes the SHA-256 checksum of schema with farp.CalculateSchemaChecksum and compares it to expected.

Types

type Client

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

Client is a reference implementation for API gateway integration It watches for service schema changes and provides conversion utilities.

func NewClient

func NewClient(registry farp.SchemaRegistry, opts ...ClientOption) *Client

NewClient creates a new gateway client.

func (*Client) ClearCache

func (c *Client) ClearCache()

ClearCache clears the schema cache.

func (*Client) ConvertToRoutes

func (c *Client) ConvertToRoutes(manifests []*farp.SchemaManifest) []ServiceRoute

ConvertToRoutes converts service manifests to gateway routes This is a reference implementation - actual gateways should customize this.

func (*Client) GetManifest

func (c *Client) GetManifest(instanceID string) (*farp.SchemaManifest, bool)

GetManifest retrieves a cached manifest by instance ID.

func (*Client) WatchServices

func (c *Client) WatchServices(ctx context.Context, serviceName string, onChange func([]ServiceRoute)) error

WatchServices watches for service registrations and schema updates onChange is called whenever services are added, updated, or removed.

type ClientOption added in v1.14.0

type ClientOption func(*Client)

ClientOption configures a Client.

func WithLogger added in v1.14.0

func WithLogger(logger *slog.Logger) ClientOption

WithLogger makes the client log schemas it skips because they could not be fetched or their content did not match the descriptor hash. Without it the client skips them silently.

func WithSchemaCacheSize added in v1.14.0

func WithSchemaCacheSize(n int) ClientOption

WithSchemaCacheSize bounds the number of schemas kept in the client's cache. Values below 1 fall back to DefaultSchemaCacheSize.

type ServiceRoute

type ServiceRoute struct {
	// Path is the route path pattern
	Path string

	// Methods are HTTP methods for this route (e.g., ["GET", "POST"])
	Methods []string

	// TargetURL is the backend service URL
	TargetURL string

	// HealthURL is the health check URL
	HealthURL string

	// Middleware are middleware names to apply
	Middleware []string

	// Metadata contains additional route information
	Metadata map[string]any

	// ServiceName is the name of the backend service
	ServiceName string

	// ServiceVersion is the version of the backend service
	ServiceVersion string
}

ServiceRoute represents a route configuration for the gateway.

Jump to

Keyboard shortcuts

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