server: set payload if request body present
This commit is contained in:
parent
32acd23f26
commit
89abbb79dd
2 changed files with 6 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -70,8 +71,11 @@ func handleMsg(ctx lib.Context, cfg *mhSpec, gc *gin.Context) {
|
||||||
head := strings.Split(gc.Param("msg"), "/")[1:]
|
head := strings.Split(gc.Param("msg"), "/")[1:]
|
||||||
cctx := ctx.ChildContext(cfg)
|
cctx := ctx.ChildContext(cfg)
|
||||||
msg := message.New(head...).WithSender(cctx)
|
msg := message.New(head...).WithSender(cctx)
|
||||||
// if gc.Request.Method == "POST" && data != "": msg.WithPayload(data)
|
if body, _ := ioutil.ReadAll(gc.Request.Body); len(body) > 0 {
|
||||||
logging.DebugM(cctx, msg).Msg("server.handleMessage")
|
pl := message.PayloadFromJson[lib.Data](string(body))
|
||||||
|
msg.WithPayload(pl)
|
||||||
|
}
|
||||||
|
logging.DebugM(cctx, msg).Msg("server.handleMsg")
|
||||||
var proc msgProc
|
var proc msgProc
|
||||||
for _, act := range action.Select(cctx, msg) {
|
for _, act := range action.Select(cctx, msg) {
|
||||||
act.Handle()
|
act.Handle()
|
||||||
|
|
|
@ -26,8 +26,6 @@ func Config() lib.Config {
|
||||||
}
|
}
|
||||||
app_c.AddAction("demo", action.Base(action.Forward, "test-receiver"))
|
app_c.AddAction("demo", action.Base(action.Forward, "test-receiver"))
|
||||||
|
|
||||||
//server_amh := server.MsgHandler()
|
|
||||||
//server_amh.AddActionProc("demo", server.Async, "test-receiver")
|
|
||||||
server_c := b("server", server.Start(
|
server_c := b("server", server.Start(
|
||||||
(&server.Cfg{Port: ovr("8123", SERVER_PORT)}).
|
(&server.Cfg{Port: ovr("8123", SERVER_PORT)}).
|
||||||
AddRoute("/docs", server.FileServer("html")).
|
AddRoute("/docs", server.FileServer("html")).
|
||||||
|
|
Loading…
Add table
Reference in a new issue