57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package s3browser
|
|
|
|
import (
|
|
"context"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"git.kapelle.org/niklas/s3browser/internal/db"
|
|
gql "git.kapelle.org/niklas/s3browser/internal/gql"
|
|
httpserver "git.kapelle.org/niklas/s3browser/internal/httpserver"
|
|
"git.kapelle.org/niklas/s3browser/internal/loader"
|
|
"git.kapelle.org/niklas/s3browser/internal/s3"
|
|
types "git.kapelle.org/niklas/s3browser/internal/types"
|
|
)
|
|
|
|
// Start starts the app
|
|
func Start(config types.AppConfig) {
|
|
|
|
if config.LogDebug {
|
|
log.SetLevel(log.DebugLevel)
|
|
}
|
|
|
|
log.Info("Starting")
|
|
s3Client, err := s3.NewMinio(config)
|
|
|
|
if err != nil {
|
|
log.Error("Failed to setup s3 client: ", err.Error())
|
|
return
|
|
}
|
|
|
|
dbStore, err := db.NewDB(config.DSN)
|
|
if err != nil {
|
|
log.Error("Failed to connect DB: ", err.Error())
|
|
}
|
|
|
|
loader := loader.NewLoader(config)
|
|
|
|
gql.GraphqlTypes()
|
|
schema, err := gql.GraphqlSchema()
|
|
|
|
if err != nil {
|
|
log.Error("Failed to generate graphq schemas: ", err.Error())
|
|
return
|
|
}
|
|
|
|
resolveContext := context.WithValue(context.Background(), "s3Client", s3Client)
|
|
resolveContext = context.WithValue(resolveContext, "loader", loader)
|
|
resolveContext = context.WithValue(resolveContext, "dbStore", dbStore)
|
|
|
|
err = httpserver.InitHttp(resolveContext, schema, config.Address)
|
|
|
|
if err != nil {
|
|
log.Error("Failed to start webserver: ", err.Error())
|
|
return
|
|
}
|
|
}
|