forked from urdt/ussd
Add debug package
This commit is contained in:
parent
3d2ca606ca
commit
1a782c1db9
47
debug/db.go
Normal file
47
debug/db.go
Normal file
@ -0,0 +1,47 @@
|
||||
package debug
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"encoding/binary"
|
||||
|
||||
"git.grassecon.net/urdt/ussd/internal/storage"
|
||||
"git.grassecon.net/urdt/ussd/common"
|
||||
)
|
||||
|
||||
type KeyInfo struct {
|
||||
SessionId string
|
||||
Typ uint8
|
||||
SubTyp common.DataTyp
|
||||
Label string
|
||||
Description string
|
||||
}
|
||||
|
||||
func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) {
|
||||
o := KeyInfo{}
|
||||
b := []byte(sessionId)
|
||||
if len(k) <= len(b) {
|
||||
return o, fmt.Errorf("storage key missing")
|
||||
}
|
||||
|
||||
o.SessionId = sessionId
|
||||
|
||||
k = k[len(b):]
|
||||
o.Typ = k[0]
|
||||
k = k[1:]
|
||||
|
||||
if o.Typ == storage.DATATYPE_USERSUB {
|
||||
if len(k) == 0 {
|
||||
return o, fmt.Errorf("missing subtype key")
|
||||
}
|
||||
v := binary.BigEndian.Uint16(k[:2])
|
||||
o.SubTyp = common.DataTyp(v)
|
||||
o.Label = typToString(o.SubTyp)
|
||||
k = k[2:]
|
||||
}
|
||||
|
||||
if len(k) != 0 {
|
||||
return o, fmt.Errorf("excess key information")
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
14
debug/db_no.go
Normal file
14
debug/db_no.go
Normal file
@ -0,0 +1,14 @@
|
||||
// +build !debugdb
|
||||
|
||||
package debug
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.grassecon.net/urdt/ussd/common"
|
||||
)
|
||||
|
||||
|
||||
func typToString(v common.DataTyp) string {
|
||||
return fmt.Sprintf("(%d)", v)
|
||||
}
|
42
debug/db_yes.go
Normal file
42
debug/db_yes.go
Normal file
@ -0,0 +1,42 @@
|
||||
// +build debugdb
|
||||
|
||||
package debug
|
||||
|
||||
import (
|
||||
"git.defalsify.org/vise.git/db"
|
||||
|
||||
"git.grassecon.net/urdt/ussd/common"
|
||||
)
|
||||
|
||||
var (
|
||||
dbTypStr map[common.DataTyp]string = map[common.DataTyp]string {
|
||||
db.DATATYPE_USERDATA: "userdata",
|
||||
common.DATA_ACCOUNT: "account",
|
||||
common.DATA_ACCOUNT_CREATED: "account created",
|
||||
common.DATA_TRACKING_ID: "tracking id",
|
||||
common.DATA_PUBLIC_KEY: "public key",
|
||||
common.DATA_CUSTODIAL_ID: "custodial id",
|
||||
common.DATA_ACCOUNT_PIN: "account pin",
|
||||
common.DATA_ACCOUNT_STATUS: "account status",
|
||||
common.DATA_FIRST_NAME: "first name",
|
||||
common.DATA_FAMILY_NAME: "family name",
|
||||
common.DATA_YOB: "year of birth",
|
||||
common.DATA_LOCATION: "location",
|
||||
common.DATA_GENDER: "gender",
|
||||
common.DATA_OFFERINGS: "offerings",
|
||||
common.DATA_RECIPIENT: "recipient",
|
||||
common.DATA_AMOUNT: "amount",
|
||||
common.DATA_TEMPORARY_VALUE: "temporary value",
|
||||
common.DATA_ACTIVE_SYM: "active sym",
|
||||
common.DATA_ACTIVE_BAL: "active bal",
|
||||
common.DATA_BLOCKED_NUMBER: "blocked number",
|
||||
common.DATA_PUBLIC_KEY_REVERSE: "public key reverse",
|
||||
common.DATA_ACTIVE_DECIMAL: "active decimal",
|
||||
common.DATA_ACTIVE_ADDRESS: "active address",
|
||||
common.DATA_TRANSACTIONS: "transactions",
|
||||
}
|
||||
)
|
||||
|
||||
func typToString(v common.DataTyp) string {
|
||||
return dbTypStr[v]
|
||||
}
|
@ -22,6 +22,7 @@ func init() {
|
||||
initializers.LoadEnvVariables()
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
config.LoadConfig()
|
||||
|
||||
@ -59,6 +60,6 @@ func main() {
|
||||
if k == nil {
|
||||
break
|
||||
}
|
||||
fmt.Printf("%x %s\n", k, v)
|
||||
fmt.Printf("%x %s %x\n", k, v)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user