Simplify main.go
This commit is contained in:
@@ -1,94 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
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/joho/godotenv"
|
||||
"go.uber.org/fx"
|
||||
"git.kocoder.xyz/kocoded/vt/core"
|
||||
"git.kocoder.xyz/kocoded/vt/fx"
|
||||
)
|
||||
|
||||
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()
|
||||
core.Main(fx.SetupOTelSDK, func(*http.Server) {})
|
||||
}
|
||||
|
||||
19
cmd/cronjobs/imap/main.go
Normal file
19
cmd/cronjobs/imap/main.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.kocoder.xyz/kocoded/vt/core"
|
||||
"git.kocoder.xyz/kocoded/vt/integration"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
|
||||
defer cancel()
|
||||
|
||||
app := core.Main(func(*integration.IntegrationHandler) {})
|
||||
app.Stop(ctx)
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user