Gofmt
This commit is contained in:
parent
f7d31e4e81
commit
d5e636fbd6
@ -25,7 +25,7 @@ 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,9 +7,9 @@ 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 {
|
||||
@ -20,7 +20,7 @@ type BaseRequestHandler struct {
|
||||
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"
|
||||
)
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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,7 +7,6 @@ import (
|
||||
"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 (
|
||||
@ -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]
|
||||
}
|
||||
|
||||
@ -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,7 +228,7 @@ 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
|
||||
@ -237,7 +237,7 @@ func (ms *MenuStorageService) Close(ctx context.Context) error {
|
||||
}
|
||||
if haveErr {
|
||||
errStr := ""
|
||||
for i, err := range(errs) {
|
||||
for i, err := range errs {
|
||||
errStr += fmt.Sprintf("(%d: %v)", i, err)
|
||||
}
|
||||
return errors.New(errStr)
|
||||
|
@ -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