Starting to improve the project structure

This commit is contained in:
2025-05-17 18:43:54 +03:30
parent cb5149b7bc
commit ab9254fcad
11 changed files with 874 additions and 16 deletions

79
internal/config/config.go Normal file
View File

@@ -0,0 +1,79 @@
package config
import (
//"CatsOfMastodonBotGo/internal/auth"
"CatsOfMastodonBotGo/internal/database"
//"CatsOfMastodonBotGo/internal/services"
"log"
"os"
"gorm.io/gorm"
)
type config struct {
Db *gorm.DB
// PostService *services.PostService
// Jwt *auth.JwtTokenGenerator
AdminPassword string
Instance string
Tag string
}
func SetupAppContext() *config {
// Get mastodon instance
instance := os.Getenv("CAOM_INSTANCE")
if instance == "" {
instance = "https://mstdn.party"
}
// Get mastodon tag
tag := os.Getenv("CAOM_TAG")
if tag == "" {
tag = "catsofmastodon"
}
// Get admin password (Its a single user/admin app so its just fine)
adminPassword := os.Getenv("CAOM_ADMIN_PASSWORD")
if adminPassword == "" {
log.Println("No admin password provided, using default password 'catsaregood'")
adminPassword = "catsaregood"
}
// Jwt params
secret := os.Getenv("CAOM_JWT_SECRET")
if secret == "" {
log.Fatal("No jwt secret provided, using default secret 'secret'")
}
issuer := os.Getenv("CAOM_JWT_ISSUER")
if issuer == "" {
log.Println("No jwt issuer provided, using default issuer 'CatsOfMastodonBotGo'")
issuer = "CatsOfMastodonBotGo"
}
audience := os.Getenv("CAOM_JWT_AUDIENCE")
if audience == "" {
log.Println("No jwt audience provided, using default audience 'CatsOfMastodonBotGo'")
audience = "CatsOfMastodonBotGo"
}
// Setup database
db, err := database.Connect()
if err != nil {
log.Fatal(err)
}
//Setup PostService
// var postService = services.NewPostService(db)
// // Setup Jwt
// var jwt = auth.NewJwtTokenGenerator(secret, issuer, audience)
// Inititlize AppContext
var appContext = &config{
Db: db,
// PostService: postService,
// Jwt: jwt,
AdminPassword: adminPassword,
Instance: instance,
Tag: tag,
}
return appContext
}