forked from urdt/ussd
78 lines
1.4 KiB
Go
78 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
|
|
"git.defalsify.org/vise.git/logging"
|
|
"git.grassecon.net/urdt/ussd/config"
|
|
"git.grassecon.net/urdt/ussd/initializers"
|
|
"git.grassecon.net/urdt/ussd/internal/storage"
|
|
)
|
|
|
|
var (
|
|
logg = logging.NewVanilla()
|
|
scriptDir = path.Join("services", "registration")
|
|
)
|
|
|
|
func init() {
|
|
initializers.LoadEnvVariables()
|
|
}
|
|
|
|
func main() {
|
|
config.LoadConfig()
|
|
|
|
var dbDir string
|
|
var sessionId string
|
|
var database string
|
|
|
|
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
|
|
flag.StringVar(&database, "db", "gdbm", "database to be used")
|
|
flag.StringVar(&dbDir, "dbdir", ".state", "database dir to read from")
|
|
flag.Parse()
|
|
|
|
ctx := context.Background()
|
|
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
|
ctx = context.WithValue(ctx, "Database", database)
|
|
|
|
resourceDir := scriptDir
|
|
menuStorageService := storage.NewMenuStorageService(dbDir, resourceDir)
|
|
|
|
err := menuStorageService.EnsureDbDir()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
pe, err := menuStorageService.GetPersister(ctx)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
// initialize the persister
|
|
|
|
// get the state
|
|
|
|
// restart the state
|
|
|
|
// persist the state
|
|
|
|
// exit
|
|
|
|
st := pe.GetState()
|
|
|
|
if st == nil {
|
|
logg.ErrorCtxf(ctx, "state fail in devtool", "state", st)
|
|
fmt.Errorf("cannot get state")
|
|
os.Exit(1)
|
|
}
|
|
|
|
st.Restart()
|
|
|
|
os.Exit(1)
|
|
}
|