wip-account-creation #4

Merged
lash merged 143 commits from wip-account-creation into master 2024-08-30 14:37:58 +02:00
7 changed files with 55 additions and 17 deletions
Showing only changes of commit fb7b35af74 - Show all commits

4
.gitignore vendored
View File

@ -1,4 +1,6 @@
**/*.env
covprofile
go.work*
services/registration/*.bin
**/*/*.bin
**/*/.state/
cmd/.state/

View File

@ -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

@ -0,0 +1 @@
Subproject commit ef9a4c3073e7e878846693d4aa7fd0cf1cc977a7

View File

@ -0,0 +1 @@
Welcome to Sarafu Network!

View File

@ -0,0 +1,5 @@
MOUT english 0
MOUT kiswahili 1
HALT
INCMP terms 0
INCMP terms 1

View File

@ -0,0 +1 @@
Karibu Sarafu Network!

View File

@ -1,2 +1,4 @@
LOAD select_language 0
RELOAD select_language
MOUT yes 0
MOUT no 1