🚧 Beta Notice goops is in beta. If you encounter any issues, please report them here.
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, 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.
Use the go
plugin to build your charm in charmcraft.yaml
:
parts:
charm:
source: .
plugin: go
build-snaps:
- go
organize:
bin/<your-charm-name>: dispatch
In your charm's root directory, create a main.go
file under the cmd/<your-charm-name>
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:
package main
import (
"os"
"github.com/gruyaume/goops/commands"
"github.com/gruyaume/goops/environment"
)
func main() {
hookCommand := &commands.HookCommand{}
execEnv := &environment.ExecutionEnvironment{}
logger := commands.NewLogger(hookCommand)
hookName := environment.JujuHookName(execEnv)
logger.Info("Hook name:", hookName)
err := commands.StatusSet(hookCommand, commands.StatusActive)
if err != nil {
logger.Error("Could not set status:", err.Error())
os.Exit(0)
}
logger.Info("Status set to active")
os.Exit(0)
}
You can find an example of the library being used in the certificates charm repository.
- 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.