wip-account-creation #4
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,4 +1,6 @@
|
||||
**/*.env
|
||||
covprofile
|
||||
go.work*
|
||||
services/registration/*.bin
|
||||
**/*/*.bin
|
||||
**/*/.state/
|
||||
cmd/.state/
|
||||
|
56
cmd/main.go
56
cmd/main.go
@ -6,8 +6,10 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"git.defalsify.org/vise.git/engine"
|
||||
|
||||
"git.defalsify.org/vise.git/cache"
|
||||
"git.defalsify.org/vise.git/engine"
|
||||
"git.defalsify.org/vise.git/persist"
|
||||
"git.defalsify.org/vise.git/resource"
|
||||
"git.defalsify.org/vise.git/state"
|
||||
)
|
||||
@ -36,33 +38,54 @@ func (fsd *fsData) SetLanguageSelected(ctx context.Context, sym string, input []
|
||||
return res, nil
|
||||
}
|
||||
|
||||
var (
|
||||
scriptDir = path.Join("services", "registration")
|
||||
)
|
||||
|
||||
func main() {
|
||||
var dir string
|
||||
var root string
|
||||
var size uint
|
||||
var sessionId string
|
||||
var persist bool
|
||||
flag.StringVar(&dir, "d", ".", "resource dir to read from")
|
||||
flag.UintVar(&size, "s", 0, "max size of output")
|
||||
flag.StringVar(&root, "root", "root", "entry point symbol")
|
||||
flag.StringVar(&sessionId, "session-id", "default", "session id")
|
||||
flag.BoolVar(&persist, "persist", false, "use state persistence")
|
||||
flag.Parse()
|
||||
fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, dir)
|
||||
|
||||
fp := path.Join(dir, sessionId)
|
||||
ctx := context.Background()
|
||||
st := state.NewState(3)
|
||||
rfs := resource.NewFsResource(scriptDir)
|
||||
ca := cache.NewCache()
|
||||
cfg := engine.Config{
|
||||
Root: "root",
|
||||
SessionId: sessionId,
|
||||
}
|
||||
|
||||
dp := path.Join(scriptDir, ".state")
|
||||
err := os.MkdirAll(dp, 0700)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "state dir create exited with error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
pr := persist.NewFsPersister(dp)
|
||||
en, err := engine.NewPersistedEngine(ctx, cfg, pr, rfs)
|
||||
if err != nil {
|
||||
pr = pr.WithContent(&st, ca)
|
||||
err = pr.Save(cfg.SessionId)
|
||||
en, err = engine.NewPersistedEngine(ctx, cfg, pr, rfs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "engine create exited with error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
fp := path.Join(dp, sessionId)
|
||||
fs := &fsData{
|
||||
path: fp,
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
en, rs, err := engine.NewSizedEnginee(dir, uint32(size), persist, &sessionId)
|
||||
rs.AddLocalFunc("select_language", fs.SetLanguageSelected)
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "engine create error: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
rfs.AddLocalFunc("select_language", fs.SetLanguageSelected)
|
||||
cont, err := en.Init(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "engine init exited with error: %v\n", err)
|
||||
@ -74,14 +97,17 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, "dead init write error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
err = en.Finish()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "engine finish error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Stdout.Write([]byte{0x0a})
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
err = engine.Loop(ctx, en, os.Stdin, os.Stdout)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
}
|
||||
|
1
go-vise
Submodule
1
go-vise
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit ef9a4c3073e7e878846693d4aa7fd0cf1cc977a7
|
1
services/registration/root
Normal file
1
services/registration/root
Normal file
@ -0,0 +1 @@
|
||||
Welcome to Sarafu Network!
|
5
services/registration/root.vis
Normal file
5
services/registration/root.vis
Normal file
@ -0,0 +1,5 @@
|
||||
MOUT english 0
|
||||
MOUT kiswahili 1
|
||||
HALT
|
||||
INCMP terms 0
|
||||
INCMP terms 1
|
1
services/registration/root_swa
Normal file
1
services/registration/root_swa
Normal file
@ -0,0 +1 @@
|
||||
Karibu Sarafu Network!
|
@ -1,2 +1,4 @@
|
||||
LOAD select_language 0
|
||||
RELOAD select_language
|
||||
MOUT yes 0
|
||||
MOUT no 1
|
||||
|
Loading…
Reference in New Issue
Block a user