work in progress: unify data structures for message payload and server response
This commit is contained in:
parent
efb09c9019
commit
d03b3ab11d
8 changed files with 19 additions and 16 deletions
|
@ -14,7 +14,6 @@ import (
|
|||
|
||||
type Cfg struct {
|
||||
*config.BaseCfg
|
||||
AppType string
|
||||
Home string
|
||||
Logging *logging.Cfg
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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),
|
||||
},
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ type Context interface {
|
|||
|
||||
// message, address
|
||||
|
||||
type Data interface{}
|
||||
|
||||
type MsgHead interface {
|
||||
fmt.Stringer
|
||||
Slice() []string
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Add table
Reference in a new issue