https://github.com/gruyaume/goops
Develop reliable, portable, and fast Juju Charms in Go
https://github.com/gruyaume/goops
charm framework go juju operator
Last synced: about 1 year ago
JSON representation
Develop reliable, portable, and fast Juju Charms in Go
- Host: GitHub
- URL: https://github.com/gruyaume/goops
- Owner: gruyaume
- License: apache-2.0
- Created: 2025-03-27T21:14:25.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-29T23:17:56.000Z (about 1 year ago)
- Last Synced: 2025-03-30T00:20:42.642Z (about 1 year ago)
- Topics: charm, framework, go, juju, operator
- Language: Go
- Homepage: https://pkg.go.dev/github.com/gruyaume/goops
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# goops
> :construction: **Beta Notice**
> goops is in beta. If you encounter any issues, please [report them here](https://github.com/gruyaume/goops/issues).
**Develop Reliable, Portable, and Fast Juju Charms in Go**
`goops` is a Go library for developing robust Juju charms. While charm developers traditionally use the [ops Python framework](https://github.com/canonical/operator), Python's dynamic typing and interpreter-based execution often lead to runtime errors and portability issues across different bases. In contrast, Go compiles to a single, self-contained binary, ensuring greater reliability and consistent behavior in any environment.
## Try it now
### 1. Use the Charmcraft `go` plugin
Use the `go` plugin to build your charm in `charmcraft.yaml`:
```yaml
parts:
charm:
source: .
plugin: go
build-snaps:
- go
organize:
bin/: dispatch
```
### 2. Write your charm
In your charm's root directory, create a `main.go` file under the `cmd/` directory. This file will contain the main logic of your charm. Import the `goops` library and use its functions to interact with Juju. For example:
```go
package main
import (
"os"
"github.com/gruyaume/goops"
"github.com/gruyaume/goops/commands"
)
func main() {
hookContext := goops.NewHookContext()
hookName := hookContext.Environment.JujuHookName()
hookContext.Commands.JujuLog(commands.Info, "Hook name:", hookName)
err := hookContext.Commands.StatusSet(commands.StatusActive, "A happy charm")
if err != nil {
hookContext.Commands.JujuLog(commands.Error, "Could not set status:", err.Error())
os.Exit(0)
}
hookContext.Commands.JujuLog(commands.Info, "Status set to active")
os.Exit(0)
}
```
You can find an example of the library being used in the [certificates charm repository](https://github.com/gruyaume/certificates-operator).
## Design principles
- **Reliability**: Building predictable, robust charms is our top priority.
- **Simplicity**: `goops` serves as a minimal, one-to-one mapping between Juju concepts and Go constructs. It is not a framework; it does not impose charm design patterns. The library has no dependencies.