s3browser-backend/internal/s3Broswer.go

64 lines
1.7 KiB
Go
Raw Normal View History

2021-07-26 12:52:36 +00:00
package s3browser
import (
"context"
2021-11-27 03:07:27 +00:00
"github.com/graph-gophers/dataloader"
2021-08-12 15:48:28 +00:00
log "github.com/sirupsen/logrus"
2021-07-26 12:52:36 +00:00
2021-11-27 03:07:27 +00:00
"git.kapelle.org/niklas/s3browser/internal/cache"
2021-10-20 14:11:18 +00:00
"git.kapelle.org/niklas/s3browser/internal/db"
2021-09-24 13:39:23 +00:00
gql "git.kapelle.org/niklas/s3browser/internal/gql"
httpserver "git.kapelle.org/niklas/s3browser/internal/httpserver"
2021-10-14 17:00:11 +00:00
"git.kapelle.org/niklas/s3browser/internal/loader"
2021-11-23 19:12:24 +00:00
"git.kapelle.org/niklas/s3browser/internal/s3"
2021-09-24 13:39:23 +00:00
types "git.kapelle.org/niklas/s3browser/internal/types"
)
2021-07-26 12:52:36 +00:00
// Start starts the app
2021-09-24 13:39:23 +00:00
func Start(config types.AppConfig) {
2021-07-26 12:52:36 +00:00
2021-09-09 11:41:38 +00:00
if config.LogDebug {
log.SetLevel(log.DebugLevel)
}
2021-08-12 15:48:28 +00:00
log.Info("Starting")
2021-11-23 19:12:24 +00:00
s3Client, err := s3.NewMinio(config)
2021-08-12 15:48:28 +00:00
if err != nil {
log.Error("Failed to setup s3 client: ", err.Error())
return
}
2021-11-04 19:28:37 +00:00
dbStore, err := db.NewDB(config.DSN)
2021-10-20 14:11:18 +00:00
if err != nil {
log.Error("Failed to connect DB: ", err.Error())
}
2021-11-27 03:07:27 +00:00
loader := loader.NewLoader(loader.CacheConfig{
ListObjectsLoaderCache: &dataloader.NoCache{},
ListObjectsRecursiveLoaderCache: &dataloader.NoCache{},
StatObjectLoaderCache: cache.NewTTLCache(config.CacheTTL, config.CacheCleanup),
ListBucketsLoaderCache: cache.NewTTLCache(config.CacheTTL, config.CacheCleanup),
})
2021-07-26 12:52:36 +00:00
2021-09-24 13:39:23 +00:00
gql.GraphqlTypes()
schema, err := gql.GraphqlSchema()
2021-07-26 12:52:36 +00:00
if err != nil {
2021-08-12 15:48:28 +00:00
log.Error("Failed to generate graphq schemas: ", err.Error())
return
2021-07-26 12:52:36 +00:00
}
2021-08-03 21:10:23 +00:00
resolveContext := context.WithValue(context.Background(), "s3Client", s3Client)
2021-10-14 17:00:11 +00:00
resolveContext = context.WithValue(resolveContext, "loader", loader)
2021-10-20 14:11:18 +00:00
resolveContext = context.WithValue(resolveContext, "dbStore", dbStore)
2021-08-03 21:10:23 +00:00
2021-09-24 13:39:23 +00:00
err = httpserver.InitHttp(resolveContext, schema, config.Address)
2021-08-06 14:31:07 +00:00
if err != nil {
2021-08-12 15:48:28 +00:00
log.Error("Failed to start webserver: ", err.Error())
return
2021-08-06 14:31:07 +00:00
}
2021-07-26 12:52:36 +00:00
}