Skip to content

Instantly share code, notes, and snippets.

View ripienaar's full-sized avatar

R.I.Pienaar ripienaar

View GitHub Profile
% choria buildinfo -D
....
Compile time module dependencies:
github.com/AlecAivazis/survey/v2 v2.0.5
github.com/OneOfOne/xxhash v1.2.3
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4
github.com/beorn7/perks v1.0.1
github.com/cespare/xxhash/v2 v2.1.1
diff --git a/goss/client/client.go b/goss/client/client.go
index 04d7d96..c679ae6 100644
--- a/goss/client/client.go
+++ b/goss/client/client.go
@@ -11,6 +11,7 @@ import (
"context"
"github.com/choria-io/go-choria/choria"
+ coreclient "github.com/choria-io/go-choria/client/client"
"github.com/choria-io/go-choria/config"
@ripienaar
ripienaar / docstrings.go
Created February 13, 2020 13:55
20200213_choria_config_blog
package config
var docStrings = map[string]string{
"loglevel": "The lowest level log to add to the logfile",
"logfile": "The file to write logs to, when set to an empty string logging will be to the console",
}
@ripienaar
ripienaar / config.go
Created February 13, 2020 13:55
20200213_choria_config_blog
type Config struct {
// LogLevel is the logging level
//
// @doc The lowest level log to add to the logfile
LogLevel string `confkey:"loglevel" default:"info" validate:"enum=debug,info,warn,error,fatal" deprecated:"1" url:"http://example.com"`
// The file to write logs to, when set to an empty string logging will be to the console
LogFile string `confkey:"logfile" type:"path_string" description:"The log file"`
}
@ripienaar
ripienaar / confkey_keydoc.go
Created February 13, 2020 13:51
20200213_choria_config_blog
c := &Config{}
doc := confkey.KeyDoc(c, "loglevel", "Config")
// Description of the field, also have Type(), URL(), Default(), Validation(),
// Deprecate(), Environment(), ConfigKey() and StructKey()
fmt.Printf("Description: %s\n", doc.Description())
@ripienaar
ripienaar / confkey_set.go
Created February 13, 2020 13:49
20200213_choria_config_blog
c := &Config{}
// Initialize the struct with default values
err := confkey.SetStructDefaults(c)
panicIfErr(err)
// Next we have to set complex types - number, bool, slices etc - from strings as the data comes from the configuration file as text
// the conversions are all handled by the confkey package
// Set the value in the struct for whatever field matches the key loglevel
@ripienaar
ripienaar / config.go
Created February 13, 2020 13:47
20200213_choria_config_blog_1.go
type Config struct {
// LogLevel is the logging level
//
// @doc The lowest level log to add to the logfile
LogLevel string `confkey:"loglevel" default:"info" validate:"enum=debug,info,warn,error,fatal" deprecated:"1" url:"http://example.com"`
// The file to write logs to, when set to an empty string logging will be to the console
LogFile string `confkey:"logfile" type:"path_string" description:"The log file"`
Servers []string `confkey:"servers" type:"comma_split" environment:"SERVERS"` // Servers to connect to
@ripienaar
ripienaar / gen.go
Last active February 13, 2020 13:56
20200213_choria_config_blog
// reads config.go and includes parsing of comments
d, err := parser.ParseFile(token.NewFileSet(), "config.go", nil, parser.ParseComments)
panicIfErr(err)
ast.Inspect(d, func(n ast.Node) bool {
// this function filters and parses the ast, return false to stop descending into a
// branch of the AST, so we skip over everything till we reach Config struct
switch t := n.(type) {
case *ast.TypeSpec:
@ripienaar
ripienaar / main.go
Last active February 10, 2020 12:05
$ go run main.go
Config.Registration: doc: "The plugin to use for sending Registration data, when this is unset or empty sending registration data is disabled "
broker {
network {
listen_address = "0.0.0.0"
client_port = 4222
client_tls_required = true
peer_port = 5222
peers = [
"nats://p1.example.net:5222"
]
}