package main import ( "context" "flag" "fmt" "os" "path" "git.defalsify.org/vise.git/db" "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" testdataloader "github.com/peteole/testdata-loader" ) var ( logg = logging.NewVanilla() baseDir = testdataloader.GetBasePath() scriptDir = path.Join("services", "registration") ) func init() { initializers.LoadEnvVariables(baseDir) } func main() { config.LoadConfig() var connStr string var sessionId string var database string var engineDebug bool var err error flag.StringVar(&sessionId, "session-id", "075xx2123", "session id") flag.StringVar(&connStr, "c", ".state", "connection string") flag.BoolVar(&engineDebug, "d", false, "use engine debug output") flag.Parse() if connStr != "" { connStr = config.DbConn } connData, err := storage.ToConnData(config.DbConn) if err != nil { fmt.Fprintf(os.Stderr, "connstr err: %v", err) os.Exit(1) } logg.Infof("start command", "conn", connData) ctx := context.Background() ctx = context.WithValue(ctx, "SessionId", sessionId) ctx = context.WithValue(ctx, "Database", database) resourceDir := scriptDir menuStorageService := storage.NewMenuStorageService(connData, resourceDir) store, err := menuStorageService.GetUserdataDb(ctx) if err != nil { fmt.Fprintf(os.Stderr, "get userdata db: %v\n", err.Error()) os.Exit(1) } store.SetPrefix(db.DATATYPE_USERDATA) d, err := store.Dump(ctx, []byte(sessionId)) if err != nil { fmt.Fprintf(os.Stderr, "store dump fail: %v\n", err.Error()) os.Exit(1) } for true { k, v := d.Next(ctx) if k == nil { break } r, err := formatItem(k, v) if err != nil { fmt.Fprintf(os.Stderr, "format db item error: %v", err) os.Exit(1) } fmt.Printf(r) } err = store.Close() if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) } }