draincloud-core/internal/app/app.go

69 lines
1.6 KiB
Go
Raw Normal View History

2024-09-27 22:37:58 +00:00
package app
import (
2024-10-10 21:36:51 +00:00
"context"
2024-09-30 22:21:37 +00:00
"git.optclblast.xyz/draincloud/draincloud-core/internal/app/handlers"
2024-11-23 08:52:06 +00:00
filesengine "git.optclblast.xyz/draincloud/draincloud-core/internal/files_engine"
2024-12-29 23:15:44 +00:00
"git.optclblast.xyz/draincloud/draincloud-core/internal/processor"
resolvedispatcher "git.optclblast.xyz/draincloud/draincloud-core/internal/resolve_dispatcher"
"git.optclblast.xyz/draincloud/draincloud-core/internal/resolvers/auth"
2024-10-10 21:36:51 +00:00
"git.optclblast.xyz/draincloud/draincloud-core/internal/storage"
2024-09-27 22:37:58 +00:00
"github.com/gin-gonic/gin"
)
type DrainCloud struct {
2024-11-23 08:52:06 +00:00
mux *gin.Engine
database storage.Database
filesEngine *filesengine.FilesEngine
2024-12-29 23:15:44 +00:00
ginProcessor processor.Processor[gin.HandlerFunc]
2024-09-27 22:37:58 +00:00
}
2024-10-20 09:12:54 +00:00
func New(
ctx context.Context,
2024-11-23 08:52:06 +00:00
database storage.Database,
filesEngine *filesengine.FilesEngine,
2024-10-20 09:12:54 +00:00
) *DrainCloud {
2024-09-27 22:37:58 +00:00
mux := gin.Default()
dispatcher := resolvedispatcher.New()
dispatcher.RegisterResolver(
ctx,
auth.AuthResolverV1Name,
auth.NewAuthResolver(database),
)
2024-10-20 09:12:54 +00:00
d := &DrainCloud{
database: database,
filesEngine: filesEngine,
ginProcessor: processor.NewGinProcessor(database, dispatcher),
2024-10-20 09:12:54 +00:00
}
2024-09-27 22:37:58 +00:00
2024-10-20 09:12:54 +00:00
// Built-in auth component of DrainCloud-Core
2024-09-27 22:37:58 +00:00
authGroup := mux.Group("/auth")
{
authGroup.POST("/register", d.ginProcessor.Process(
handlers.NewRegisterHandler(database),
))
authGroup.POST("/logon", d.ginProcessor.Process(
handlers.NewLogonHandler(database),
))
2024-11-23 08:52:06 +00:00
}
filesGroup := mux.Group("/files")
{
filesGroup.POST("/upload", d.ginProcessor.Process(
handlers.NewUploadFileHandler(filesEngine),
))
2024-09-27 22:37:58 +00:00
}
d.mux = mux
return d
}
2024-10-10 21:36:51 +00:00
func (d *DrainCloud) Run(ctx context.Context) error {
return d.mux.Run()
}