Uuuh, lots of stuff

More config, moved files, some endpoints (wip), some storage
This commit is contained in:
mStar aka a person 2024-01-19 10:21:31 +00:00
parent f3514b5a42
commit 935fc33094
18 changed files with 394 additions and 70 deletions

View file

@ -13,16 +13,40 @@ package storage
import (
"fmt"
"gitlab.com/beckersam/linstrom/config"
"gitlab.com/mstarongitlab/linstrom/config"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
type Storage struct {
Db *gorm.DB
}
func NewDb(cfg *config.Config) (*gorm.DB, error) {
db, err := gorm.Open(postgres.Open(cfg.General.DbPath))
if err != nil {
return nil, fmt.Errorf("Failed to connect to db %s: %w", cfg.General.DbPath, err)
return nil, fmt.Errorf("failed to connect to db %s: %w", cfg.General.DbPath, err)
}
err = db.AutoMigrate(
&Person{},
&Note{
Tags: make([]string, 0),
DeliverTo: make([]string, 0),
},
&Follow{},
)
if err != nil {
return nil, fmt.Errorf("failed to apply migrations: %w", err)
}
db.AutoMigrate(&personDB{}, &noteDB{})
return db, nil
}
func NewStorage(cfg *config.Config) (*Storage, error) {
db, err := NewDb(cfg)
if err != nil {
return nil, fmt.Errorf("failed to create database connection while creating storage: %w", err)
}
return &Storage{
Db: db,
}, nil
}