Compare commits

..

3 Commits

13 changed files with 54 additions and 230 deletions

View File

@ -6,11 +6,11 @@ import (
"git.grassecon.net/grassrootseconomics/visedriver/env" "git.grassecon.net/grassrootseconomics/visedriver/env"
"git.grassecon.net/grassrootseconomics/visedriver/storage" "git.grassecon.net/grassrootseconomics/visedriver/storage"
"github.com/grassrootseconomics/go-vise/logging" slogging "github.com/grassrootseconomics/go-vise/slog"
) )
var ( var (
logg = logging.NewVanilla().WithDomain("visedriver-config") logg = slogging.Get().With("component", "visedriver-config")
defaultLanguage = "eng" defaultLanguage = "eng"
languages []string languages []string
DefaultLanguage string DefaultLanguage string
@ -136,7 +136,7 @@ func GetConns() (storage.Conns, error) {
// LoadConfig initializes the configuration values after environment variables are loaded. // LoadConfig initializes the configuration values after environment variables are loaded.
func LoadConfig() error { func LoadConfig() error {
configManager = NewConfig(logg) configManager = NewConfig()
// Add configuration keys with validation // Add configuration keys with validation
configManager.AddKey("HOST", "127.0.0.1", false, nil) configManager.AddKey("HOST", "127.0.0.1", false, nil)

View File

@ -8,12 +8,12 @@ import (
"os" "os"
"testing" "testing"
"github.com/grassrootseconomics/go-vise/logging" slogging "github.com/grassrootseconomics/go-vise/slog"
) )
// go test -tags configreport ./config/... ---> run with tag // go test -tags configreport ./config/... ---> run with tag
func TestConfig(t *testing.T) { func TestConfig(t *testing.T) {
logger := logging.NewVanilla().WithDomain("test") logger := slogging.Get().With("component", "test")
cfg := NewConfig(logger) cfg := NewConfig(logger)
t.Run("Default Values", func(t *testing.T) { t.Run("Default Values", func(t *testing.T) {

View File

@ -6,7 +6,7 @@ import (
"fmt" "fmt"
"git.grassecon.net/grassrootseconomics/visedriver/env" "git.grassecon.net/grassrootseconomics/visedriver/env"
"github.com/grassrootseconomics/go-vise/logging" slogging "github.com/grassrootseconomics/go-vise/slog"
) )
// ConfigValue represents a configuration key-value pair // ConfigValue represents a configuration key-value pair
@ -20,13 +20,13 @@ type ConfigValue struct {
// Config handles configuration management and reporting // Config handles configuration management and reporting
type Config struct { type Config struct {
values map[string]ConfigValue values map[string]ConfigValue
logger logging.Vanilla logger *slogging.Slog
} }
func NewConfig(logger logging.Vanilla) *Config { func NewConfig(logging interface{}) *Config {
return &Config{ return &Config{
values: make(map[string]ConfigValue), values: make(map[string]ConfigValue),
logger: logger, logger: slogging.Get().With("component", "visedriver-config-reporter"),
} }
} }
@ -79,17 +79,6 @@ func (c *Config) Report(level string) {
value = "****" value = "****"
} }
switch level {
case "DEBUG":
c.logger.Debugf("config set", cv.Key, value) c.logger.Debugf("config set", cv.Key, value)
case "INFO":
c.logger.Infof("config set", cv.Key, value)
case "WARN":
c.logger.Warnf("config set", cv.Key, value)
case "ERROR":
c.logger.Errorf("config set", cv.Key, value)
default:
c.logger.Infof("config set", cv.Key, value)
}
} }
} }

View File

@ -2,13 +2,9 @@
package config package config
import (
"github.com/grassrootseconomics/go-vise/logging"
)
type Config struct{} type Config struct{}
func NewConfig(logger logging.Vanilla) *Config { func NewConfig() *Config {
return &Config{} return &Config{}
} }

View File

@ -4,19 +4,15 @@
This document describes component versions: This document describes component versions:
- `urdt-ussd` `v0.5.0-beta` * `urdt-ussd` `v0.5.0-beta`
- `go-vise` `v0.2.2` * `go-vise` `v0.2.2`
## User profile data ## User profile data
All user profile items are stored under keys matching the user's session id, All user profile items are stored under keys matching the user's session id, prefixed with the 8-bit value `github.com/grassrootseconomics/go-vise/db.DATATYPE_USERDATA` (32), and followed with a 16-big big-endian value subprefix.
prefixed with the 8-bit value
`github.com/grassrootseconomics/go-vise/db.DATATYPE_USERDATA` (32), and followed
with a 16-big big-endian value subprefix.
For example, given the sessionId `+254123` and the key For example, given the sessionId `+254123` and the key `git.grassecon.net/urdt-ussd/common.DATA_PUBLIC_KEY` (2) will be stored under the key:
`git.grassecon.net/urdt-ussd/common.DATA_PUBLIC_KEY` (2) will be stored under
the key:
``` ```
0x322b3235343132330002 0x322b3235343132330002
@ -27,9 +23,6 @@ prefix sessionid subprefix
### Sub-prefixes ### Sub-prefixes
All sub-prefixes are defined as constants in the All sub-prefixes are defined as constants in the `git.grassecon.net/urdt-ussd/common` package. The constant names have the prefix `DATA_`
`git.grassecon.net/urdt-ussd/common` package. The constant names have the prefix
`DATA_`
Please refer to inline godoc documentation for the Please refer to inline godoc documentation for the `git.grassecon.net/urdt-ussd/common` package for details on each data item.
`git.grassecon.net/urdt-ussd/common` package for details on each data item.

18
go.mod
View File

@ -2,28 +2,26 @@ module git.grassecon.net/grassrootseconomics/visedriver
go 1.24 go 1.24
toolchain go1.24.2 toolchain go1.24.6
require ( require (
github.com/grassrootseconomics/go-vise v0.4.2 github.com/grassrootseconomics/go-vise v0.5.0
github.com/jackc/pgx/v5 v5.7.4 github.com/jackc/pgx/v5 v5.7.5
github.com/joho/godotenv v1.5.1 github.com/joho/godotenv v1.5.1
) )
require ( require (
github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c // indirect github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fxamacker/cbor/v2 v2.4.0 // indirect github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/graygnuorg/go-gdbm v0.0.0-20220711140707-71387d66dce4 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/mattn/kinako v0.0.0-20170717041458-332c0a7e205a // indirect github.com/leonelquinteros/gotext v1.7.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/stretchr/testify v1.9.0 // indirect github.com/stretchr/testify v1.9.0 // indirect
github.com/x448/float16 v0.8.4 // indirect github.com/x448/float16 v0.8.4 // indirect
golang.org/x/crypto v0.38.0 // indirect golang.org/x/crypto v0.40.0 // indirect
golang.org/x/sync v0.14.0 // indirect golang.org/x/sync v0.16.0 // indirect
golang.org/x/text v0.25.0 // indirect golang.org/x/text v0.27.0 // indirect
gopkg.in/leonelquinteros/gotext.v1 v1.3.1 // indirect
) )

38
go.sum
View File

@ -3,28 +3,24 @@ github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c/go.mod h1:rGod7
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88= github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM=
github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo= github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
github.com/grassrootseconomics/go-vise v0.4.1 h1:g26jvYnsWaTns60ZHdltGcsL9cjWqvYZwUZ2FWVKOGo= github.com/grassrootseconomics/go-vise v0.5.0 h1:FRg2de55Eb5SisrgTBeFWfWX+sXwp5q9r7YWtKWDwsk=
github.com/grassrootseconomics/go-vise v0.4.1/go.mod h1:tt3/Swp9F9PdhSDBDvwuI1GZRrCg32kWXWzyATIpTO4= github.com/grassrootseconomics/go-vise v0.5.0/go.mod h1:b2/q4jfTu2i1wyUwYUu7FYq4m2f1AZv8MpiDM3ZcoGo=
github.com/grassrootseconomics/go-vise v0.4.2 h1:6c6ncOCvvXOGWBtMRhuDDLvhsUb+wn11zW6NuCmlFXY=
github.com/grassrootseconomics/go-vise v0.4.2/go.mod h1:tt3/Swp9F9PdhSDBDvwuI1GZRrCg32kWXWzyATIpTO4=
github.com/graygnuorg/go-gdbm v0.0.0-20220711140707-71387d66dce4 h1:U4kkNYryi/qfbBF8gh7Vsbuz+cVmhf5kt6pE9bYYyLo=
github.com/graygnuorg/go-gdbm v0.0.0-20220711140707-71387d66dce4/go.mod h1:zpZDgZFzeq9s0MIeB1P50NIEWDFFHSFBohI/NbaTD/Y=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.7.4 h1:9wKznZrhWa2QiHL+NjTSPP6yjl3451BX3imWDnokYlg= github.com/jackc/pgx/v5 v5.7.5 h1:JHGfMnQY+IEtGM63d+NGMjoRpysB2JBwDr5fsngwmJs=
github.com/jackc/pgx/v5 v5.7.4/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ= github.com/jackc/pgx/v5 v5.7.5/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/lmittmann/tint v1.0.7 h1:D/0OqWZ0YOGZ6AyC+5Y2kD8PBEzBk6rFHVSfOqCkF9Y= github.com/leonelquinteros/gotext v1.7.2 h1:bDPndU8nt+/kRo1m4l/1OXiiy2v7Z7dfPQ9+YP7G1Mc=
github.com/lmittmann/tint v1.0.7/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE= github.com/leonelquinteros/gotext v1.7.2/go.mod h1:9/haCkm5P7Jay1sxKDGJ5WIg4zkz8oZKw4ekNpALob8=
github.com/mattn/kinako v0.0.0-20170717041458-332c0a7e205a h1:0Q3H0YXzMHiciXtRcM+j0jiCe8WKPQHoRgQiRTnfcLY= github.com/lmittmann/tint v1.1.2 h1:2CQzrL6rslrsyjqLDwD11bZ5OpLBPU+g3G/r5LSfS8w=
github.com/mattn/kinako v0.0.0-20170717041458-332c0a7e205a/go.mod h1:CdTTBOYzS5E4mWS1N8NWP6AHI19MP0A2B18n3hLzRMk= github.com/lmittmann/tint v1.1.2/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE=
github.com/pashagolub/pgxmock/v4 v4.7.0 h1:de2ORuFYyjwOQR7NBm57+321RnZxpYiuUjsmqRiqgh8= github.com/pashagolub/pgxmock/v4 v4.7.0 h1:de2ORuFYyjwOQR7NBm57+321RnZxpYiuUjsmqRiqgh8=
github.com/pashagolub/pgxmock/v4 v4.7.0/go.mod h1:9L57pC193h2aKRHVyiiE817avasIPZnPwPlw3JczWvM= github.com/pashagolub/pgxmock/v4 v4.7.0/go.mod h1:9L57pC193h2aKRHVyiiE817avasIPZnPwPlw3JczWvM=
github.com/peteole/testdata-loader v0.3.0 h1:8jckE9KcyNHgyv/VPoaljvKZE0Rqr8+dPVYH6rfNr9I= github.com/peteole/testdata-loader v0.3.0 h1:8jckE9KcyNHgyv/VPoaljvKZE0Rqr8+dPVYH6rfNr9I=
@ -39,15 +35,13 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ= golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/leonelquinteros/gotext.v1 v1.3.1 h1:8d9/fdTG0kn/B7NNGV1BsEyvektXFAbkMsTZS2sFSCc=
gopkg.in/leonelquinteros/gotext.v1 v1.3.1/go.mod h1:X1WlGDeAFIYsW6GjgMm4VwUwZ2XjI7Zan2InxSUQWrU=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -3,13 +3,13 @@ package request
import ( import (
"context" "context"
"git.grassecon.net/grassrootseconomics/visedriver/entry"
"git.grassecon.net/grassrootseconomics/visedriver/errors"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
"github.com/grassrootseconomics/go-vise/db" "github.com/grassrootseconomics/go-vise/db"
"github.com/grassrootseconomics/go-vise/engine" "github.com/grassrootseconomics/go-vise/engine"
"github.com/grassrootseconomics/go-vise/persist" "github.com/grassrootseconomics/go-vise/persist"
"github.com/grassrootseconomics/go-vise/resource" "github.com/grassrootseconomics/go-vise/resource"
"git.grassecon.net/grassrootseconomics/visedriver/entry"
"git.grassecon.net/grassrootseconomics/visedriver/errors"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
) )
type EngineFunc func(engine.Config, resource.Resource, *persist.Persister) engine.Engine type EngineFunc func(engine.Config, resource.Resource, *persist.Persister) engine.Engine

View File

@ -6,11 +6,11 @@ import (
"git.grassecon.net/grassrootseconomics/visedriver/errors" "git.grassecon.net/grassrootseconomics/visedriver/errors"
"git.grassecon.net/grassrootseconomics/visedriver/request" "git.grassecon.net/grassrootseconomics/visedriver/request"
"github.com/grassrootseconomics/go-vise/logging" slogging "github.com/grassrootseconomics/go-vise/slog"
) )
var ( var (
logg = logging.NewVanilla().WithDomain("visedriver.http.session") logg = slogging.Get().With("component", "visedriver.http.session")
) )
// HTTPRequestHandler implements the session handler for HTTP // HTTPRequestHandler implements the session handler for HTTP

View File

@ -8,10 +8,10 @@ import (
"net/http/httptest" "net/http/httptest"
"testing" "testing"
"github.com/grassrootseconomics/go-vise/engine"
viseerrors "git.grassecon.net/grassrootseconomics/visedriver/errors" viseerrors "git.grassecon.net/grassrootseconomics/visedriver/errors"
"git.grassecon.net/grassrootseconomics/visedriver/request" "git.grassecon.net/grassrootseconomics/visedriver/request"
"git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks/httpmocks" "git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks/httpmocks"
"github.com/grassrootseconomics/go-vise/engine"
) )
// invalidRequestType is a custom type to test invalid request scenarios // invalidRequestType is a custom type to test invalid request scenarios

View File

@ -6,13 +6,13 @@ import (
"git.grassecon.net/grassrootseconomics/visedriver/storage" "git.grassecon.net/grassrootseconomics/visedriver/storage"
"github.com/grassrootseconomics/go-vise/engine" "github.com/grassrootseconomics/go-vise/engine"
"github.com/grassrootseconomics/go-vise/logging"
"github.com/grassrootseconomics/go-vise/persist" "github.com/grassrootseconomics/go-vise/persist"
"github.com/grassrootseconomics/go-vise/resource" "github.com/grassrootseconomics/go-vise/resource"
slogging "github.com/grassrootseconomics/go-vise/slog"
) )
var ( var (
logg = logging.NewVanilla().WithDomain("visedriver.request") logg = slogging.Get().With("component", "visedriver.request")
) )
type RequestSession struct { type RequestSession struct {

View File

@ -1,147 +0,0 @@
package storage
import (
"context"
"github.com/grassrootseconomics/go-vise/db"
gdbmdb "github.com/grassrootseconomics/go-vise/db/gdbm"
"github.com/grassrootseconomics/go-vise/lang"
"github.com/grassrootseconomics/go-vise/logging"
)
var (
logg = logging.NewVanilla().WithDomain("gdbmstorage")
)
var (
dbC map[string]chan db.Db
)
type ThreadGdbmDb struct {
db db.Db
connStr string
}
func NewThreadGdbmDb() *ThreadGdbmDb {
if dbC == nil {
dbC = make(map[string]chan db.Db)
}
return &ThreadGdbmDb{}
}
func (tdb *ThreadGdbmDb) Connect(ctx context.Context, connStr string) error {
var ok bool
_, ok = dbC[connStr]
if ok {
logg.WarnCtxf(ctx, "already registered thread gdbm, skipping", "connStr", connStr)
return nil
}
gdb := gdbmdb.NewGdbmDb()
err := gdb.Connect(ctx, connStr)
if err != nil {
return err
}
dbC[connStr] = make(chan db.Db, 1)
dbC[connStr] <- gdb
tdb.connStr = connStr
return nil
}
func (tdb *ThreadGdbmDb) reserve() {
if tdb.db == nil {
tdb.db = <-dbC[tdb.connStr]
}
}
func (tdb *ThreadGdbmDb) release() {
if tdb.db == nil {
return
}
dbC[tdb.connStr] <- tdb.db
tdb.db = nil
}
func (tdb *ThreadGdbmDb) SetPrefix(pfx uint8) {
tdb.reserve()
tdb.db.SetPrefix(pfx)
}
func (tdb *ThreadGdbmDb) SetSession(sessionId string) {
tdb.reserve()
tdb.db.SetSession(sessionId)
}
func (tdb *ThreadGdbmDb) SetLanguage(lng *lang.Language) {
tdb.reserve()
tdb.db.SetLanguage(lng)
}
func (tdb *ThreadGdbmDb) Safe() bool {
tdb.reserve()
v := tdb.db.Safe()
tdb.release()
return v
}
func (tdb *ThreadGdbmDb) Prefix() uint8 {
tdb.reserve()
v := tdb.db.Prefix()
tdb.release()
return v
}
func (tdb *ThreadGdbmDb) SetLock(typ uint8, locked bool) error {
tdb.reserve()
err := tdb.db.SetLock(typ, locked)
tdb.release()
return err
}
func (tdb *ThreadGdbmDb) Put(ctx context.Context, key []byte, val []byte) error {
tdb.reserve()
err := tdb.db.Put(ctx, key, val)
tdb.release()
return err
}
func (tdb *ThreadGdbmDb) Get(ctx context.Context, key []byte) ([]byte, error) {
tdb.reserve()
v, err := tdb.db.Get(ctx, key)
tdb.release()
return v, err
}
func (tdb *ThreadGdbmDb) Close(ctx context.Context) error {
tdb.reserve()
close(dbC[tdb.connStr])
delete(dbC, tdb.connStr)
err := tdb.db.Close(ctx)
tdb.db = nil
return err
}
func (tdb *ThreadGdbmDb) Dump(ctx context.Context, key []byte) (*db.Dumper, error) {
tdb.reserve()
defer tdb.release()
return tdb.db.Dump(ctx, key)
}
func (tdb *ThreadGdbmDb) DecodeKey(ctx context.Context, key []byte) ([]byte, error) {
return tdb.db.DecodeKey(ctx, key)
}
func (tdb *ThreadGdbmDb) Abort(ctx context.Context) {
tdb.db.Abort(ctx)
}
func (tdb *ThreadGdbmDb) Start(ctx context.Context) error {
return tdb.db.Start(ctx)
}
func (tdb *ThreadGdbmDb) Stop(ctx context.Context) error {
return tdb.db.Stop(ctx)
}
func (tdb *ThreadGdbmDb) Connection() string {
return tdb.db.Connection()
}

View File

@ -11,14 +11,14 @@ import (
memdb "github.com/grassrootseconomics/go-vise/db/mem" memdb "github.com/grassrootseconomics/go-vise/db/mem"
"github.com/grassrootseconomics/go-vise/db/postgres" "github.com/grassrootseconomics/go-vise/db/postgres"
"github.com/grassrootseconomics/go-vise/lang" "github.com/grassrootseconomics/go-vise/lang"
"github.com/grassrootseconomics/go-vise/logging"
"github.com/grassrootseconomics/go-vise/persist" "github.com/grassrootseconomics/go-vise/persist"
"github.com/grassrootseconomics/go-vise/resource" "github.com/grassrootseconomics/go-vise/resource"
slogging "github.com/grassrootseconomics/go-vise/slog"
"github.com/jackc/pgx/v5/pgxpool" "github.com/jackc/pgx/v5/pgxpool"
) )
var ( var (
logg = logging.NewVanilla().WithDomain("storage") logg = slogging.Get().With("component", "storage")
) )
type StorageService interface { type StorageService interface {
@ -92,6 +92,7 @@ func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, section string,
return nil, err return nil, err
} }
newDb = postgres.NewPgDb().WithSchema(connData.Domain()) newDb = postgres.NewPgDb().WithSchema(connData.Domain())
} else if dbTyp == DBTYPE_FS { } else if dbTyp == DBTYPE_FS {
err = ms.ensureDbDir(connStr) err = ms.ensureDbDir(connStr)
if err != nil { if err != nil {