From d03b3ab11dff70978a9d6fde9f767192a629c944 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Sun, 13 Aug 2023 14:44:57 +0200 Subject: [PATCH] work in progress: unify data structures for message payload and server response --- app/app.go | 1 - config/config.go | 12 +++++++----- examples/demo/etc/etc.go | 1 - logging/logging.go | 2 -- scopes.go | 2 ++ server/config.go | 2 +- server/server.go | 14 +++++++++----- tests/etc/etc.go | 1 - 8 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/app.go b/app/app.go index 23e1e1e..d4483a7 100644 --- a/app/app.go +++ b/app/app.go @@ -14,7 +14,6 @@ import ( type Cfg struct { *config.BaseCfg - AppType string Home string Logging *logging.Cfg } diff --git a/config/config.go b/config/config.go index 2d23692..efe447d 100644 --- a/config/config.go +++ b/config/config.go @@ -137,11 +137,13 @@ func Base(name string, starter lib.Proc) *base { } // will be set by core.init() -var DefaultStart lib.Proc -var DefaultListen lib.Proc -var DefaultStep lib.Step -var DefaultMsgHandler lib.MessageHandler -var DefaultDoneHandler lib.Step +var ( + DefaultStart lib.Proc + DefaultListen lib.Proc + DefaultStep lib.Step + DefaultMsgHandler lib.MessageHandler + DefaultDoneHandler lib.Step +) // action configuration diff --git a/examples/demo/etc/etc.go b/examples/demo/etc/etc.go index c97897b..79613fa 100644 --- a/examples/demo/etc/etc.go +++ b/examples/demo/etc/etc.go @@ -14,7 +14,6 @@ func Config() lib.Config { app_c := app.Cfg{ BaseCfg: b("dummy", app.Start), Home: ovr(".", HOME), - AppType: "standard", Logging: &logging.Cfg{ Logfile: ovr("log/scopes.log", LOGFILE), }, diff --git a/logging/logging.go b/logging/logging.go index 09f8255..011d0c9 100644 --- a/logging/logging.go +++ b/logging/logging.go @@ -7,7 +7,6 @@ import ( "path/filepath" lib "git.sr.ht/~cco/go-scopes" - "git.sr.ht/~cco/go-scopes/config" "github.com/rs/zerolog" "github.com/rs/zerolog/log" ) @@ -32,7 +31,6 @@ var defaultLogger = log.Logger.Level(InfoLevel) var globalLogger *Logger = &log.Logger type Cfg struct { - *config.BaseCfg Logfile string Level string } diff --git a/scopes.go b/scopes.go index 6965a92..2abc017 100644 --- a/scopes.go +++ b/scopes.go @@ -32,6 +32,8 @@ type Context interface { // message, address +type Data interface{} + type MsgHead interface { fmt.Stringer Slice() []string diff --git a/server/config.go b/server/config.go index a4bb292..8a34559 100644 --- a/server/config.go +++ b/server/config.go @@ -56,4 +56,4 @@ func MsgHandler(pattern string, proc msgProc, rcvs ...string) *mhSpec { return &cfg } -type msgProc func(lib.Context, lib.Message) (int, Data) +type msgProc func(lib.Context, lib.Message) (int, lib.Data) diff --git a/server/server.go b/server/server.go index 3bb34db..358422d 100644 --- a/server/server.go +++ b/server/server.go @@ -12,7 +12,7 @@ import ( "github.com/gin-gonic/gin" ) -type Data = map[string]interface{} +type data = map[string]interface{} type ServerState struct { server *http.Server @@ -76,10 +76,14 @@ func handleMsg(ctx lib.Context, cfg *mhSpec, gc *gin.Context) { gc.JSON(code, data) } -func Async(ctx lib.Context, msg lib.Message) (int, Data) { - return http.StatusOK, Data{"status": "OK"} +func Async(ctx lib.Context, msg lib.Message) (int, lib.Data) { + return http.StatusOK, data{"status": "OK"} } -func Sync(ctx lib.Context, msg lib.Message) (int, Data) { - return http.StatusOK, Data{"status": "OK"} +func Sync(ctx lib.Context, msg lib.Message) (int, lib.Data) { + select { + case msg := <-ctx.Mailbox(): + return http.StatusOK, data(msg.Payload().Data().(map[string]interface{})) + } + return http.StatusOK, data{"status": "OK"} } diff --git a/tests/etc/etc.go b/tests/etc/etc.go index 6e844be..9addc00 100644 --- a/tests/etc/etc.go +++ b/tests/etc/etc.go @@ -19,7 +19,6 @@ func Config() lib.Config { app_c := &app.Cfg{ BaseCfg: b("testing", testing.Start), Home: ovr(".", HOME), - AppType: "standard", Logging: &logging.Cfg{ Logfile: ovr("log/scopes.log", LOGFILE), Level: ovr("info", LOGLEVEL),