config

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package config provides a parser for a JSON configuration file format used to configure Tarmac functions and services.

Index

Constants

This section is empty.

Variables

View Source
var ErrRouteNotFound = fmt.Errorf("route not found")

ErrRouteNotFound is returned when a requested route is not found in the service's route configuration.

Functions

This section is empty.

Types

type Config

type Config struct {
	sync.RWMutex

	// Services maps the names of Tarmac services to their configurations, which include the set of functions they provide
	// and the routes by which they can be invoked.
	Services map[string]Service `json:"services"`
	// contains filtered or unexported fields
}

Config is a struct that represents the parsed configuration file. It contains a map of Tarmac Services, where each Service is identified by a unique string key.

func Parse

func Parse(filepath string) (*Config, error)

Parse function reads the file specified and attempts to parse the contents into a Config instance.

func (*Config) RouteLookup

func (cfg *Config) RouteLookup(key string) (string, error)

RouteLookup searches the routes map for a given key and returns the corresponding function name if the key is found,

or an empty string and an error if it is not found.

type Function

type Function struct {
	// Filepath to the WASM function
	Filepath string `json:"filepath"`

	// PoolSize defines the number of instances of the function to create
	PoolSize int `json:"pool_size"`
}

Function defines the Tarmac function to load and execute.

type Route

type Route struct {
	// Type defines the protocol used for the route, examples are "http", "nats", "scheduled_task", etc.
	Type string `json:"type"`

	// Path defines the path for HTTP types.
	Path string `json:"path,omitempty"`

	// Topic defines the topic or channel to listen to for message queue based routes.
	Topic string `json:"topic,omitempty"`

	// Methods defines the HTTP methods to accept for the defined route.
	Methods []string `json:"methods,omitempty"`

	// Function defines the Function to execute when this route is called.
	Function string `json:"function"`

	// Frequency is used to define the frequency of scheduled_task routes in seconds.
	Frequency int `json:"frequency,omitempty"`
}

Route defines available routes for the service.

type Service

type Service struct {
	// Name is the human-readable name for the service.
	Name string `json:"name"`

	// Functions is a map of Function objects, where the keys are string identifiers for each function.
	Functions map[string]Function `json:"functions"`

	// Routes is a slice of Route objects representing the available routes for this service.
	Routes []Route `json:"routes"`
}

Service defines a Tarmac service, which consists of a Name, a set of Functions, and a collection of available Routes.

Jump to

Keyboard shortcuts

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