server message handling: simplify, with hard-coded Forward action
This commit is contained in:
parent
399b3576b0
commit
d1732dd851
3 changed files with 9 additions and 9 deletions
|
@ -3,7 +3,7 @@ package server
|
|||
import (
|
||||
lib "git.sr.ht/~cco/go-scopes"
|
||||
"git.sr.ht/~cco/go-scopes/config"
|
||||
"git.sr.ht/~cco/go-scopes/core"
|
||||
"git.sr.ht/~cco/go-scopes/core/action"
|
||||
)
|
||||
|
||||
type Cfg struct {
|
||||
|
@ -41,6 +41,8 @@ func FileServer(docRoot string) *fsSpec {
|
|||
return &fsSpec{docRoot}
|
||||
}
|
||||
|
||||
func MsgHandler() lib.Config {
|
||||
return config.Base("", core.Start)
|
||||
func MsgHandler(pattern string, rcvs ...string) lib.Config {
|
||||
cfg := config.Base("", nil)
|
||||
cfg.AddAction(pattern, action.Base(action.Forward, rcvs...))
|
||||
return cfg
|
||||
}
|
||||
|
|
|
@ -61,10 +61,10 @@ func setRoute(ctx lib.Context, rcfg routeCfg, r *gin.Engine) {
|
|||
|
||||
func handle(ctx lib.Context, cfg lib.Config, gc *gin.Context) {
|
||||
head := strings.Split(gc.Param("msg"), "/")[1:]
|
||||
msg := message.New(head...)
|
||||
//fmt.Printf("*** RCell called: msg: %+v, method: %s\n", msg, gc.Request.Method)
|
||||
cctx := ctx.ChildContext(cfg)
|
||||
msg := message.New(head...).WithSender(cctx)
|
||||
//fmt.Printf("*** RCell called: msg: %+v, method: %s\n", msg, gc.Request.Method)
|
||||
core.HandleMessage(cctx, msg)
|
||||
// cfg.Starter()(cctx)
|
||||
// if cfg.sync: wait for response message
|
||||
gc.String(http.StatusOK, "Hello World")
|
||||
}
|
||||
|
|
|
@ -32,9 +32,7 @@ func Config() lib.Config {
|
|||
Port: ovr("8123", SERVER_PORT),
|
||||
}
|
||||
server_c.AddRoute("/docs", server.FileServer("html"))
|
||||
server_mh := server.MsgHandler()
|
||||
server_mh.AddAction("demo", action.Base(action.Forward, "test-receiver"))
|
||||
server_c.AddRoute("/api", server_mh)
|
||||
server_c.AddRoute("/api", server.MsgHandler("demo", "test-receiver"))
|
||||
|
||||
test_client := &client.Cfg{
|
||||
BaseCfg: b("test-client", core.Start),
|
||||
|
|
Loading…
Add table
Reference in a new issue