Gofmt
This commit is contained in:
parent
f7d31e4e81
commit
d5e636fbd6
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 (
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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())
|
||||
|
@ -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,
|
||||
},
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -22,4 +22,4 @@ func (m *MockWriter) Header() http.Header {
|
||||
return http.Header{}
|
||||
}
|
||||
|
||||
func (m *MockWriter) WriteHeader(statusCode int) {}
|
||||
func (m *MockWriter) WriteHeader(statusCode int) {}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user