state

package
v1.23.3 Latest Latest
Warning

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

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

Documentation

Overview

Package state provides a simple framework to handle states from a storage.

The types.State interface represents the main interface for the interaction with states.

The types.StateStorage interface represents the interface to read and write states from a storage e.g. a file. At the moment the implementation for YAML files is done but any other type could be provided too.

Example Usage

import (
	"github.com/ddev/ddev/pkg/config/state/storage/yaml"
)

type MyState struct {
	BoolField   bool   `yaml:"bool_field"`
	StringField string `yaml:"string_field,omitempty"`
}

state := yaml.NewState(filepath.Join("config", "state.yml"))

myState := MyState{}

// Retrieve state, Get() implicitly calls Load()
err := state.Get("my_state", &myState)
if err != nil {
	// add error handling
}

// Access state fields
printf("Value of BoolField is: %v", myState.BoolField)
printf("Value of StringField is: %v", myState.StringField)

// Update states
myState.BoolField = true
myState.StringField = "New value for string field"

err := state.Set("my_state", myState)
if err != nil {
	// add error handling
}

// Save state to file
err := state.Save()
if err != nil {
	// add error handling
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(storage types.StateStorage) types.State

New returns a new State interface to get and set states based on the stateManager implementation bellow. The 'storage' parameter defines the storage to be used to read and write states from and to.

Types

This section is empty.

Directories

Path Synopsis
storage

Jump to

Keyboard shortcuts

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