Add user store converter, improve config separation

This commit is contained in:
lash 2025-01-12 12:14:25 +00:00
parent e848117f4c
commit f089822300
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
12 changed files with 36 additions and 27 deletions

View File

@ -60,9 +60,9 @@ func main() {
flag.Parse() flag.Parse()
if connStr == "" { if connStr == "" {
connStr = config.DbConn connStr = config.DbConn()
} }
connData, err := storage.ToConnData(config.DbConn) connData, err := storage.ToConnData(connStr)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v", err) fmt.Fprintf(os.Stderr, "connstr err: %v", err)
os.Exit(1) os.Exit(1)
@ -72,7 +72,7 @@ func main() {
ctx := context.Background() ctx := context.Background()
ctx = context.WithValue(ctx, "Database", database) ctx = context.WithValue(ctx, "Database", database)
ln, err := lang.LanguageFromCode(config.DefaultLanguage) ln, err := lang.LanguageFromCode(config.Language())
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "default language set error: %v", err) fmt.Fprintf(os.Stderr, "default language set error: %v", err)
os.Exit(1) os.Exit(1)

View File

@ -68,7 +68,7 @@ func main() {
flag.Parse() flag.Parse()
if connStr == "" { if connStr == "" {
connStr = config.DbConn connStr = config.DbConn()
} }
connData, err := storage.ToConnData(connStr) connData, err := storage.ToConnData(connStr)
if err != nil { if err != nil {
@ -80,7 +80,7 @@ func main() {
ctx := context.Background() ctx := context.Background()
ln, err := lang.LanguageFromCode(config.DefaultLanguage) ln, err := lang.LanguageFromCode(config.Language())
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "default language set error: %v", err) fmt.Fprintf(os.Stderr, "default language set error: %v", err)
os.Exit(1) os.Exit(1)

View File

@ -56,7 +56,7 @@ func main() {
flag.Parse() flag.Parse()
if connStr == "" { if connStr == "" {
connStr = config.DbConn connStr = config.DbConn()
} }
connData, err := storage.ToConnData(connStr) connData, err := storage.ToConnData(connStr)
if err != nil { if err != nil {
@ -68,7 +68,7 @@ func main() {
ctx := context.Background() ctx := context.Background()
ln, err := lang.LanguageFromCode(config.DefaultLanguage) ln, err := lang.LanguageFromCode(config.Language())
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "default language set error: %v", err) fmt.Fprintf(os.Stderr, "default language set error: %v", err)
os.Exit(1) os.Exit(1)

View File

@ -32,7 +32,6 @@ func main() {
var connStr string var connStr string
var size uint var size uint
var sessionId string var sessionId string
var database string
var engineDebug bool var engineDebug bool
var resourceDir string var resourceDir string
var err error var err error
@ -49,7 +48,7 @@ func main() {
flag.Parse() flag.Parse()
if connStr != "" { if connStr != "" {
connStr = config.DbConn connStr = config.DbConn()
} }
connData, err := storage.ToConnData(connStr) connData, err := storage.ToConnData(connStr)
if err != nil { if err != nil {
@ -60,14 +59,13 @@ func main() {
logg.Infof("start command", "conn", connData, "outputsize", size) logg.Infof("start command", "conn", connData, "outputsize", size)
if len(langs.Langs()) == 0 { if len(langs.Langs()) == 0 {
langs.Set(config.DefaultLanguage) langs.Set(config.Language())
} }
ctx := context.Background() ctx := context.Background()
ctx = context.WithValue(ctx, "SessionId", sessionId) ctx = context.WithValue(ctx, "SessionId", sessionId)
ctx = context.WithValue(ctx, "Database", database)
ln, err := lang.LanguageFromCode(config.DefaultLanguage) ln, err := lang.LanguageFromCode(config.Language())
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "default language set error: %v", err) fmt.Fprintf(os.Stderr, "default language set error: %v", err)
os.Exit(1) os.Exit(1)

View File

@ -49,7 +49,7 @@ func main() {
flag.Parse() flag.Parse()
if connStr == "" { if connStr == "" {
connStr = config.DbConn connStr = config.DbConn()
} }
if authConnStr == "" { if authConnStr == "" {
authConnStr = connStr authConnStr = connStr

View File

@ -15,11 +15,6 @@ const (
defaultSSHPort uint = 7122 defaultSSHPort uint = 7122
) )
var (
DbConn = viseconfig.DbConn
DefaultLanguage = viseconfig.DefaultLanguage
)
func LoadConfig() error { func LoadConfig() error {
err := viseconfig.LoadConfig() err := viseconfig.LoadConfig()
if err != nil { if err != nil {
@ -29,11 +24,17 @@ func LoadConfig() error {
if err != nil { if err != nil {
return err return err
} }
DbConn = viseconfig.DbConn
DefaultLanguage = viseconfig.DefaultLanguage
return nil return nil
} }
func DbConn() string {
return viseconfig.DbConn
}
func Language() string {
return viseconfig.DefaultLanguage
}
func Host() string { func Host() string {
return apiconfig.Host() return apiconfig.Host()
} }

View File

@ -43,9 +43,9 @@ func main() {
flag.Parse() flag.Parse()
if connStr != "" { if connStr != "" {
connStr = config.DbConn connStr = config.DbConn()
} }
connData, err := storage.ToConnData(config.DbConn) connData, err := storage.ToConnData(connStr)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v", err) fmt.Fprintf(os.Stderr, "connstr err: %v", err)
os.Exit(1) os.Exit(1)

View File

@ -37,9 +37,9 @@ func main() {
flag.Parse() flag.Parse()
if connStr != "" { if connStr != "" {
connStr = config.DbConn connStr = config.DbConn()
} }
connData, err := storage.ToConnData(config.DbConn) connData, err := storage.ToConnData(connStr)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v", err) fmt.Fprintf(os.Stderr, "connstr err: %v", err)
os.Exit(1) os.Exit(1)

2
go.mod
View File

@ -6,7 +6,7 @@ require (
git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d
git.grassecon.net/grassrootseconomics/common v0.0.0-20250112102149-4feac5e490e9 git.grassecon.net/grassrootseconomics/common v0.0.0-20250112102149-4feac5e490e9
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112110836-26a51bc95f38 git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112110836-26a51bc95f38
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250112104023-611c5a8dfc80 git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250112121325-9e4c65c8b4d1
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250112104256-7d37d7f5cac5 git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250112104256-7d37d7f5cac5
github.com/alecthomas/assert/v2 v2.2.2 github.com/alecthomas/assert/v2 v2.2.2
github.com/gofrs/uuid v4.4.0+incompatible github.com/gofrs/uuid v4.4.0+incompatible

4
go.sum
View File

@ -4,8 +4,8 @@ git.grassecon.net/grassrootseconomics/common v0.0.0-20250112102149-4feac5e490e9
git.grassecon.net/grassrootseconomics/common v0.0.0-20250112102149-4feac5e490e9/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60= git.grassecon.net/grassrootseconomics/common v0.0.0-20250112102149-4feac5e490e9/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60=
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112110836-26a51bc95f38 h1:M++O6THA26LRdC7jfsPCaIIPMosNhFc+PgnEtDY3+hk= git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112110836-26a51bc95f38 h1:M++O6THA26LRdC7jfsPCaIIPMosNhFc+PgnEtDY3+hk=
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112110836-26a51bc95f38/go.mod h1:E0ayNSbqpt+aAHoA7f7jXZcH2Zgjkt7rYs50YH9sLgk= git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112110836-26a51bc95f38/go.mod h1:E0ayNSbqpt+aAHoA7f7jXZcH2Zgjkt7rYs50YH9sLgk=
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250112104023-611c5a8dfc80 h1:8j7iDSC9lzOM8NexEQlMfEn+3mJStDf66OTZK8ulsho= git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250112121325-9e4c65c8b4d1 h1:RfU5/WFfPxDptlkyx4MT+4YmO79sY6HvIngUq5uwQPU=
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250112104023-611c5a8dfc80/go.mod h1:E6W7ZOa7ZvVr0Bc5ot0LNSwpSPYq4hXlAIvEPy3AJ7U= git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250112121325-9e4c65c8b4d1/go.mod h1:E6W7ZOa7ZvVr0Bc5ot0LNSwpSPYq4hXlAIvEPy3AJ7U=
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250112104256-7d37d7f5cac5 h1:byD+vsY9kqCVFX2Kx2+Z3/Lqk10l4MQnUBXm/zLpy20= git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250112104256-7d37d7f5cac5 h1:byD+vsY9kqCVFX2Kx2+Z3/Lqk10l4MQnUBXm/zLpy20=
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250112104256-7d37d7f5cac5/go.mod h1:wf5CtGf07LRtnPqr9sefMY+bQK5oASsvzIr7ebs7MWU= git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250112104256-7d37d7f5cac5/go.mod h1:wf5CtGf07LRtnPqr9sefMY+bQK5oASsvzIr7ebs7MWU=
github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk= github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk=

View File

@ -74,6 +74,7 @@ const (
) )
const ( const (
// List of senders for valid transactions in the user context.
DATA_TX_SENDERS = 512 + iota DATA_TX_SENDERS = 512 + iota
// List of recipients for valid transactions in the user context. // List of recipients for valid transactions in the user context.
DATA_TX_RECIPIENTS DATA_TX_RECIPIENTS
@ -91,6 +92,11 @@ const (
DATA_TX_DECIMALS DATA_TX_DECIMALS
) )
const (
// Token transfer list
DATA_TRANSACTIONS = 1024 + iota
)
var ( var (
logg = logging.NewVanilla().WithDomain("urdt-common") logg = logging.NewVanilla().WithDomain("urdt-common")
) )

View File

@ -35,3 +35,7 @@ func (store *UserDataStore) WriteEntry(ctx context.Context, sessionId string, ty
k := storedb.ToBytes(typ) k := storedb.ToBytes(typ)
return store.Put(ctx, k, value) return store.Put(ctx, k, value)
} }
func StoreToPrefixDb(userStore *UserDataStore, pfx []byte) storedb.PrefixDb {
return storedb.NewSubPrefixDb(userStore.Db, pfx)
}