state

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ReadStateFile = func(filename string) ([]byte, error) {
	f, err := os.Open(filename)
	if err != nil {

		return []byte(`{"resources":{}}`), nil
	}
	defer f.Close()

	data, err := ioutil.ReadAll(f)
	if err != nil {
		return nil, err
	}

	return data, nil
}
View Source
var SaveStateFile = func(filename string) (io.Writer, error) {
	return os.Create(filename)
}

Functions

func Keys

func Keys(resources []Resource) []string

func Map

func Map(resources []Resource) map[ID]Resource

Types

type ID

type ID = string

ID is to prevent from detecting state changes unexpected by package name changing By using fixed string instead of package name, we can forcus on detecting the changes of only package contents itself.

type Resource

type Resource struct {
	ID      ID       `json:"id"`
	Name    string   `json:"name"`
	Home    string   `json:"home"`
	Type    string   `json:"type"`
	Version string   `json:"version"`
	Paths   []string `json:"paths"`
}

func Slice added in v0.1.16

func Slice(m map[ID]Resource) []Resource

func (Resource) GetResource

func (e Resource) GetResource() Resource

type Resourcer

type Resourcer interface {
	GetResource() Resource
}

type Self

type Self struct {
	Resources map[ID]Resource `json:"resources"`
}

type State

type State struct {
	// State itself of state file
	Self

	// No record in state file
	Additions []Resource

	// Exists in state file but no in config file
	// so maybe users had deleted the package from config file
	Deletions []Resource

	// Something changes happened between config file and state file
	// Currently only version (github.release.tag) is detected as changes
	Changes []Resource

	// All items recorded in state file. It means no changes between state file
	// and config file
	NoChanges []Resource
	// contains filtered or unexported fields
}

func Open

func Open(path string, resourcers []Resourcer) (*State, error)

func (*State) Add

func (s *State) Add(resourcer Resourcer)

func (*State) Get

func (s *State) Get(name string) (Resource, error)

func (*State) List

func (s *State) List() ([]Resource, error)

func (*State) New

func (s *State) New() error

func (*State) Refresh

func (s *State) Refresh() error

func (*State) Remove

func (s *State) Remove(resourcer Resourcer)

func (*State) Update

func (s *State) Update(resourcer Resourcer)

Jump to

Keyboard shortcuts

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