Help us shape the future of Go! Take the 2026 Go Developer Survey

store

package
v0.1.65 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package store resolves named connections from typed Connection resources (connection/crd) kept as files, in layers a later one of which overrides an earlier one by name: by default the connections every Flanksource tool shares, then an app's own, then the working directory's. A Store attached to a context (Attach) answers connection:// references before the connections table does.

Index

Constants

View Source
const (
	LayerGlobal = "global"
	LayerApp    = "app"
	LayerCWD    = "cwd"
)

Default layer names.

View Source
const GlobalApp = "flanksource"

GlobalApp is the config dir name the connections every Flanksource tool shares live under.

Variables

This section is empty.

Functions

func ConfigDir

func ConfigDir(name string) (string, error)

ConfigDir is name's config dir: $XDG_CONFIG_HOME/name when that is set, otherwise ~/.config/name on every platform.

Types

type Entry

type Entry struct {
	Layer      Layer
	Path       string
	Connection models.Connection
	// Problem is why the file does not define a usable connection; the
	// connection then carries it in Warnings, and hydrating it fails.
	Problem error
}

Entry is one connection a layer's file defines.

type Layer

type Layer struct {
	// Name identifies the layer, such as "global", "app" or "cwd".
	Name string
	Dir  string
}

Layer is a directory of connection files.

func DefaultLayers

func DefaultLayers(app string) ([]Layer, error)

DefaultLayers are the connections every Flanksource tool shares (<config>/flanksource/connections), then app's own (<config>/<app>/connections), then the working directory's (./.connections), each overriding the one before.

type Store

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

Store is the connections its layers' files define, a later layer's connection replacing an earlier one's of the same namespace and name. It reads the files on every call, so an edit applies at once.

func New

func New(layers ...Layer) (*Store, error)

New is the store over layers, in override order.

func Open

func Open(app string) (*Store, error)

Open is the store over DefaultLayers(app).

func (*Store) Attach

func (s *Store) Attach(ctx dbcontext.Context) dbcontext.Context

Attach is ctx answering connection references from the store first, then from the resolver ctx already had, then from the connections table.

func (*Store) Delete

func (s *Store) Delete(layer, reference string) error

Delete removes the file in layer that defines the connection reference names; one the layer does not define is os.ErrNotExist.

func (*Store) Entries

func (s *Store) Entries() ([]Entry, error)

Entries are the entries in effect, by namespace and name, each with the layer and file that define it.

func (*Store) Find

func (s *Store) Find(reference string) (*Entry, error)

Find is the entry in effect that reference names, with the layer and file that define it, on the terms of ResolveConnection: (nil, nil) for a reference the store does not define.

func (*Store) Layers

func (s *Store) Layers() []Layer

Layers are the store's layers, in override order.

func (*Store) ListConnections

func (s *Store) ListConnections() ([]*models.Connection, error)

ListConnections are the connections in effect, by namespace and name.

func (*Store) ResolveConnection

func (s *Store) ResolveConnection(_ dbcontext.Context, reference string) (*models.Connection, error)

ResolveConnection is the connection reference names: its id, connection://name, connection://namespace/name, the deprecated connection://type/namespace/name, or a bare name. A connection with no namespace answers any namespace a reference names that defines no connection of that name. It is (nil, nil) for a reference the store does not define, and an error for a name more than one namespace defines. A file that defines no usable connection resolves to a connection carrying the problem in Warnings, which dbcontext.HydrateConnection refuses to use. It is a dbcontext.ConnectionResolver.

func (*Store) Save

func (s *Store) Save(layer string, resource *crd.Connection) error

Save writes resource into layer, over the file that already defines its namespace and name there, else as <name>.yaml.

Jump to

Keyboard shortcuts

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