store

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package store keeps the saved state of sites: one SQLite database per site in the data directory (see docs/adr/0002 and 0003). The process that runs a site writes to its database; other commands read it, or change it while the site is not running.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSite = errors.New("the site has no saved state")

ErrNoSite is returned when a site has no saved state.

Functions

func Delete

func Delete(dataDir, siteName string) error

Delete wipes the saved state of a site, and its log.

func Exists

func Exists(dataDir, siteName string) bool

Exists reports whether the site has saved state.

func LogPath

func LogPath(dataDir, siteName string) string

LogPath returns the file a site logs to. When it is full it is rotated to files of the same name with a number added.

func OutputPath

func OutputPath(dataDir, siteName string) string

OutputPath returns the file that takes what the background process of a site prints, which is only what goes wrong with the process itself.

func Path

func Path(dataDir, siteName string) string

Path returns the database file of the site with the given name.

Types

type Change

type Change struct {
	// Put creates chargers or replaces their name, power and spec. The
	// state of an existing charger is kept.
	Put []Charger
	// Reset wipes the state of chargers, which keep their name.
	Reset []string
	// Remove deletes chargers.
	Remove []string
}

Change is a set of changes to a site's chargers that is applied as a whole or not at all.

type Charger

type Charger struct {
	// ID is the charge point ID.
	ID   string
	Name string
	// Power says whether the charger is to be powered on when the site's
	// process starts.
	Power bool
	Spec  Spec
	// State is nil for a charger that has never run.
	State *charger.State
}

Charger is a saved charger.

type Meta

type Meta struct {
	Name string `json:"name"`
	// File is the site file the site was last brought up from. It is empty
	// for the implicit site of "plugyard run".
	File string `json:"file,omitempty"`
	// Implicit marks the site of a charger started with "plugyard run".
	Implicit bool `json:"implicit,omitempty"`
	// Down says the site was taken down: its chargers are no longer listed,
	// though their state is kept.
	Down        bool                    `json:"down,omitempty"`
	Speed       float64                 `json:"speed,omitempty"`
	ConnectRate float64                 `json:"connectRate,omitempty"`
	EVs         map[string]ev.Overrides `json:"evs,omitempty"`
	// LogMaxSize and LogFiles cap the site's log: at most LogFiles files of
	// LogMaxSize bytes. Zero stands for the defaults.
	LogMaxSize int64 `json:"logMaxSize,omitempty"`
	LogFiles   int   `json:"logFiles,omitempty"`
	// AllowUploads lists the hosts diagnostics may be uploaded to besides
	// the machine the CSMS is on.
	AllowUploads []string `json:"allowUploads,omitempty"`
	// UploadsInsecureSkipVerify turns off the check of the certificate of
	// an https or ftps server diagnostics are uploaded to.
	UploadsInsecureSkipVerify bool `json:"uploadsInsecureSkipVerify,omitempty"`
}

Meta is what is saved about a site as a whole.

type Site

type Site struct {
	Meta     Meta
	Chargers []Charger
}

Site is the saved state of a whole site.

func All

func All(dataDir string) ([]Site, error)

All reads the saved state of every site in the data directory, sorted by site name.

type Spec

type Spec struct {
	Model              *model.Model `json:"model"`
	CSMSURL            string       `json:"csmsUrl"`
	InsecureSkipVerify bool         `json:"insecureSkipVerify,omitempty"`
	// HasPassword says the charger authenticates with a password. The
	// password itself is never saved.
	HasPassword bool `json:"hasPassword,omitempty"`
	// EV names the EV preset used when a plug does not name one.
	EV string `json:"ev,omitempty"`
}

Spec is the snapshot of the files a charger was created from.

type Store

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

Store is the open database of one site.

func Open

func Open(dataDir, siteName string) (*Store, error)

Open opens the saved state of a site, creating it when the site has none.

func OpenExisting

func OpenExisting(dataDir, siteName string) (*Store, error)

OpenExisting opens the saved state of a site, or returns ErrNoSite.

func OpenMemory

func OpenMemory(siteName string) (*Store, error)

OpenMemory returns a store that keeps nothing on disk, for a charger that is to leave no trace.

func (*Store) Apply

func (st *Store) Apply(change Change) error

Apply makes a set of changes.

func (*Store) Chargers

func (st *Store) Chargers() ([]Charger, error)

Chargers returns the site's chargers, sorted by charge point ID.

func (*Store) Close

func (st *Store) Close() error

Close flushes pending saves and closes the database.

func (*Store) Load

func (st *Store) Load() (Site, error)

Load reads the whole saved state of the site.

func (*Store) LoadState

func (st *Store) LoadState(id string) (*charger.State, error)

LoadState returns the saved state of a charger, or nil if it has never run.

func (*Store) Meta

func (st *Store) Meta() (Meta, error)

Meta returns what is saved about the site as a whole.

func (*Store) Remove

func (st *Store) Remove(id string) error

Remove deletes a charger and its state.

func (*Store) SaveState

func (st *Store) SaveState(id string, state charger.State) error

SaveState saves the state of a charger and returns once it is on disk.

func (*Store) SetMeta

func (st *Store) SetMeta(meta Meta) error

SetMeta replaces what is saved about the site as a whole.

func (*Store) SetPower

func (st *Store) SetPower(ids []string) error

SetPower marks which chargers are to be powered on when the site's process starts: the given ones, or all of them when ids is nil.

Jump to

Keyboard shortcuts

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