commit e93f9cbdebfd00ae2fb51bafaaa80e0253445bac
parent f2205dfa78b60b77ba677398dbb1aa2c5929d199
Author: lash <dev@holbrook.no>
Date: Tue, 27 Aug 2024 21:52:57 +0100
Add branch in input
Diffstat:
7 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/examples/http/end b/examples/http/end
@@ -0,0 +1 @@
+whoops
diff --git a/examples/http/end.vis b/examples/http/end.vis
@@ -0,0 +1,2 @@
+HALT
+MOVE ^
diff --git a/examples/http/main.go b/examples/http/main.go
@@ -21,6 +21,26 @@ var (
Logg logging.Logger = logging.NewVanilla().WithDomain("http")
)
+type LocalHandler struct {
+ sessionId string
+}
+
+func NewLocalHandler() *LocalHandler {
+ return &LocalHandler{
+ sessionId: "",
+ }
+}
+
+func(h* LocalHandler) SetSession(sessionId string) {
+ h.sessionId = sessionId
+}
+
+func(h* LocalHandler) AddSession(ctx context.Context, sym string, input []byte) (resource.Result, error) {
+ return resource.Result{
+ Content: h.sessionId + ":" + string(input),
+ }, nil
+}
+
type RequestParser interface {
GetSessionId(*http.Request) (string, error)
GetInput(*http.Request) ([]byte, error)
@@ -50,10 +70,14 @@ type DefaultSessionHandler struct {
cfgTemplate engine.Config
rp RequestParser
rs resource.Resource
+ rh *LocalHandler
peBase string
}
func NewDefaultSessionHandler(persistBase string, resourceBase string, rp RequestParser, outputSize uint32, cacheSize uint32, flagCount uint32) *DefaultSessionHandler {
+ rs := resource.NewFsResource(resourceBase)
+ rh := NewLocalHandler()
+ rs.AddLocalFunc("echo", rh.AddSession)
return &DefaultSessionHandler{
cfgTemplate: engine.Config{
OutputSize: outputSize,
@@ -61,7 +85,8 @@ func NewDefaultSessionHandler(persistBase string, resourceBase string, rp Reques
FlagCount: flagCount,
CacheSize: cacheSize,
},
- rs: resource.NewFsResource(resourceBase),
+ rs: rs,
+ rh: rh,
rp: rp,
}
}
@@ -75,6 +100,7 @@ func(f *DefaultSessionHandler) GetEngine(ctx context.Context, sessionId string)
if err != nil {
return nil, err
}
+ f.rh.SetSession(sessionId)
pe := persist.NewFsPersister(persistPath)
en, err := engine.NewPersistedEngine(ctx, cfg, pe, f.rs)
diff --git a/examples/http/second b/examples/http/second
@@ -1 +1,2 @@
-please enter something else
+you wrote: {{.echo}}
+now choose next step
diff --git a/examples/http/second.vis b/examples/http/second.vis
@@ -1,2 +1,6 @@
+LOAD echo 0
+MAP echo
+MOUT quit 0
HALT
-INCMP third *
+INCMP third 0
+INCMP end *
diff --git a/examples/http/third b/examples/http/third
@@ -0,0 +1 @@
+bye
diff --git a/examples/http/third.vis b/examples/http/third.vis
@@ -1 +1,2 @@
HALT
+MOVE ^