working commit

This commit is contained in:
2026-01-26 18:36:30 +02:00
parent 15e4e893b1
commit 6db319088e
19 changed files with 621 additions and 95 deletions
+14 -6
View File
@@ -1,7 +1,17 @@
package config
type Config struct {
Service Service `json:"service" yaml:"service"`
Service Service `json:"service" yaml:"service"`
Database Database `json:"database" yaml:"database"`
}
type Service struct {
Address string `json:"address" yaml:"address"`
Port int64 `json:"port" yaml:"port"`
}
type Database struct {
Basepath string `json:"basepath" yaml:"basepath"`
}
func NewConfig() (*Config, error) {
@@ -11,10 +21,8 @@ func NewConfig() (*Config, error) {
Address: "0.0.0.0",
Port: 1025,
},
Database: Database{
Basepath: datadir,
},
}, err
}
type Service struct {
Address string `json:"address" yaml:"address"`
Port int64 `json:"port" yaml:"port"`
}
+9
View File
@@ -0,0 +1,9 @@
package config
const (
confdir = "/home/ziggi/Projects/mstore/etc/mstore"
rundir = "/home/ziggi/Projects/mstore/tmp/run"
logdir = "/home/ziggi/Projects/mstore/tmp/log"
datadir = "/home/ziggi/Projects/mstore/tmp/data"
version = "0.1.0"
)
+9
View File
@@ -0,0 +1,9 @@
package config
const (
confdir = "@srv_confdir@"
rundir = "@srv_rundir@"
logdir = "@srv_logdir@"
datadir = "@srv_datadir@"
version = "@PACKAGE_VERSION@"
)
+9 -10
View File
@@ -1,14 +1,13 @@
package descr
type File struct {
ID string `db:"id" json:"id,omitempty" yaml:"id,omitempty"`
Collection string `db:"collection" json:"collection,omitempty" yaml:"collection,omitempty"`
Name string `db:"name" json:"name,omitempty" yaml:"name,omitempty"`
Checksum string `db:"checksum" json:"checksum,omitempty" yaml:"checksum,omitempty"`
Size int64 `db:"size" json:"size,omitempty" yaml:"size,omitempty"`
CreatedAt string `db:"created_at" json:"createdAt,omitempty" yaml:"createdAt,omitempty"`
UpdatedAt string `db:"updated_at" json:"updatedAt,omitempty" yaml:"updatedAt,omitempty"`
CreatedBy string `db:"created_by" json:"createdBy,omitempty" yaml:"createdBy,omitempty"`
UpdatedBy string `db:"updated_by" json:"updatedBy,omitempty" yaml:"updatedBy,omitempty"`
ID string `db:"id" json:"id,omitempty" yaml:"id,omitempty"`
Collection string `db:"collection" json:"collection,omitempty" yaml:"collection,omitempty"`
Name string `db:"name" json:"name,omitempty" yaml:"name,omitempty"`
Checksum string `db:"checksum" json:"checksum,omitempty" yaml:"checksum,omitempty"`
Size int64 `db:"size" json:"size,omitempty" yaml:"size,omitempty"`
CreatedAt string `db:"created_at" json:"createdAt,omitempty" yaml:"createdAt,omitempty"`
UpdatedAt string `db:"updated_at" json:"updatedAt,omitempty" yaml:"updatedAt,omitempty"`
CreatedBy string `db:"created_by" json:"createdBy,omitempty" yaml:"createdBy,omitempty"`
UpdatedBy string `db:"updated_by" json:"updatedBy,omitempty" yaml:"updatedBy,omitempty"`
}
-2
View File
@@ -14,8 +14,6 @@ func (hand *Handler) FileExists(rctx *router.Context) {
}
hand.logg.Debugf("filepath: %s", filepath)
code, _, _ := hand.oper.FileExists(params)
rctx.SetStatus(code)
}
+31 -33
View File
@@ -1,48 +1,46 @@
package maindb
import (
"testing"
"testing"
"mstore/app/descr"
"mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/app/descr"
"mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
)
func TestFile(t *testing.T) {
var err error
var err error
dbDir := t.TempDir()
db := NewDatabase(dbDir)
dbDir := t.TempDir()
db := NewDatabase(dbDir)
err = db.OpenDatabase()
require.NoError(t, err)
err = db.OpenDatabase()
require.NoError(t, err)
err = db.InitDatabase()
require.NoError(t, err)
err = db.InitDatabase()
require.NoError(t, err)
id := auxuuid.NewUUID()
timenow := auxtool.TimeNow()
creator := "some"
collection := "foo"
newFile := &descr.File{
ID: id,
Collection: "foo" ,
Name: "bare",
CreatedAt: timenow,
UpdatedAt: timenow,
CreatedBy: creator,
UpdatedBy: creator,
}
id := auxuuid.NewUUID()
timenow := auxtool.TimeNow()
creator := "some"
collection := "foo"
newFile := &descr.File{
ID: id,
Collection: "foo",
Name: "bare",
CreatedAt: timenow,
UpdatedAt: timenow,
CreatedBy: creator,
UpdatedBy: creator,
}
err = db.InsertFile(newFile)
require.NoError(t, err)
err = db.InsertFile(newFile)
require.NoError(t, err)
files, err := db.ListFilesByCollection(collection)
require.NoError(t, err)
require.Equal(t, len(files), 1)
require.Equal(t, files[0].ID, id)
files, err := db.ListFilesByCollection(collection)
require.NoError(t, err)
require.Equal(t, len(files), 1)
require.Equal(t, files[0].ID, id)
}
-1
View File
@@ -10,7 +10,6 @@ import (
_ "github.com/mattn/go-sqlite3"
)
type Database struct {
datapath string
log *logger.Logger
+3 -3
View File
@@ -3,7 +3,7 @@ package operator
import (
"io"
"net/http"
"path"
//"path"
)
// File exists
@@ -17,8 +17,8 @@ type FileExistsResult struct{}
func (oper *Operator) FileExists(param *FileExistsParams) (int, *FileExistsResult, error) {
var err error
filename := path.Base(param.Filepath)
dirname := path.Dir(filepath)
//filename := path.Base(param.Filepath)
//dirname := path.Dir(filepath)
res := &FileExistsResult{}
code := http.StatusOK
+3 -3
View File
@@ -5,17 +5,17 @@ import (
)
type OperatorParams struct {
MainDB *database.Database
MainDB *maindb.Database
}
type Operator struct {
maindb *main.Database
maindb *maindb.Database
}
func NewOperator(params *OperatorParams) (*Operator, error) {
var err error
oper := &Operator{
db: params.MainDB,
maindb: params.MainDB,
}
return oper, err
}
+28 -9
View File
@@ -12,19 +12,21 @@ import (
"syscall"
//"time"
"mstore/app/database"
"mstore/app/config"
"mstore/app/handler"
"mstore/app/logger"
"mstore/app/maindb"
"mstore/app/operator"
"mstore/app/service"
)
type Server struct {
oper *operator.Operator
svc *service.Service
db *database.Database
hand *handler.Handler
logg *logger.Logger
conf *config.Config
oper *operator.Operator
svc *service.Service
maindb *maindb.Database
hand *handler.Handler
logg *logger.Logger
}
func NewServer() (*Server, error) {
@@ -41,21 +43,38 @@ func (srv *Server) Handler() *handler.Handler {
func (srv *Server) Configure() error {
var err error
srv.logg.Infof("Server configure")
srv.conf, err = config.NewConfig()
if err != nil {
return err
}
return err
}
func (srv *Server) Build() error {
var err error
srv.logg.Infof("Server build")
// Database create
databaseParams := &database.DatabaseParams{}
srv.db, err = database.NewDatabase(databaseParams)
dbdir := srv.conf.Database.Basepath
err = os.MkdirAll(srv.conf.Database.Basepath, 0750)
if err != nil {
return err
}
maindb := maindb.NewDatabase(dbdir)
err = maindb.OpenDatabase()
if err != nil {
return err
}
err = maindb.InitDatabase()
if err != nil {
return err
}
// Operator create
operatorParams := &operator.OperatorParams{
Database: srv.db,
MainDB: srv.maindb,
}
srv.oper, err = operator.NewOperator(operatorParams)
if err != nil {