Remove obsolete store and persister global
This commit is contained in:
parent
62b7adb967
commit
db3ec1991d
30
cmd/main.go
30
cmd/main.go
@ -15,13 +15,13 @@ import (
|
|||||||
"git.defalsify.org/vise.git/persist"
|
"git.defalsify.org/vise.git/persist"
|
||||||
"git.defalsify.org/vise.git/resource"
|
"git.defalsify.org/vise.git/resource"
|
||||||
"git.defalsify.org/vise.git/state"
|
"git.defalsify.org/vise.git/state"
|
||||||
|
"git.defalsify.org/vise.git/logging"
|
||||||
"git.grassecon.net/urdt/ussd/internal/handlers/ussd"
|
"git.grassecon.net/urdt/ussd/internal/handlers/ussd"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
logg = logging.NewVanilla()
|
||||||
scriptDir = path.Join("services", "registration")
|
scriptDir = path.Join("services", "registration")
|
||||||
store = fsdb.NewFsDb()
|
|
||||||
pr = persist.NewPersister(store)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func getFlags(fp string, debug bool) (*asm.FlagParser, error) {
|
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) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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)
|
return nil, fmt.Errorf("state dir create exited with error: %v\n", err)
|
||||||
}
|
}
|
||||||
store := gdbmdb.NewGdbmDb()
|
store := gdbmdb.NewGdbmDb()
|
||||||
storeFile := path.Join(dbDir, ".state")
|
storeFile := path.Join(dbDir, "state.gdbm")
|
||||||
store.Connect(ctx, storeFile)
|
store.Connect(ctx, storeFile)
|
||||||
pr := persist.NewPersister(store)
|
pr := persist.NewPersister(store)
|
||||||
return pr, nil
|
return pr, nil
|
||||||
@ -112,28 +112,20 @@ func getEngine(cfg engine.Config, rs resource.Resource, pr *persist.Persister) *
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
//var dir string
|
|
||||||
var dbDir string
|
var dbDir string
|
||||||
var resourceDir string
|
var resourceDir string
|
||||||
//var root string
|
|
||||||
var size uint
|
var size uint
|
||||||
var sessionId string
|
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.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(&dbDir, "dbdir", ".state", "database dir to read from")
|
||||||
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
|
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
|
||||||
flag.UintVar(&size, "s", 160, "max size of output")
|
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.Background()
|
||||||
|
ctx = context.WithValue(ctx, "SessionId",sessionId)
|
||||||
|
|
||||||
ctx = context.WithValue(ctx, "SessionId",sessionId)
|
|
||||||
pfp := path.Join(scriptDir, "pp.csv")
|
pfp := path.Join(scriptDir, "pp.csv")
|
||||||
flagParser, err := getFlags(pfp, true)
|
flagParser, err := getFlags(pfp, true)
|
||||||
|
|
||||||
@ -147,18 +139,14 @@ func main() {
|
|||||||
OutputSize: uint32(size),
|
OutputSize: uint32(size),
|
||||||
FlagCount: uint32(16),
|
FlagCount: uint32(16),
|
||||||
}
|
}
|
||||||
//ca := cache.Cache{}
|
|
||||||
|
|
||||||
rs, err := getResource(resourceDir, ctx)
|
rs, err := getResource(resourceDir, ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pr, err := getPersister(dbDir, ctx)
|
pr, err := getPersister(dbDir, ctx)
|
||||||
//pr.WithContent(state.NewState(uint32(16)),&ca)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -169,8 +157,8 @@ func main() {
|
|||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
dbResource, ok := rs.(*resource.DbResource)
|
|
||||||
|
|
||||||
|
dbResource, ok := rs.(*resource.DbResource)
|
||||||
if !ok {
|
if !ok {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
@ -100,10 +100,6 @@ func NewHandlers(appFlags *asm.FlagParser, pe *persist.Persister, userdataStore
|
|||||||
accountFileHandler: utils.NewAccountFileHandler(userdataStore),
|
accountFileHandler: utils.NewAccountFileHandler(userdataStore),
|
||||||
accountService: &server.AccountService{},
|
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
|
return h, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +175,6 @@ func (h *Handlers) CreateAccount(ctx context.Context, sym string, input []byte)
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Error here:", err)
|
|
||||||
err = h.createAccountNoExist(ctx, sessionId, &res)
|
err = h.createAccountNoExist(ctx, sessionId, &res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
|
Loading…
Reference in New Issue
Block a user