Ensure is a small library to build a configuration management system in go.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Gibheer 7229ba2f5c fix comparison value for file content 6 months ago
exec initial commit 6 months ago
file fix comparison value for file content 6 months ago
LICENSE add license file 6 months ago
README.md add Readme too 6 months ago
go.mod initial commit 6 months ago
main.go switch around the WithCheck function 6 months ago
runner.go fix package name 6 months ago
runner_test.go fix package name 6 months ago

README.md

ensure

Ensure is a small library to help ensure state on a UNIX system. It is currently pretty basic and doesn’t have much to offer apart from a file/directory and exec helper.

But with these small pieces more should easily be possible and go offers more than enough to implement other functions on top of the ensurer interface and the runner to ensure the state.

how to use

To use this library use one of the provided resources or implement one yourself with the Ensurer interface.

Either call Ensure on the resource yourself or let one of the runners do it for all your resources.

package main

import (
  "io/ioutil"
  "os"
  "path"

  "git.zero-knowledge.org/gibheer/ensure"
  "git.zero-knowledge.org/gibheer/ensure/file"
)

func main() {
  tmpDir, _ := ioutil.TempDir("", "")
  defer os.RemoveAll(tmpDir)
  f := &file.F{
    Path: path.Join(tmpDir, "test")
  }
  if !f.Is() {
    if err := f.Ensure(); err != nil {
      fmt.Fatalf("could not ensure file: %s\n", err)
    }
  }

  // Use a runner to ensure multiple resources blocked by a check.
  // In case of the runner, ensure will also run Is() before making changes.
  // Better read the documentation, not all resources do that or can do that.
  r := &ensure.Runner{
    States: []ensure.Ensurer{f},
    Is: f.Is,
  }
  if err := r.Ensure(); err != nil {
    fmt.Fatalf("could not ensure directory: %s", err)
  }
}