8000 GitHub - gruyaume/goops at v0.0.4
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

gruyaume/goops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goops

🚧 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.

Try it now

1. Use the Charmcraft go plugin

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

2. Write your charm

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.

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.

About

Develop reliable, portable, and fast Juju Charms in Go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages

0