How-to manage config¶
Juju users can configure charms using the juju config
command. Here we cover how you can use goops
to read those configuration options in your charm.
1. Declare configuration options¶
Declare the configuration options in you charm's charmcraft.yaml
file. For example:
config:
options:
username:
type: string
default: gruyaume
description: >
Example configuration option for this charm.
Note
For more information on the charmcraft.yaml
charm definition, read the official charmcraft documentation.
2. Read configuration options¶
You can read the configuration options in your charm using GetConfig()
:
package charm
import (
"fmt"
"github.com/gruyaume/goops"
)
type Config struct {
Username string `json:"username"`
}
func Configure() error {
c := Config{}
err := goops.GetConfig(&c)
if err != nil {
return fmt.Errorf("could not get config: %w", err)
}
goops.LogInfof("Configuring charm with username: %s", c.Username)
return nil
}