From 764a084f8385dfb6eaf4ec359c00dd025caab377 Mon Sep 17 00:00:00 2001 From: Ash Keel Date: Sun, 5 Nov 2023 13:34:33 +0100 Subject: [PATCH] docs: add doc for strimertul meta keys --- app.go | 14 ++++-------- docs/init.go | 2 ++ docs/strimertul.go | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 docs/strimertul.go diff --git a/app.go b/app.go index 27c54ba..e621889 100644 --- a/app.go +++ b/app.go @@ -109,7 +109,7 @@ func (a *App) startup(ctx context.Context) { } // Set meta keys - _ = a.db.PutKey("strimertul/version", appVersion) + _ = a.db.PutKey(docs.VersionKey, appVersion) a.ready.Set(true) runtime.EventsEmit(ctx, "ready", true) @@ -176,20 +176,14 @@ func (a *App) initializeComponents() error { return nil } -type ExternalLog struct { - Level string `json:"level"` - Message string `json:"message"` - Data map[string]any `json:"data"` -} - func (a *App) listenForLogs() (error, database.CancelFunc) { - return a.db.SubscribeKey("strimertul/@log", func(newValue string) { - var entry ExternalLog + return a.db.SubscribeKey(docs.LogRPCKey, func(newValue string) { + var entry docs.ExternalLog if err := json.Unmarshal([]byte(newValue), &entry); err != nil { return } - level, err := zapcore.ParseLevel(entry.Level) + level, err := zapcore.ParseLevel(string(entry.Level)) if err != nil { level = zapcore.InfoLevel } diff --git a/docs/init.go b/docs/init.go index b9a89d8..bfdfb7f 100644 --- a/docs/init.go +++ b/docs/init.go @@ -26,8 +26,10 @@ func addKeys(keyMap interfaces.KeyMap) { func init() { // Put all enums here utils.MergeMap(Enums, twitch.Enums) + utils.MergeMap(Enums, enums) // Put all keys here + addKeys(strimertulKeys) addKeys(twitch.Keys) addKeys(loyalty.Keys) addKeys(webserver.Keys) diff --git a/docs/strimertul.go b/docs/strimertul.go new file mode 100644 index 0000000..ee5184d --- /dev/null +++ b/docs/strimertul.go @@ -0,0 +1,57 @@ +package docs + +import ( + "reflect" + + "github.com/strimertul/strimertul/docs/interfaces" +) + +// Documentation stuff, keep updated at all times + +const ( + VersionKey = "strimertul/version" + LogRPCKey = "strimertul/@log" +) + +type ExternalLog struct { + // Log level + Level ExternalLogLevel `json:"level"` + + // Log message + Message string `json:"message"` + + // Additional data as non-nested dictionary + Data map[string]any `json:"data"` +} + +type ExternalLogLevel string + +const ( + ExternalLogLevelDebug ExternalLogLevel = "debug" + ExternalLogLevelInfo ExternalLogLevel = "info" + ExternalLogLevelWarn ExternalLogLevel = "warn" + ExternalLogLevelError ExternalLogLevel = "error" +) + +var enums = interfaces.EnumMap{ + "ExternalLogLevel": interfaces.Enum{ + Values: []any{ + ExternalLogLevelDebug, + ExternalLogLevelInfo, + ExternalLogLevelWarn, + ExternalLogLevelError, + }, + }, +} + +var strimertulKeys = interfaces.KeyMap{ + VersionKey: interfaces.KeyDef{ + Description: "Strimertul version (semantic version, e.g. v3.4.0-alpha.1)", + Type: reflect.TypeOf(""), + }, + LogRPCKey: interfaces.KeyDef{ + Description: "Add a log entry", + Type: reflect.TypeOf(ExternalLog{}), + Tags: []interfaces.KeyTag{interfaces.TagRPC}, + }, +}