CasaOS - A simple, easy-to-use, elegant open-source Personal Cloud system.
add `message-bus-codegen` CLI tool for generating a markdown of all event types (#1346)
Tiger Wang37fee157dd10
diff --git a/cmd/message-bus-docgen/main.go b/cmd/message-bus-docgen/main.gonew file mode 100644index 0000000..a0649ea--- /dev/null+++ b/cmd/message-bus-docgen/main.go@@ -0,0 +1,28 @@+package main++import (+ "github.com/IceWhaleTech/CasaOS-Common/external"+ "github.com/IceWhaleTech/CasaOS/codegen/message_bus"+ "github.com/IceWhaleTech/CasaOS/common"+ "github.com/samber/lo"+)++func main() {+ eventTypes := lo.Map(common.EventTypes, func(item message_bus.EventType, index int) external.EventType {+ return external.EventType{+ Name: item.Name,+ SourceID: item.SourceID,+ PropertyTypeList: lo.Map(+ item.PropertyTypeList, func(item message_bus.PropertyType, index int) external.PropertyType {+ return external.PropertyType{+ Name: item.Name,+ Description: item.Description,+ Example: item.Example,+ }+ },+ ),+ }+ })++ external.PrintEventTypesAsMarkdown(common.SERVICENAME, common.VERSION, eventTypes)+}diff --git a/common/message.go b/common/message.goindex 5e41a25..6aa6204 100644--- a/common/message.go+++ b/common/message.go@@ -1,23 +1,12 @@package commonimport (- "fmt"-"github.com/IceWhaleTech/CasaOS/codegen/message_bus")-var (- // devtype -> action -> event- EventTypes map[string]map[string]message_bus.EventType-- PropertyNameLookupMaps = map[string]map[string]string{- "system": {- fmt.Sprintf("%s:%s", SERVICENAME, "utilization"): "ID_BUS",- },- }-- ActionPastTense = map[string]string{- "add": "added",- "remove": "removed",- }-)+// devtype -> action -> event+var EventTypes = []message_bus.EventType{+ {Name: "casaos:system:utilization", SourceID: SERVICENAME, PropertyTypeList: []message_bus.PropertyType{}},+ {Name: "casaos:file:recover", SourceID: SERVICENAME, PropertyTypeList: []message_bus.PropertyType{}},+ {Name: "casaos:file:operate", SourceID: SERVICENAME, PropertyTypeList: []message_bus.PropertyType{}},+}diff --git a/go.mod b/go.modindex 6b1a91a..0ce12f4 100644--- a/go.mod+++ b/go.mod@@ -4,7 +4,7 @@ go 1.20require (github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d- github.com/IceWhaleTech/CasaOS-Common v0.4.4-alpha8+ github.com/IceWhaleTech/CasaOS-Common v0.4.7-alpha4github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcfgithub.com/deckarep/golang-set/v2 v2.3.0github.com/deepmap/oapi-codegen v1.12.4@@ -33,6 +33,7 @@ require (github.com/patrickmn/go-cache v2.1.0+incompatiblegithub.com/pkg/errors v0.9.1github.com/robfig/cron/v3 v3.0.1+ github.com/samber/lo v1.38.1github.com/satori/go.uuid v1.2.0github.com/shirou/gopsutil/v3 v3.23.2github.com/sirupsen/logrus v1.9.0@@ -106,7 +107,6 @@ require (github.com/pmezard/go-difflib v1.0.0 // indirectgithub.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirectgithub.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect- github.com/samber/lo v1.38.1 // indirectgithub.com/tidwall/match v1.1.1 // indirectgithub.com/tidwall/pretty v1.2.1 // indirectgithub.com/tklauser/go-sysconf v0.3.11 // indirectdiff --git a/go.sum b/go.sumindex 2055a06..f8bc3e9 100644--- a/go.sum+++ b/go.sum@@ -1,7 +1,7 @@github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d h1:62lEBImTxZ83pgzywgDNIrPPuQ+j4ep9QjqrWBn1hrU=github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d/go.mod h1:lW9x+yEjqKdPbE3+cf2fGPJXCw/hChX3Omi9QHTLFsQ=-github.com/IceWhaleTech/CasaOS-Common v0.4.4-alpha8 h1:UhCg3d9Cxhx7KVmqh8oUrUl1qFmFdcHee3Zkk4+P2JA=-github.com/IceWhaleTech/CasaOS-Common v0.4.4-alpha8/go.mod h1:2IuYyy5qW1BE6jqC6M+tOU+WtUec1K565rLATBJ9p/0=+github.com/IceWhaleTech/CasaOS-Common v0.4.7-alpha4 h1:bsVQ+kdVkmPsqX6lxxETaShiMb9I8OgiR4xrEQ/vyss=+github.com/IceWhaleTech/CasaOS-Common v0.4.7-alpha4/go.mod h1:2IuYyy5qW1BE6jqC6M+tOU+WtUec1K565rLATBJ9p/0=github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=diff --git a/main.go b/main.goindex 8e3cca1..cb527f4 100644--- a/main.go+++ b/main.go@@ -18,7 +18,6 @@ import (util_http "github.com/IceWhaleTech/CasaOS-Common/utils/http"- "github.com/IceWhaleTech/CasaOS/codegen/message_bus""github.com/IceWhaleTech/CasaOS/common""github.com/IceWhaleTech/CasaOS/pkg/cache""github.com/IceWhaleTech/CasaOS/pkg/config"@@ -161,13 +160,10 @@ func main() {panic(err)}}- var events []message_bus.EventType- events = append(events, message_bus.EventType{Name: "casaos:system:utilization", SourceID: common.SERVICENAME, PropertyTypeList: []message_bus.PropertyType{}})- events = append(events, message_bus.EventType{Name: "casaos:file:recover", SourceID: common.SERVICENAME, PropertyTypeList: []message_bus.PropertyType{}})- events = append(events, message_bus.EventType{Name: "casaos:file:operate", SourceID: common.SERVICENAME, PropertyTypeList: []message_bus.PropertyType{}})+// register at message busfor i := 0; i < 10; i++ {- response, err := service.MyService.MessageBus().RegisterEventTypesWithResponse(context.Background(), events)+ response, err := service.MyService.MessageBus().RegisterEventTypesWithResponse(context.Background(), common.EventTypes)if err != nil {logger.Error("error when trying to register one or more event types - some event type will not be discoverable", zap.Error(err))}