Ensure is a small library to build a configuration management system in go.
Go to file
Gibheer 7229ba2f5c fix comparison value for file content
The comparison of the wanted and current file content was wrong.
2020-04-21 21:48:20 +02:00
exec initial commit 2020-04-21 20:12:47 +02:00
file fix comparison value for file content 2020-04-21 21:48:20 +02:00
LICENSE add license file 2020-04-21 20:23:40 +02:00
README.md add Readme too 2020-04-21 20:22:10 +02:00
go.mod initial commit 2020-04-21 20:12:47 +02:00
main.go switch around the WithCheck function 2020-04-21 21:23:44 +02:00
runner.go fix package name 2020-04-21 20:38:12 +02:00
runner_test.go fix package name 2020-04-21 20:38:12 +02:00

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)
  }
}