Commit: Bulk unfinished work
This commit is contained in:
139
cmd/api/main.go
139
cmd/api/main.go
@@ -1,63 +1,94 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"log/slog"
|
||||
"os"
|
||||
"time"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.kocoder.xyz/kocoded/vt/routers"
|
||||
kfx "git.kocoder.xyz/kocoded/vt/fx"
|
||||
"git.kocoder.xyz/kocoded/vt/fx/interfaces"
|
||||
"git.kocoder.xyz/kocoded/vt/fx/interfaces/stores"
|
||||
"git.kocoder.xyz/kocoded/vt/integration"
|
||||
"git.kocoder.xyz/kocoded/vt/integration/mailing"
|
||||
"git.kocoder.xyz/kocoded/vt/interceptors"
|
||||
"git.kocoder.xyz/kocoded/vt/repositories"
|
||||
mandantv1 "git.kocoder.xyz/kocoded/vt/routers/mandant/v1"
|
||||
messagebusv1 "git.kocoder.xyz/kocoded/vt/routers/messagebus/v1"
|
||||
projectv1 "git.kocoder.xyz/kocoded/vt/routers/project/v1"
|
||||
todov1 "git.kocoder.xyz/kocoded/vt/routers/todo/v1"
|
||||
"git.kocoder.xyz/kocoded/vt/utils"
|
||||
"github.com/gofiber/contrib/websocket"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/joho/godotenv"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
|
||||
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
logger.Error("Error Loading Environment variables! ", "error", err)
|
||||
}
|
||||
|
||||
db := utils.SetupDatabase(os.Getenv("DB_DSN"), logger)
|
||||
cache, ok := utils.SetupCache(os.Getenv("VALKEY_HOST"), os.Getenv("VALKEY_PORT"), os.Getenv("VALKEY_USER"), os.Getenv("VALKEY_PASS"))
|
||||
if !ok {
|
||||
logger.Error("Configuring and connecting to Valkey failed!")
|
||||
}
|
||||
|
||||
appCtx := utils.Application{Logger: logger, DB: db, Client: cache}
|
||||
|
||||
app := fiber.New()
|
||||
|
||||
utils.RegisterMiddlewares(app)
|
||||
|
||||
utils.CreateOIDCClient(context.Background(), app, appCtx)
|
||||
|
||||
routers.RegisterMandantRouter(app.Group("/v1/mandant"), appCtx)
|
||||
routers.RegisterAnsprechpartnerRouter(app.Group("/v1/ansprechpartner"), appCtx)
|
||||
routers.RegisterFirmaRouter(app.Group("/v1/firma"), appCtx)
|
||||
routers.RegisterProjectRouter(app.Group("/v1/projects"), appCtx)
|
||||
routers.RegisterUserRouter(app.Group("/v1/users"), appCtx)
|
||||
|
||||
app.Use("/ws", func(c *fiber.Ctx) error {
|
||||
if websocket.IsWebSocketUpgrade(c) {
|
||||
c.Locals("allowed", true)
|
||||
return c.Next()
|
||||
}
|
||||
return fiber.ErrUpgradeRequired
|
||||
})
|
||||
|
||||
app.Get("/ws", websocket.New(func(c *websocket.Conn) {
|
||||
go func() {
|
||||
time.Sleep(time.Second)
|
||||
}()
|
||||
|
||||
utils.MessageBus.AddConn(1, c)
|
||||
|
||||
}))
|
||||
|
||||
log.Fatalln(app.Listen(":3000"))
|
||||
func AsIntegration(f any) any {
|
||||
return fx.Annotate(
|
||||
f,
|
||||
fx.As(new(interfaces.BasicIntegration)),
|
||||
fx.ResultTags(`group:"integration"`),
|
||||
)
|
||||
}
|
||||
|
||||
func AsRoute(f any) any {
|
||||
return fx.Annotate(
|
||||
f,
|
||||
fx.As(new(kfx.Handler)),
|
||||
fx.ResultTags(`group:"connectRoute"`),
|
||||
)
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := godotenv.Load()
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Error loading env vars... %v", err)
|
||||
}
|
||||
|
||||
fx.New(
|
||||
fx.Provide(
|
||||
kfx.NewHTTPServer,
|
||||
utils.NewReflector,
|
||||
utils.NewHealthchecker,
|
||||
|
||||
utils.NewDB,
|
||||
utils.NewCache,
|
||||
|
||||
utils.NewOIDCProvider,
|
||||
utils.NewOIDCVerifier,
|
||||
|
||||
fx.Annotate(repositories.NewSessionRepository, fx.As(new(stores.SessionStore))),
|
||||
fx.Annotate(repositories.NewInMemeoryMessageRepository, fx.As(new(stores.MessageStore))),
|
||||
interceptors.NewOIDCInterceptor,
|
||||
|
||||
AsIntegration(mailing.NewImapIntegration),
|
||||
fx.Annotate(
|
||||
integration.NewIntegrationHandler,
|
||||
fx.ParamTags(`group:"integration"`),
|
||||
),
|
||||
|
||||
kfx.NewOtelLoggerProvider,
|
||||
kfx.NewOtelMeterProvider,
|
||||
kfx.NewOtelTracerProvider,
|
||||
kfx.NewLogger,
|
||||
|
||||
AsRoute(utils.NewHealthCheckV1),
|
||||
|
||||
AsRoute(utils.NewReflectorV1),
|
||||
AsRoute(utils.NewReflectorV1Alpha1),
|
||||
|
||||
AsRoute(kfx.NewEchoHandler),
|
||||
|
||||
AsRoute(messagebusv1.NewMessagebusRoute),
|
||||
|
||||
AsRoute(projectv1.NewProjectRoute),
|
||||
AsRoute(todov1.NewTodoRoute),
|
||||
AsRoute(mandantv1.NewMandantRoute),
|
||||
|
||||
fx.Annotate(
|
||||
kfx.NewServeMux,
|
||||
fx.ParamTags(`group:"connectRoute"`),
|
||||
),
|
||||
),
|
||||
|
||||
fx.Invoke(func(*integration.IntegrationHandler) {}, kfx.SetupOTelSDK, func(*http.Server) {}),
|
||||
).Run()
|
||||
}
|
||||
|
||||
38
cmd/generate/main.go
Normal file
38
cmd/generate/main.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"git.kocoder.xyz/kocoded/vt/model"
|
||||
"github.com/joho/godotenv"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
slog.Error("Error Loading Environment variables! ", "error", err)
|
||||
}
|
||||
|
||||
db, err := gorm.Open(postgres.Open(os.Getenv("DB_DSN")), &gorm.Config{})
|
||||
if err != nil {
|
||||
slog.Error("Error connecting to the Database", "error", err)
|
||||
}
|
||||
|
||||
g := gen.NewGenerator(gen.Config{
|
||||
OutPath: "query",
|
||||
Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode
|
||||
})
|
||||
|
||||
// gormdb, _ := gorm.Open(mysql.Open("root:@(127.0.0.1:3306)/demo?charset=utf8mb4&parseTime=True&loc=Local"))
|
||||
g.UseDB(db) // reuse your gorm db
|
||||
|
||||
// Generate basic type-safe DAO API for struct `model.User` following conventions
|
||||
g.ApplyBasic(model.Mandant{}, model.User{}, model.Ansprechpartner{}, model.Dokument{}, model.Firma{}, model.Kalender{}, model.Kalendereintrag{}, model.Kostenstelle{}, model.Lager{}, model.Lagerplatz{}, model.Material{}, model.Nachricht{}, model.Projekt{}, model.Rechnung{}, model.Rechnungsposition{}, model.Scanobject{}, model.User{}, model.Zahlung{}, model.FirmaAnsprechpartner{}, model.Task{})
|
||||
|
||||
// Generate the code
|
||||
g.Execute()
|
||||
}
|
||||
Reference in New Issue
Block a user