diff --git a/config/config.go b/config/config.go index 0c827bd..2a2c9f5 100644 --- a/config/config.go +++ b/config/config.go @@ -9,23 +9,23 @@ import ( ) var ( - logg = logging.NewVanilla().WithDomain("visedriver-config") - defaultLanguage = "eng" - languages []string - DefaultLanguage string - dbConn string - dbConnMissing bool - stateDbConn string - resourceDbConn string - userDbConn string - Languages []string + logg = logging.NewVanilla().WithDomain("visedriver-config") + defaultLanguage = "eng" + languages []string + DefaultLanguage string + dbConn string + dbConnMissing bool + stateDbConn string + resourceDbConn string + userDbConn string + Languages []string ) func setLanguage() error { defaultLanguage = env.GetEnv("DEFAULT_LANGUAGE", defaultLanguage) languages = strings.Split(env.GetEnv("LANGUAGES", defaultLanguage), ",") haveDefaultLanguage := false - for i, v := range(languages) { + for i, v := range languages { languages[i] = strings.ReplaceAll(v, " ", "") if languages[i] == defaultLanguage { haveDefaultLanguage = true @@ -48,6 +48,7 @@ func setConn() error { } func ApplyConn(connStr *string, stateConnStr *string, resourceConnStr *string, userConnStr *string) { + logg.Infof("applyconn", "state", stateConnStr, "user", userConnStr) if connStr != nil { dbConn = *connStr } diff --git a/entry/handlers.go b/entry/handlers.go index ef85be4..8622e6a 100644 --- a/entry/handlers.go +++ b/entry/handlers.go @@ -2,8 +2,9 @@ package entry import ( "context" - "git.defalsify.org/vise.git/resource" + "git.defalsify.org/vise.git/persist" + "git.defalsify.org/vise.git/resource" ) type EntryHandler interface { diff --git a/request/base.go b/request/base.go index 7a38851..65bcf58 100644 --- a/request/base.go +++ b/request/base.go @@ -7,20 +7,20 @@ import ( "git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/resource" - "git.grassecon.net/grassrootseconomics/visedriver/storage" - "git.grassecon.net/grassrootseconomics/visedriver/errors" "git.grassecon.net/grassrootseconomics/visedriver/entry" + "git.grassecon.net/grassrootseconomics/visedriver/errors" + "git.grassecon.net/grassrootseconomics/visedriver/storage" ) type BaseRequestHandler struct { cfgTemplate engine.Config - rp RequestParser - rs resource.Resource - hn entry.EntryHandler - provider storage.StorageProvider + rp RequestParser + rs resource.Resource + hn entry.EntryHandler + provider storage.StorageProvider } -//func NewBaseRequestHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp request.RequestParser, hn *handlers.Handlers) *BaseRequestHandler { +// func NewBaseRequestHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp request.RequestParser, hn *handlers.Handlers) *BaseRequestHandler { func NewBaseRequestHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp RequestParser, hn entry.EntryHandler) *BaseRequestHandler { return &BaseRequestHandler{ cfgTemplate: cfg, @@ -44,7 +44,7 @@ func (f *BaseRequestHandler) GetEngine(cfg engine.Config, rs resource.Resource, return en } -func(f *BaseRequestHandler) Process(rqs RequestSession) (RequestSession, error) { +func (f *BaseRequestHandler) Process(rqs RequestSession) (RequestSession, error) { var r bool var err error var ok bool @@ -92,13 +92,13 @@ func(f *BaseRequestHandler) Process(rqs RequestSession) (RequestSession, error) return rqs, nil } -func(f *BaseRequestHandler) Output(rqs RequestSession) (RequestSession, error) { +func (f *BaseRequestHandler) Output(rqs RequestSession) (RequestSession, error) { var err error _, err = rqs.Engine.Flush(rqs.Ctx, rqs.Writer) return rqs, err } -func(f *BaseRequestHandler) Reset(ctx context.Context, rqs RequestSession) (RequestSession, error) { +func (f *BaseRequestHandler) Reset(ctx context.Context, rqs RequestSession) (RequestSession, error) { defer f.provider.Put(ctx, rqs.Config.SessionId, rqs.Storage) return rqs, rqs.Engine.Finish(ctx) } @@ -107,6 +107,6 @@ func (f *BaseRequestHandler) GetConfig() engine.Config { return f.cfgTemplate } -func(f *BaseRequestHandler) GetRequestParser() RequestParser { +func (f *BaseRequestHandler) GetRequestParser() RequestParser { return f.rp } diff --git a/request/http/server.go b/request/http/server.go index d514e5f..97a2dd8 100644 --- a/request/http/server.go +++ b/request/http/server.go @@ -5,8 +5,8 @@ import ( "strconv" "git.defalsify.org/vise.git/logging" - "git.grassecon.net/grassrootseconomics/visedriver/request" "git.grassecon.net/grassrootseconomics/visedriver/errors" + "git.grassecon.net/grassrootseconomics/visedriver/request" ) var ( diff --git a/request/http/server_test.go b/request/http/server_test.go index 64fc420..8bfaf8f 100644 --- a/request/http/server_test.go +++ b/request/http/server_test.go @@ -10,8 +10,8 @@ import ( "git.defalsify.org/vise.git/engine" viseerrors "git.grassecon.net/grassrootseconomics/visedriver/errors" - "git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks/httpmocks" "git.grassecon.net/grassrootseconomics/visedriver/request" + "git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks/httpmocks" ) // invalidRequestType is a custom type to test invalid request scenarios @@ -165,7 +165,7 @@ func TestDefaultRequestParser_GetSessionId(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - id, err := parser.GetSessionId(context.Background(),tt.request) + id, err := parser.GetSessionId(context.Background(), tt.request) if id != tt.expectedID { t.Errorf("Expected session ID %s, got %s", tt.expectedID, id) diff --git a/request/request.go b/request/request.go index 3132446..279d504 100644 --- a/request/request.go +++ b/request/request.go @@ -4,10 +4,10 @@ import ( "context" "io" - "git.defalsify.org/vise.git/resource" - "git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/logging" + "git.defalsify.org/vise.git/persist" + "git.defalsify.org/vise.git/resource" "git.grassecon.net/grassrootseconomics/visedriver/storage" ) @@ -16,12 +16,12 @@ var ( ) type RequestSession struct { - Ctx context.Context - Config engine.Config - Engine engine.Engine - Input []byte - Storage *storage.Storage - Writer io.Writer + Ctx context.Context + Config engine.Config + Engine engine.Engine + Input []byte + Storage *storage.Storage + Writer io.Writer Continue bool } @@ -34,7 +34,7 @@ type RequestParser interface { type RequestHandler interface { GetConfig() engine.Config GetRequestParser() RequestParser - GetEngine(engine.Config, resource.Resource, *persist.Persister) engine.Engine + GetEngine(engine.Config, resource.Resource, *persist.Persister) engine.Engine Process(RequestSession) (RequestSession, error) Output(RequestSession) (RequestSession, error) Reset(context.Context, RequestSession) (RequestSession, error) diff --git a/storage/conn.go b/storage/conn.go index 2eb0f0b..97daaca 100644 --- a/storage/conn.go +++ b/storage/conn.go @@ -35,7 +35,7 @@ func (c Conns) Set(conn ConnData, typ int8) { } func (c Conns) Have(conn *ConnData) int8 { - for i := range(_STORETYPE_MAX) { + for i := range _STORETYPE_MAX { ii := int8(i) v, ok := c[ii] if !ok { @@ -49,8 +49,8 @@ func (c Conns) Have(conn *ConnData) int8 { } type ConnData struct { - typ int - str string + typ int + str string domain string } diff --git a/storage/db/gdbm/gdbm.go b/storage/db/gdbm/gdbm.go index 32fed60..4d74a11 100644 --- a/storage/db/gdbm/gdbm.go +++ b/storage/db/gdbm/gdbm.go @@ -18,7 +18,7 @@ var ( ) type ThreadGdbmDb struct { - db db.Db + db db.Db connStr string } @@ -29,7 +29,7 @@ func NewThreadGdbmDb() *ThreadGdbmDb { return &ThreadGdbmDb{} } -func(tdb *ThreadGdbmDb) Connect(ctx context.Context, connStr string) error { +func (tdb *ThreadGdbmDb) Connect(ctx context.Context, connStr string) error { var ok bool _, ok = dbC[connStr] if ok { @@ -42,18 +42,18 @@ func(tdb *ThreadGdbmDb) Connect(ctx context.Context, connStr string) error { return err } dbC[connStr] = make(chan db.Db, 1) - dbC[connStr]<- gdb + dbC[connStr] <- gdb tdb.connStr = connStr return nil } -func(tdb *ThreadGdbmDb) reserve() { +func (tdb *ThreadGdbmDb) reserve() { if tdb.db == nil { tdb.db = <-dbC[tdb.connStr] } } -func(tdb *ThreadGdbmDb) release() { +func (tdb *ThreadGdbmDb) release() { if tdb.db == nil { return } @@ -61,57 +61,57 @@ func(tdb *ThreadGdbmDb) release() { tdb.db = nil } -func(tdb *ThreadGdbmDb) SetPrefix(pfx uint8) { +func (tdb *ThreadGdbmDb) SetPrefix(pfx uint8) { tdb.reserve() tdb.db.SetPrefix(pfx) } -func(tdb *ThreadGdbmDb) SetSession(sessionId string) { +func (tdb *ThreadGdbmDb) SetSession(sessionId string) { tdb.reserve() tdb.db.SetSession(sessionId) } -func(tdb *ThreadGdbmDb) SetLanguage(lng *lang.Language) { +func (tdb *ThreadGdbmDb) SetLanguage(lng *lang.Language) { tdb.reserve() tdb.db.SetLanguage(lng) } -func(tdb *ThreadGdbmDb) Safe() bool { +func (tdb *ThreadGdbmDb) Safe() bool { tdb.reserve() v := tdb.db.Safe() tdb.release() return v } -func(tdb *ThreadGdbmDb) Prefix() uint8 { +func (tdb *ThreadGdbmDb) Prefix() uint8 { tdb.reserve() v := tdb.db.Prefix() tdb.release() return v } -func(tdb *ThreadGdbmDb) SetLock(typ uint8, locked bool) error { +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 { +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) { +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 { +func (tdb *ThreadGdbmDb) Close(ctx context.Context) error { tdb.reserve() close(dbC[tdb.connStr]) delete(dbC, tdb.connStr) @@ -120,28 +120,28 @@ func(tdb *ThreadGdbmDb) Close(ctx context.Context) error { return err } -func(tdb *ThreadGdbmDb) Dump(ctx context.Context, key []byte) (*db.Dumper, error) { +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) { +func (tdb *ThreadGdbmDb) DecodeKey(ctx context.Context, key []byte) ([]byte, error) { return tdb.db.DecodeKey(ctx, key) } -func(tdb *ThreadGdbmDb) Abort(ctx context.Context) { +func (tdb *ThreadGdbmDb) Abort(ctx context.Context) { tdb.db.Abort(ctx) } -func(tdb *ThreadGdbmDb) Start(ctx context.Context) error { +func (tdb *ThreadGdbmDb) Start(ctx context.Context) error { return tdb.db.Start(ctx) } -func(tdb *ThreadGdbmDb) Stop(ctx context.Context) error { +func (tdb *ThreadGdbmDb) Stop(ctx context.Context) error { return tdb.db.Stop(ctx) } -func(tdb *ThreadGdbmDb) Connection() string { +func (tdb *ThreadGdbmDb) Connection() string { return tdb.db.Connection() } diff --git a/storage/parse_test.go b/storage/parse_test.go index 44b755f..59b9ece 100644 --- a/storage/parse_test.go +++ b/storage/parse_test.go @@ -7,28 +7,28 @@ import ( func TestParseConnStr(t *testing.T) { v, err := ToConnData("postgres://foo:bar@localhost:5432/baz") if err != nil { - t.Fatal(err) + t.Fatal(err) } if v.DbType() != DBTYPE_POSTGRES { t.Fatalf("expected type %v, got %v", DBTYPE_POSTGRES, v.DbType()) } v, err = ToConnData("gdbm:///foo/bar") if err != nil { - t.Fatal(err) + t.Fatal(err) } if v.DbType() != DBTYPE_GDBM { t.Fatalf("expected type %v, got %v", DBTYPE_GDBM, v.DbType()) } v, err = ToConnData("/foo/bar") if err != nil { - t.Fatal(err) + t.Fatal(err) } if v.DbType() != DBTYPE_FS { t.Fatalf("expected type %v, got %v", DBTYPE_FS, v.DbType()) } v, err = ToConnData("/foo/bar/") if err != nil { - t.Fatal(err) + t.Fatal(err) } if v.DbType() != DBTYPE_FS { t.Fatalf("expected type %v, got %v", DBTYPE_FS, v.DbType()) diff --git a/storage/storage.go b/storage/storage.go index c4a69bb..391835c 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -12,8 +12,8 @@ const ( ) type Storage struct { - Persister *persist.Persister - UserdataDb db.Db + Persister *persist.Persister + UserdataDb db.Db } func (s *Storage) Close(ctx context.Context) error { @@ -35,7 +35,7 @@ func NewSimpleStorageProvider(stateStore db.Db, userdataStore db.Db) StorageProv pe = pe.WithFlush() return &SimpleStorageProvider{ Storage: &Storage{ - Persister: pe, + Persister: pe, UserdataDb: userdataStore, }, } diff --git a/storage/storage_service.go b/storage/storage_service.go index fcf58f5..d4e409f 100644 --- a/storage/storage_service.go +++ b/storage/storage_service.go @@ -6,8 +6,7 @@ import ( "fmt" "os" "path" - - "github.com/jackc/pgx/v5/pgxpool" + "git.defalsify.org/vise.git/db" fsdb "git.defalsify.org/vise.git/db/fs" memdb "git.defalsify.org/vise.git/db/mem" @@ -17,6 +16,7 @@ import ( "git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/resource" gdbmstorage "git.grassecon.net/grassrootseconomics/visedriver/storage/db/gdbm" + "github.com/jackc/pgx/v5/pgxpool" ) var ( @@ -30,9 +30,9 @@ type StorageService interface { } type MenuStorageService struct { - conns Conns - poResource resource.Resource - store map[int8]db.Db + conns Conns + poResource resource.Resource + store map[int8]db.Db } func NewMenuStorageService(conn Conns) *MenuStorageService { @@ -55,7 +55,7 @@ func (ms *MenuStorageService) WithDb(store db.Db, typ int8) *MenuStorageService return ms } -func (ms *MenuStorageService) checkDb(ctx context.Context,typ int8) db.Db { +func (ms *MenuStorageService) checkDb(ctx context.Context, typ int8) db.Db { store := ms.store[typ] if store != nil { return store @@ -70,7 +70,7 @@ func (ms *MenuStorageService) checkDb(ctx context.Context,typ int8) db.Db { return nil } ms.store[typ] = ms.store[v] - logg.DebugCtxf(ctx, "found existing db", "typ", typ, "srctyp", v, "store", ms.store[typ], "srcstore", ms.store[v]) + logg.DebugCtxf(ctx, "found existing db", "typ", typ, "srctyp", v, "store", ms.store[typ], "srcstore", ms.store[v], "conn", connData) return ms.store[typ] } @@ -124,7 +124,7 @@ func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, section string, // WithGettext triggers use of gettext for translation of templates and menus. // -// The first language in `lns` will be used as default language, to resolve node keys to +// The first language in `lns` will be used as default language, to resolve node keys to // language strings. // // If `lns` is an empty array, gettext will not be used. @@ -135,7 +135,7 @@ func (ms *MenuStorageService) WithGettext(path string, lns []lang.Language) *Men } rs := resource.NewPoResource(lns[0], path) - for _, ln := range(lns) { + for _, ln := range lns { rs = rs.WithLanguage(ln) } @@ -228,16 +228,16 @@ func (ms *MenuStorageService) ensureDbDir(path string) error { func (ms *MenuStorageService) Close(ctx context.Context) error { var errs []error var haveErr bool - for i := range(_STORETYPE_MAX) { + for i := range _STORETYPE_MAX { err := ms.store[int8(i)].Close(ctx) if err != nil { haveErr = true } - errs = append(errs, err) + errs = append(errs, err) } if haveErr { errStr := "" - for i, err := range(errs) { + for i, err := range errs { errStr += fmt.Sprintf("(%d: %v)", i, err) } return errors.New(errStr) diff --git a/storage/storage_service_test.go b/storage/storage_service_test.go index 54d952f..37423c6 100644 --- a/storage/storage_service_test.go +++ b/storage/storage_service_test.go @@ -61,7 +61,7 @@ func TestMenuStorageServiceExplicit(t *testing.T) { if err != nil { t.Fatal(err) } - + ms := NewMenuStorageService(conns) ms = ms.WithDb(store, STORETYPE_RESOURCE) _, err = ms.GetStateStore(ctx) diff --git a/testutil/mocks/httpmocks/writer_mock.go b/testutil/mocks/httpmocks/writer_mock.go index 0d171d2..a3d455d 100644 --- a/testutil/mocks/httpmocks/writer_mock.go +++ b/testutil/mocks/httpmocks/writer_mock.go @@ -22,4 +22,4 @@ func (m *MockWriter) Header() http.Header { return http.Header{} } -func (m *MockWriter) WriteHeader(statusCode int) {} \ No newline at end of file +func (m *MockWriter) WriteHeader(statusCode int) {} diff --git a/testutil/mocks/storage.go b/testutil/mocks/storage.go index 003e48c..059bc04 100644 --- a/testutil/mocks/storage.go +++ b/testutil/mocks/storage.go @@ -5,8 +5,8 @@ import ( "git.defalsify.org/vise.git/db" memdb "git.defalsify.org/vise.git/db/mem" - "git.defalsify.org/vise.git/resource" "git.defalsify.org/vise.git/persist" + "git.defalsify.org/vise.git/resource" ) type MemStorageService struct { @@ -39,4 +39,3 @@ func (mss *MemStorageService) GetUserdataDb(ctx context.Context) (db.Db, error) func (mss *MemStorageService) GetResource(ctx context.Context) (resource.Resource, error) { return mss.rs, nil } -