config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config turns a Config file into the Upstream definitions it declares.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(data []byte, lookupEnv LookupEnv) ([]Upstream, []Warning, error)

Parse parses Config bytes into the Upstreams to start, in Config order, plus warnings about the Config. lookupEnv resolves ${VAR} references.

func Path

func Path(flag string, lookupEnv LookupEnv) (path string, named bool, err error)

Path resolves which Config file to read: flag (from -c/--config), then $SPRUT_CONFIG, then $XDG_CONFIG_HOME/sprut/config.json, then ~/.config/sprut/config.json. It reports whether the path was named, by flag or $SPRUT_CONFIG, rather than being the default location.

func XDGDir added in v0.2.0

func XDGDir(lookupEnv LookupEnv, variable, fallback string) (string, bool)

XDGDir returns the base directory that the XDG variable names, or the fallback under $HOME that the XDG spec gives for it. It reports false if neither is set.

Types

type LookupEnv

type LookupEnv func(string) (string, bool)

LookupEnv looks up an environment variable, like os.LookupEnv.

func LookupIn

func LookupIn(env []string) LookupEnv

LookupIn returns a lookup over env, which is in os.Environ form. As with a real environment, the last entry for a key wins.

type OAuth added in v0.2.0

type OAuth struct {
	// A pre-registered client, in place of Dynamic Client Registration.
	ClientID     string
	ClientSecret string
	// The scopes to request, in place of those the Upstream asks for; nil
	// when the Config has none.
	Scopes []string
}

OAuth is how sprut logs in to an OAuth Upstream, where the Config says.

type Transport

type Transport string

Transport is how the Gateway talks to an Upstream.

const (
	Stdio Transport = "stdio"
	HTTP  Transport = "http"
)

type Upstream

type Upstream struct {
	Name      string
	Transport Transport

	// stdio
	Command string
	Args    []string
	Env     map[string]string // layered on top of the inherited environment

	// HTTP
	URL     string
	Headers map[string]string
	OAuth   *OAuth // nil when the Config has no "oauth"

	// ConfigPath is the absolute path of the Config file, which a command
	// run from another shell needs with -c to find it, or "" when it is
	// where sprut looks by default. Parse leaves it empty.
	ConfigPath string
}

Upstream is one resolved Upstream definition from the Config.

type Warning

type Warning struct {
	Upstream string
	Message  string
}

Warning is a problem in the Config that does not stop the Gateway.

Jump to

Keyboard shortcuts

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