Remove obsolete store and persister global

This commit is contained in:
lash 2024-09-05 16:45:35 +01:00
parent 62b7adb967
commit db3ec1991d
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 9 additions and 26 deletions

View File

@ -15,13 +15,13 @@ import (
"git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/resource"
"git.defalsify.org/vise.git/state"
"git.defalsify.org/vise.git/logging"
"git.grassecon.net/urdt/ussd/internal/handlers/ussd"
)
var (
logg = logging.NewVanilla()
scriptDir = path.Join("services", "registration")
store = fsdb.NewFsDb()
pr = persist.NewPersister(store)
)
func getFlags(fp string, debug bool) (*asm.FlagParser, error) {
@ -35,7 +35,7 @@ func getFlags(fp string, debug bool) (*asm.FlagParser, error) {
func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, pe *persist.Persister, userdataStore db.Db) (*ussd.Handlers, error) {
ussdHandlers, err := ussd.NewHandlers(appFlags, pr, store)
ussdHandlers, err := ussd.NewHandlers(appFlags, pe, userdataStore)
if err != nil {
return nil, err
}
@ -81,7 +81,7 @@ func getPersister(dbDir string, ctx context.Context) (*persist.Persister, error)
return nil, fmt.Errorf("state dir create exited with error: %v\n", err)
}
store := gdbmdb.NewGdbmDb()
storeFile := path.Join(dbDir, ".state")
storeFile := path.Join(dbDir, "state.gdbm")
store.Connect(ctx, storeFile)
pr := persist.NewPersister(store)
return pr, nil
@ -112,28 +112,20 @@ func getEngine(cfg engine.Config, rs resource.Resource, pr *persist.Persister) *
}
func main() {
//var dir string
var dbDir string
var resourceDir string
//var root string
var size uint
var sessionId string
//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", "075xx2123", "session id")
// flag.Parse()
// fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, dir)
//logg.Infof("starting session", "symbol", root, "dbdir", dbDir, "sessionid", sessionId, "outsize", size)
flag.StringVar(&dbDir, "dbdir", ".state", "database dir to read from")
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
flag.UintVar(&size, "s", 160, "max size of output")
flag.Parse()
logg.Infof("start command", "dbdir", dbDir, "resourcedir", resourceDir, "outputsize", size)
ctx := context.Background()
ctx = context.WithValue(ctx, "SessionId",sessionId)
ctx = context.WithValue(ctx, "SessionId",sessionId)
pfp := path.Join(scriptDir, "pp.csv")
flagParser, err := getFlags(pfp, true)
@ -147,18 +139,14 @@ func main() {
OutputSize: uint32(size),
FlagCount: uint32(16),
}
//ca := cache.Cache{}
rs, err := getResource(resourceDir, ctx)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
pr, err := getPersister(dbDir, ctx)
//pr.WithContent(state.NewState(uint32(16)),&ca)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
@ -169,8 +157,8 @@ func main() {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
dbResource, ok := rs.(*resource.DbResource)
dbResource, ok := rs.(*resource.DbResource)
if !ok {
os.Exit(1)
}

View File

@ -100,10 +100,6 @@ func NewHandlers(appFlags *asm.FlagParser, pe *persist.Persister, userdataStore
accountFileHandler: utils.NewAccountFileHandler(userdataStore),
accountService: &server.AccountService{},
}
// if h.st == nil || h.ca == nil || h.userdataStore == nil || h.flagManager == nil {
// logg.Errorf("have nil for essential value in handler", "state", h.st, "cache", h.ca, "store", h.userdataStore, "flags", h.flagManager)
// return nil, fmt.Errorf("have nil for essential value")
// }
return h, nil
}
@ -179,7 +175,6 @@ func (h *Handlers) CreateAccount(ctx context.Context, sym string, input []byte)
return res, err
}
} else {
fmt.Println("Error here:", err)
err = h.createAccountNoExist(ctx, sessionId, &res)
if err != nil {
return res, err