Skip to content

Commit

Permalink
feat(docs): example usage in README
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickkirschen committed Jun 11, 2024
1 parent 42506de commit 1df97ff
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,47 @@ just like Kubernetes with its resources and operators.

> [!WARNING]
> This project is currently under heavy development and not stable.
## Example usage

```yaml
# example/my-manifest.yaml

apiVersion: example.com/v1alpha1
kind: MyManifest

metadata:
name: my-manifest-1

spec:
message: hello, world
```
```go
import "github.com/yannickkirschen/manifesto"

type MySpec struct {
Message string `yaml:"message" json:"message"`
}

func MyListener(pool *manifesto.Pool, action manifesto.Action, manifest manifesto.Manifest) {
// Do something with manifesto
}

func main() {
manifest := manifesto.ParseFile("example/my-manifest-1.yaml", &MySpec{}, &MySpec{})
spec := manifest.Spec.(*MySpec) // Do something with spec

pool := manifesto.CreatePool()
pool.Listen(MyListener)

pool.Apply(manifest) // Calls all listeners
pool.ApplyPartial(MyListener, *manifest) // Calls all listeners, except the specified one
pool.ApplySilent(*manifest) // Does not call any listener at all

key := manifesto.CreateKey() // Based on apiVersion and kind
theManifest, ok := pool.GetByKey(key) // Get the manifest and check existence

pool.Delete(key) // Gets ignored if the key does not exist
}
```

0 comments on commit 1df97ff

Please sign in to comment.