diff --git a/debug/db.go b/debug/db.go index eb62a41..ec9e58f 100644 --- a/debug/db.go +++ b/debug/db.go @@ -20,6 +20,16 @@ type KeyInfo struct { Description string } +func (k KeyInfo) String() string { + v := uint16(k.SubTyp) + s := subTypToString(k.SubTyp) + if s == "" { + v = uint16(k.Typ) + s = typToString(k.Typ) + } + return fmt.Sprintf("Session Id: %s\nTyp: %s (%d)\n", k.SessionId, s, v) +} + func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) { o := KeyInfo{} b := []byte(sessionId) diff --git a/devtools/gen/main.go b/devtools/gen/main.go index 6b58a50..b9e2aed 100644 --- a/devtools/gen/main.go +++ b/devtools/gen/main.go @@ -11,6 +11,7 @@ import ( "git.defalsify.org/vise.git/logging" "git.grassecon.net/urdt/ussd/config" "git.grassecon.net/urdt/ussd/internal/storage" + "git.grassecon.net/urdt/ussd/initializers" "git.grassecon.net/urdt/ussd/common" ) @@ -19,6 +20,11 @@ var ( scriptDir = path.Join("services", "registration") ) +func init() { + initializers.LoadEnvVariables() +} + + func main() { config.LoadConfig() diff --git a/devtools/store/main.go b/devtools/store/main.go index d6abec9..9262703 100644 --- a/devtools/store/main.go +++ b/devtools/store/main.go @@ -10,6 +10,7 @@ import ( "git.grassecon.net/urdt/ussd/config" "git.grassecon.net/urdt/ussd/initializers" "git.grassecon.net/urdt/ussd/internal/storage" + "git.grassecon.net/urdt/ussd/debug" "git.defalsify.org/vise.git/logging" ) @@ -30,6 +31,7 @@ func main() { var sessionId string var database string var engineDebug bool + 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") @@ -37,7 +39,7 @@ func main() { flag.Parse() ctx := context.Background() - //ctx = context.WithValue(ctx, "SessionId", sessionId) + ctx = context.WithValue(ctx, "SessionId", sessionId) ctx = context.WithValue(ctx, "Database", database) resourceDir := scriptDir @@ -60,7 +62,12 @@ func main() { if k == nil { break } - fmt.Printf("%x %s %x\n", k, v) + o, err := debug.FromKey(k) + if err != nil { + fmt.Fprintf(os.Stderr, err.Error()) + os.Exit(1) + } + fmt.Printf("%vValue: %v\n\n", o, v) } err = store.Close() diff --git a/go.mod b/go.mod index d89f0f3..aeac055 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.grassecon.net/urdt/ussd go 1.23.0 require ( - git.defalsify.org/vise.git v0.2.1-0.20241122120231-9e9ee5bdfa7a + git.defalsify.org/vise.git v0.2.1-0.20241208224318-af1d15258dc5 github.com/alecthomas/assert/v2 v2.2.2 github.com/gofrs/uuid v4.4.0+incompatible github.com/grassrootseconomics/eth-custodial v1.3.0-beta diff --git a/go.sum b/go.sum index 5532c1c..5949d8b 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -git.defalsify.org/vise.git v0.2.1-0.20241122120231-9e9ee5bdfa7a h1:LvGKktk0kUnuRN3nF9r15D8OoV0sFaMmQr52kGq2gtE= -git.defalsify.org/vise.git v0.2.1-0.20241122120231-9e9ee5bdfa7a/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck= +git.defalsify.org/vise.git v0.2.1-0.20241208224318-af1d15258dc5 h1:QI/6xmpFM9NsG1+vRPzlUkkjAQ1Z8WhNqS+2tCjBpxg= +git.defalsify.org/vise.git v0.2.1-0.20241208224318-af1d15258dc5/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck= github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk= github.com/alecthomas/assert/v2 v2.2.2/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ= github.com/alecthomas/participle/v2 v2.0.0 h1:Fgrq+MbuSsJwIkw3fEj9h75vDP0Er5JzepJ0/HNHv0g= diff --git a/internal/storage/gdbm.go b/internal/storage/gdbm.go index 9879fe0..31ebf47 100644 --- a/internal/storage/gdbm.go +++ b/internal/storage/gdbm.go @@ -116,5 +116,7 @@ func(tdb *ThreadGdbmDb) Close() error { } func(tdb *ThreadGdbmDb) Dump(ctx context.Context, key []byte) (*db.Dumper, error) { + tdb.reserve() + defer tdb.release() return tdb.db.Dump(ctx, key) }