work in progress: unify data structures for message payload and server response

This commit is contained in:
Helmut Merz 2023-08-13 14:44:57 +02:00
parent efb09c9019
commit d03b3ab11d
8 changed files with 19 additions and 16 deletions

View file

@ -14,7 +14,6 @@ import (
type Cfg struct { type Cfg struct {
*config.BaseCfg *config.BaseCfg
AppType string
Home string Home string
Logging *logging.Cfg Logging *logging.Cfg
} }

View file

@ -137,11 +137,13 @@ func Base(name string, starter lib.Proc) *base {
} }
// will be set by core.init() // will be set by core.init()
var DefaultStart lib.Proc var (
var DefaultListen lib.Proc DefaultStart lib.Proc
var DefaultStep lib.Step DefaultListen lib.Proc
var DefaultMsgHandler lib.MessageHandler DefaultStep lib.Step
var DefaultDoneHandler lib.Step DefaultMsgHandler lib.MessageHandler
DefaultDoneHandler lib.Step
)
// action configuration // action configuration

View file

@ -14,7 +14,6 @@ func Config() lib.Config {
app_c := app.Cfg{ app_c := app.Cfg{
BaseCfg: b("dummy", app.Start), BaseCfg: b("dummy", app.Start),
Home: ovr(".", HOME), Home: ovr(".", HOME),
AppType: "standard",
Logging: &logging.Cfg{ Logging: &logging.Cfg{
Logfile: ovr("log/scopes.log", LOGFILE), Logfile: ovr("log/scopes.log", LOGFILE),
}, },

View file

@ -7,7 +7,6 @@ import (
"path/filepath" "path/filepath"
lib "git.sr.ht/~cco/go-scopes" lib "git.sr.ht/~cco/go-scopes"
"git.sr.ht/~cco/go-scopes/config"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
@ -32,7 +31,6 @@ var defaultLogger = log.Logger.Level(InfoLevel)
var globalLogger *Logger = &log.Logger var globalLogger *Logger = &log.Logger
type Cfg struct { type Cfg struct {
*config.BaseCfg
Logfile string Logfile string
Level string Level string
} }

View file

@ -32,6 +32,8 @@ type Context interface {
// message, address // message, address
type Data interface{}
type MsgHead interface { type MsgHead interface {
fmt.Stringer fmt.Stringer
Slice() []string Slice() []string

View file

@ -56,4 +56,4 @@ func MsgHandler(pattern string, proc msgProc, rcvs ...string) *mhSpec {
return &cfg return &cfg
} }
type msgProc func(lib.Context, lib.Message) (int, Data) type msgProc func(lib.Context, lib.Message) (int, lib.Data)

View file

@ -12,7 +12,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
type Data = map[string]interface{} type data = map[string]interface{}
type ServerState struct { type ServerState struct {
server *http.Server server *http.Server
@ -76,10 +76,14 @@ func handleMsg(ctx lib.Context, cfg *mhSpec, gc *gin.Context) {
gc.JSON(code, data) gc.JSON(code, data)
} }
func Async(ctx lib.Context, msg lib.Message) (int, Data) { func Async(ctx lib.Context, msg lib.Message) (int, lib.Data) {
return http.StatusOK, Data{"status": "OK"} return http.StatusOK, data{"status": "OK"}
} }
func Sync(ctx lib.Context, msg lib.Message) (int, Data) { func Sync(ctx lib.Context, msg lib.Message) (int, lib.Data) {
return http.StatusOK, Data{"status": "OK"} select {
case msg := <-ctx.Mailbox():
return http.StatusOK, data(msg.Payload().Data().(map[string]interface{}))
}
return http.StatusOK, data{"status": "OK"}
} }

View file

@ -19,7 +19,6 @@ func Config() lib.Config {
app_c := &app.Cfg{ app_c := &app.Cfg{
BaseCfg: b("testing", testing.Start), BaseCfg: b("testing", testing.Start),
Home: ovr(".", HOME), Home: ovr(".", HOME),
AppType: "standard",
Logging: &logging.Cfg{ Logging: &logging.Cfg{
Logfile: ovr("log/scopes.log", LOGFILE), Logfile: ovr("log/scopes.log", LOGFILE),
Level: ovr("info", LOGLEVEL), Level: ovr("info", LOGLEVEL),