s3browser-backend/internal/s3Broswer.go

66 lines
1.6 KiB
Go

package s3browser
import (
"context"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
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"
types "git.kapelle.org/niklas/s3browser/internal/types"
)
// setupS3Client connect the s3Client
func setupS3Client(config types.AppConfig) (*minio.Client, error) {
return minio.New(config.S3Endoint, &minio.Options{
Creds: credentials.NewStaticV4(config.S3AccessKey, config.S3SecretKey, ""),
Secure: config.S3SSL,
})
}
// Start starts the app
func Start(config types.AppConfig) {
if config.LogDebug {
log.SetLevel(log.DebugLevel)
}
log.Info("Starting")
s3Client, err := setupS3Client(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
}
}