optimize cfg
This commit is contained in:
parent
a1e7b1e00a
commit
64d15aff7f
33
app/app.go
33
app/app.go
@ -4,13 +4,14 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"gitea.pena/SQuiz/common/dal"
|
||||
"gitea.pena/SQuiz/common/healthchecks"
|
||||
"gitea.pena/SQuiz/common/middleware"
|
||||
dalBS "gitea.pena/SQuiz/storer/dal"
|
||||
"gitea.pena/SQuiz/storer/service"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"gitea.pena/PenaSide/hlog"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/skeris/appInit"
|
||||
@ -44,15 +45,15 @@ var zapOptions = []zap.Option{
|
||||
var _ appInit.CommonApp = (*App)(nil)
|
||||
|
||||
type Options struct {
|
||||
LoggerProdMode bool `env:"IS_PROD_LOG" default:"false"`
|
||||
IsProd bool `env:"IS_PROD" default:"false"`
|
||||
MinioEP string `env:"MINIO_EP" default:"localhost:3002"`
|
||||
MinioAK string `env:"MINIO_AK" default:"minio"`
|
||||
MinioSK string `env:"MINIO_SK" default:"miniostorage"`
|
||||
NumberPort string `env:"PORT" default:"1489"`
|
||||
CrtFile string `env:"CRT" default:"server.crt"`
|
||||
KeyFile string `env:"KEY" default:"server.key"`
|
||||
PostgresCredentials string `env:"PG_CRED" default:"host=localhost port=5432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"`
|
||||
LoggerProdMode bool `env:"IS_PROD_LOG" default:"false"`
|
||||
IsProd bool `env:"IS_PROD" default:"false"`
|
||||
S3Endpoint string `env:"S3_ENDPOINT" envDefault:"localhost:3002"`
|
||||
S3AccessKey string `env:"S3_ACCESS_KEY" envDefault:"minio"`
|
||||
S3SecretKey string `env:"S3_SECRET_KEY" envDefault:"miniostorage"`
|
||||
ClientHttpURL string `env:"CLIENT_HTTP_URL" envDefault:"0.0.0.0:1489"`
|
||||
CrtFile string `env:"CRT" default:"server.crt"`
|
||||
KeyFile string `env:"KEY" default:"server.key"`
|
||||
PostgresURL string `env:"POSTGRES_URL" envDefault:"host=localhost port=5432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"`
|
||||
}
|
||||
|
||||
func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.CommonApp, error) {
|
||||
@ -89,18 +90,18 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
|
||||
logger := hlog.New(zapLogger)
|
||||
logger.Emit(InfoSvcStarted{})
|
||||
|
||||
pgdal, err := dal.New(ctx, options.PostgresCredentials, nil)
|
||||
pgdal, err := dal.New(ctx, options.PostgresURL, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Initialize minio client object.
|
||||
minioClient, err := minio.New(options.MinioEP, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(options.MinioAK, options.MinioSK, ""),
|
||||
minioClient, err := minio.New(options.S3Endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(options.S3AccessKey, options.S3SecretKey, ""),
|
||||
Secure: options.IsProd,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("MINIOERR", options.MinioEP, err)
|
||||
fmt.Println("MINIOERR", options.S3Endpoint, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -130,14 +131,14 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
|
||||
}()
|
||||
|
||||
if options.IsProd {
|
||||
if err := app.ListenTLS(fmt.Sprintf(":%s", options.NumberPort), options.CrtFile, options.KeyFile); err != nil {
|
||||
if err := app.ListenTLS(options.ClientHttpURL, options.CrtFile, options.KeyFile); err != nil {
|
||||
logger.Emit(ErrorCanNotServe{
|
||||
Err: err,
|
||||
})
|
||||
errChan <- err
|
||||
}
|
||||
} else {
|
||||
if err := app.Listen(fmt.Sprintf(":%s", options.NumberPort)); err != nil {
|
||||
if err := app.Listen(options.ClientHttpURL); err != nil {
|
||||
logger.Emit(ErrorCanNotServe{
|
||||
Err: err,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user