Draft example of dev-0.1.0 refactor #34
19
cmd/main.go
19
cmd/main.go
@ -75,20 +75,27 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, pe *persist.P
|
|||||||
return ussdHandlers, nil
|
return ussdHandlers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDataPersister(dbDir string) (*persist.Persister, error) {
|
func getPersister(dbDir string) (*persist.Persister, error) {
|
||||||
err = os.MkdirAll(dp, 0700)
|
err = os.MkdirAll(dp, 0700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
dataStore := gdbmdb.NewGdbmDb()
|
store := gdbmdb.NewGdbmDb()
|
||||||
dataStoreFile := path.Join(dbDir, "states.gdbm")
|
storeFile := path.Join(dbDir, "states.gdbm")
|
||||||
dataStore.Connect(ctx, dataStoreFile)
|
store.Connect(ctx, storeFile)
|
||||||
pr := persist.NewPersister(dataStore)
|
pr := persist.NewPersister(store)
|
||||||
|
|
||||||
return pr
|
return pr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getUserdataDb(dbDir string) {
|
||||||
|
store := gdbmdb.NewGdbmDb()
|
||||||
|
storeFile := path.Join(dbDir, "userdata.gdbm")
|
||||||
|
store.Connect(ctx, storeFile)
|
||||||
|
return store
|
||||||
|
}
|
||||||
|
|
||||||
func getResource(resourceDir string) (resource.Resource, error) {
|
func getResource(resourceDir string) (resource.Resource, error) {
|
||||||
store := fsdb.NewFsDb()
|
store := fsdb.NewFsDb()
|
||||||
err = store.Connect(ctx, resourceDir)
|
err = store.Connect(ctx, resourceDir)
|
||||||
@ -141,7 +148,7 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
store, err := getUserDb(dataDir)
|
store, err := getUserdataDb(dataDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user