gateboard

package
v1.10.11 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package gateboard provides library for clients.

This pseudocode illustrates the recommended usage:

// invokeBackend calls a backend http endpoint for a gateway named 'gatewayName'.
// 'client' is created in an wider scope because it caches IDs.
function invokeBackend(client, gatewayName)
    1. get ID := client.GatewayID(gatewayName)
    2. if ID is "" {
           return status code 503
       }
    3. call the backend http endpoint with header "x-apigw-api-id: <id>"
       if backend status code is 403 {
           client.Refresh(gatewayName)
           return status code 503
       }
    4. return backend status code

Index

Constants

View Source
const (
	CacheTTLMinimum = 1 * time.Minute  // CacheTTLMinimum defines min limit for TTL
	CacheTTLMax     = 20 * time.Minute // CacheTTLMax defines max limit for TTL
	CacheTTLDefault = 5 * time.Minute  // CacheTTLDefault defines default value for TTL
)

Variables

This section is empty.

Functions

func NewEnv added in v0.1.0

func NewEnv(sessionName string) *envconfig.Env

NewEnv creates a env context for retrieving parameters.

Types

type BodyGetReply

type BodyGetReply struct {
	GatewayName string    `json:"gateway_name"    yaml:"gateway_name"    bson:"gateway_name"    dynamodbav:"gateway_name"`
	GatewayID   string    `json:"gateway_id"      yaml:"gateway_id"      bson:"gateway_id"      dynamodbav:"gateway_id"`
	Changes     int64     `json:"changes"         yaml:"changes"         bson:"changes"         dynamodbav:"changes"`
	LastUpdate  time.Time `json:"last_update"     yaml:"last_update"     bson:"last_update"     dynamodbav:"last_update"`
	Error       string    `json:"error,omitempty" yaml:"error,omitempty" bson:"error,omitempty" dynamodbav:"error,omitempty"`
	TTL         int       `json:"TTL,omitempty"   yaml:"TTL,omitempty"   bson:"TTL,omitempty"   dynamodbav:"TTL,omitempty"`
	Token       string    `json:"token,omitempty" yaml:"token,omitempty" bson:"token,omitempty" dynamodbav:"token,omitempty"`
}

BodyGetReply defines the payload format for a GET request.

type BodyPutReply

type BodyPutReply struct {
	GatewayName string `json:"gateway_name"    yaml:"gateway_name"`
	GatewayID   string `json:"gateway_id"      yaml:"gateway_id"`
	Error       string `json:"error,omitempty" yaml:"error,omitempty"`
}

BodyPutReply defines the payload format for a PUT response.

type BodyPutRequest

type BodyPutRequest struct {
	GatewayID string `json:"gateway_id"      yaml:"gateway_id"`
	Token     string `json:"token,omitempty" yaml:"token,omitempty"`
}

BodyPutRequest defines the payload format for a PUT request.

type Client

type Client struct {
	TTL time.Duration
	// contains filtered or unexported fields
}

Client holds context for a gateboard client.

func NewClient

func NewClient(options ClientOptions) *Client

NewClient creates a new gateboard client.

func (*Client) GatewayID

func (c *Client) GatewayID(ctx context.Context, gatewayName string) string

GatewayID retrieves the gateway ID for a 'gatewayName' from local fast cache. If the ID is not found in the local fast cache, it will use 'singleflight' to fetch up-to-date data.

func (*Client) Refresh

func (c *Client) Refresh(ctx context.Context, gatewayName string)

Refresh spawns only one refreshJob() goroutine at a time. The async refresh job will attempt to update the local fast cache entry for gatewayName with information retrieved from server.

type ClientOptions

type ClientOptions struct {
	ServerURL  string        // required main centralized server
	TTLMin     time.Duration // optional, if unspecified defaults to CacheTTLMinimum
	TTLMax     time.Duration // optional, if unspecified defaults to CacheTTLMax
	TTLDefault time.Duration // optional, if unspecified defaults to CacheTTLDefault
	Debug      bool          // optional, log debug information
	Tracer     trace.Tracer
}

ClientOptions defines options for the client.

Jump to

Keyboard shortcuts

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