diff --git a/service/configs/espressoconfig.yaml b/service/configs/espressoconfig.yaml index 192f849..cd64192 100644 --- a/service/configs/espressoconfig.yaml +++ b/service/configs/espressoconfig.yaml @@ -1,3 +1,9 @@ +app: + log_level: "debug" + server_port: 8081 + enable_ui: true + rod_browser_bin: "/opt/homebrew/bin/chromium" + template_storage: storage_type: "mysql" @@ -9,37 +15,37 @@ browser: workerpool: worker_count: 6 - worker_timeout: 310 # milliseconds + worker_timeout_ms: 310 # milliseconds s3: endpoint: "http://localstack:4566" debug: false region: "us-west-2" - forcePathStyle: true - uploaderConcurrency: 5 + force_path_style: true + uploader_concurrency: 5 # 5MB chunks - uploaderPartSize: 5 - downloaderConcurrency: 5 + uploader_part_size_mb: 5 + downloader_concurrency: 5 # 5MB chunks - downloaderPartSize: 5242880 - retryMaxAttempts: 3 + downloader_part_size_mb: 5242880 + retry_max_attempts: 3 bucket: "local-bucket" - useCustomTransport: false + use_custom_transport: false aws: - accessKeyID: "xxxxx-xxxxx-xxxxx-xxxxx-xxxxx" - secretAccessKey: "xxxxx-xxxxx-xxxxx-xxxxx-xxxxx" - sessionToken: "" + access_key_id: "xxxxx-xxxxx-xxxxx-xxxxx-xxxxx" + secret_access_key: "xxxxx-xxxxx-xxxxx-xxxxx-xxxxx" + session_token: "" -digital_certificates: +certificates: cert1: - cert_filepath: "./inputfiles/certificates/cert.pem" - key_filepath: "./inputfiles/certificates/key_pkcs8_encrypted.pem" + cert_file_path: "./inputfiles/certificates/cert.pem" + key_file_path: "./inputfiles/certificates/key_pkcs8_encrypted.pem" key_password: "test" - cert2: - cert_filepath: "./certificates/certificate2.pem" - key_filepath: "./certificates/pirvatekey2.key" - key_password: "password2" -mysql: - dsn: "pdf_user:pdf_password@tcp(mysql:3306)/pdf_templates?parseTime=true" \ No newline at end of file +db: + host: "mysql" + port: 3306 + username: "pdf_user" + password: "pdf_password" + database: "pdf_templates" \ No newline at end of file diff --git a/service/controller/pdf_generation/pdf_generation.go b/service/controller/pdf_generation/pdf_generation.go index 97c4a8a..e33c577 100644 --- a/service/controller/pdf_generation/pdf_generation.go +++ b/service/controller/pdf_generation/pdf_generation.go @@ -14,7 +14,6 @@ import ( "github.com/Zomato/espresso/service/internal/pkg/httppkg" "github.com/Zomato/espresso/service/internal/service/generateDoc" svcUtils "github.com/Zomato/espresso/service/utils" - "github.com/spf13/viper" ) func (s *EspressoService) GeneratePDF(w http.ResponseWriter, r *http.Request) { @@ -56,7 +55,7 @@ func (s *EspressoService) GeneratePDF(w http.ResponseWriter, r *http.Request) { generatePdfReq.SignParams = req.SignParams } - err = generateDoc.GeneratePDF(ctx, generatePdfReq, s.TemplateStorageAdapter, s.FileStorageAdapter) + err = generateDoc.GeneratePDF(ctx, generatePdfReq, s.TemplateStorageAdapter, s.FileStorageAdapter, s.CredentialStore) if err != nil { svcUtils.Logger.Error(ctx, "error in generating pdf :: %v", err, nil) httppkg.RespondWithError(w, "Failed to generate PDF: "+err.Error(), http.StatusInternalServerError) @@ -143,7 +142,7 @@ func (s *EspressoService) GeneratePDFStream(w http.ResponseWriter, r *http.Reque if pdfReq.SignPdf { generatePdfReq.SignParams = &generateDoc.SignParams{ SignPdf: true, - CertConfigKey: "digital_certificates.cert1", // certificate details are stored in config file + CertConfigKey: "cert1", // certificate details are stored in config file } } @@ -155,16 +154,8 @@ func (s *EspressoService) GeneratePDFStream(w http.ResponseWriter, r *http.Reque httppkg.RespondWithError(w, "Failed to get file storage adapter: "+err.Error(), http.StatusExpectationFailed) return } - templateStorageAdapter, err := templatestore.TemplateStorageAdapterFactory(&templatestore.StorageConfig{ - StorageType: "mysql", - MysqlDSN: viper.GetString("mysql.dsn"), - }) - if err != nil { - svcUtils.Logger.Error(ctx, "error in getting file storage adapter :: %v", err, nil) - httppkg.RespondWithError(w, "Failed to get file storage adapter: "+err.Error(), http.StatusExpectationFailed) - return - } - err = generateDoc.GeneratePDF(ctx, generatePdfReq, &templateStorageAdapter, &fileStorageAdapter) + + err = generateDoc.GeneratePDF(ctx, generatePdfReq, s.TemplateStorageAdapter, &fileStorageAdapter, s.CredentialStore) if err != nil { svcUtils.Logger.Error(ctx, "error in generating pdf stream:: %v", err, nil) httppkg.RespondWithError(w, "Failed to generate PDF stream: "+err.Error(), http.StatusInternalServerError) @@ -243,7 +234,7 @@ func (s *EspressoService) SignPDF(w http.ResponseWriter, r *http.Request) { httppkg.RespondWithError(w, err.Error(), http.StatusBadRequest) return } - err := generateDoc.SignPDF(ctx, signPDFDto, s.FileStorageAdapter) + err := generateDoc.SignPDF(ctx, signPDFDto, s.FileStorageAdapter, s.CredentialStore) if err != nil { svcUtils.Logger.Error(ctx, "error in signing pdf :: : %v", err, nil) httppkg.RespondWithError(w, "Failed to sign PDF: "+err.Error(), http.StatusInternalServerError) diff --git a/service/controller/pdf_generation/register.go b/service/controller/pdf_generation/register.go index e4e8454..58008b7 100644 --- a/service/controller/pdf_generation/register.go +++ b/service/controller/pdf_generation/register.go @@ -4,62 +4,63 @@ import ( "fmt" "log" "net/http" - "os" - "github.com/Zomato/espresso/lib/s3" + "github.com/Zomato/espresso/lib/certmanager" "github.com/Zomato/espresso/lib/templatestore" - "github.com/spf13/viper" + "github.com/Zomato/espresso/service/internal/pkg/config" ) type EspressoService struct { TemplateStorageAdapter *templatestore.StorageAdapter FileStorageAdapter *templatestore.StorageAdapter + CredentialStore *certmanager.CredentialStore } -func NewEspressoService() (*EspressoService, error) { - templateStorageType := viper.GetString("template_storage.storage_type") - if os.Getenv("ENABLE_UI") == "true" && templateStorageType != templatestore.StorageAdapterTypeMySQL { +func NewEspressoService(config config.Config) (*EspressoService, error) { + templateStorageType := config.TemplateStorageConfig.StorageType + + if config.AppConfig.EnableUI && templateStorageType != templatestore.StorageAdapterTypeMySQL { return nil, fmt.Errorf("UI requires MySQL as template storage adapter, got: %s", templateStorageType) } + + mySqlDsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?parseTime=true", + config.DBConfig.Username, + config.DBConfig.Password, + config.DBConfig.Host, + config.DBConfig.Port, + config.DBConfig.Database, + ) + templateStorageAdapter, err := templatestore.TemplateStorageAdapterFactory(&templatestore.StorageConfig{ - StorageType: templateStorageType, - // for s3 storage only - S3Config: &s3.Config{ - Endpoint: viper.GetString("s3.endpoint"), - Region: viper.GetString("s3.region"), - Bucket: viper.GetString("s3.bucket"), - Debug: viper.GetBool("s3.debug"), - ForcePathStyle: viper.GetBool("s3.forcePathStyle"), - UploaderConcurrency: viper.GetInt("s3.uploaderConcurrency"), - UploaderPartSize: viper.GetInt64("s3.uploaderPartSize"), - DownloaderConcurrency: viper.GetInt("s3.downloaderConcurrency"), - DownloaderPartSize: viper.GetInt64("s3.downloaderPartSize"), - RetryMaxAttempts: viper.GetInt("s3.retryMaxAttempts"), - UseCustomTransport: viper.GetBool("s3.useCustomTransport"), - }, - // for s3 storage only - AwsCredConfig: &s3.AwsCredConfig{ - AccessKeyID: viper.GetString("aws.accessKeyID"), - SecretAccessKey: viper.GetString("aws.secretAccessKey"), - SessionToken: viper.GetString("aws.sessionToken"), - }, - MysqlDSN: viper.GetString("mysql.dsn"), // for mysql adapter + StorageType: templateStorageType, + S3Config: &config.S3Config, // for s3 storage only + AwsCredConfig: &config.AWSConfig, // for s3 storage only + MysqlDSN: mySqlDsn, // for mysql adapter }) if err != nil { return nil, err } fileStorageAdapter, err := templatestore.TemplateStorageAdapterFactory(&templatestore.StorageConfig{ - StorageType: viper.GetString("file_storage.storage_type"), + StorageType: config.FileStorageConfig.StorageType, }) if err != nil { return nil, err } - return &EspressoService{TemplateStorageAdapter: &templateStorageAdapter, FileStorageAdapter: &fileStorageAdapter}, nil + credentialStore, err := certmanager.NewCredentialStore(config.CertConfig) + if err != nil { + return nil, err + } + + return &EspressoService{ + TemplateStorageAdapter: &templateStorageAdapter, + FileStorageAdapter: &fileStorageAdapter, + CredentialStore: credentialStore, + }, nil } -func Register(mux *http.ServeMux) { - espressoService, err := NewEspressoService() +func Register(mux *http.ServeMux, config config.Config) { + espressoService, err := NewEspressoService(config) if err != nil { log.Fatalf("Failed to initialize PDF service: %v", err) } diff --git a/service/internal/pkg/config/config.go b/service/internal/pkg/config/config.go new file mode 100644 index 0000000..32c6c07 --- /dev/null +++ b/service/internal/pkg/config/config.go @@ -0,0 +1,43 @@ +package config + +import ( + "fmt" + + "github.com/spf13/viper" +) + +func Load() (Config, error) { + viper.AutomaticEnv() + + viper.SetDefault(CONFIG_FILE_NAME, "espressoconfig") + viper.SetDefault(CONFIG_FILE_TYPE, "yaml") + viper.SetDefault(CONFIG_FILE_PATH, "/app/espresso/configs") + + viper.SetConfigName(viper.GetString(CONFIG_FILE_NAME)) // File name without extension + viper.SetConfigType(viper.GetString(CONFIG_FILE_TYPE)) // File type + + // Search paths relative to where the binary runs in container + viper.AddConfigPath(CONFIG_FILE_PATH) // Main config path in container + viper.AddConfigPath("../../configs") // For local development + viper.AddConfigPath("./configs") // Fallback path for local development + + err := viper.ReadInConfig() + if err != nil { + return Config{}, err + } + + var config Config + err = viper.Unmarshal(&config) + if err != nil { + return Config{}, err + } + + // TODO: Why are these fields set in the Dockerfile and not in the config.yaml file? + config.AppConfig.EnableUI = viper.GetBool(ENABLE_UI) + config.AppConfig.RodBrowserBin = viper.GetString(ROD_BROWSER_BIN) + if config.AppConfig.RodBrowserBin == "" { + return Config{}, fmt.Errorf("environment variable %s not set", ROD_BROWSER_BIN) + } + + return config, nil +} diff --git a/service/internal/pkg/config/constant.go b/service/internal/pkg/config/constant.go new file mode 100644 index 0000000..92dc8ca --- /dev/null +++ b/service/internal/pkg/config/constant.go @@ -0,0 +1,10 @@ +package config + +const ( + CONFIG_FILE_NAME = "CONFIG_FILE_NAME" + CONFIG_FILE_TYPE = "CONFIG_FILE_TYPE" + CONFIG_FILE_PATH = "CONFIG_FILE_PATH" + + ENABLE_UI = "ENABLE_UI" + ROD_BROWSER_BIN = "ROD_BROWSER_BIN" +) diff --git a/service/internal/pkg/config/model.go b/service/internal/pkg/config/model.go new file mode 100644 index 0000000..40def79 --- /dev/null +++ b/service/internal/pkg/config/model.go @@ -0,0 +1,46 @@ +package config + +import ( + "github.com/Zomato/espresso/lib/certmanager" + "github.com/Zomato/espresso/lib/s3" +) + +type Config struct { + AppConfig AppConfig `mapstructure:"app"` + TemplateStorageConfig StorageConfig `mapstructure:"template_storage"` + FileStorageConfig StorageConfig `mapstructure:"file_storage"` + BrowserConfig BrowserConfig `mapstructure:"browser"` + WorkerPoolConfig WorkerPoolConfig `mapstructure:"workerpool"` + S3Config s3.Config `mapstructure:"s3"` + AWSConfig s3.AwsCredConfig `mapstructure:"aws"` + CertConfig map[string]certmanager.CertificateConfig `mapstructure:"certificates"` + DBConfig DBConfig `mapstructure:"db"` +} + +type AppConfig struct { + LogLevel string `mapstructure:"log_level"` + ServerPort int `mapstructure:"server_port"` + EnableUI bool `mapstructure:"enable_ui"` + RodBrowserBin string `mapstructure:"rod_browser_bin"` +} + +type StorageConfig struct { + StorageType string `mapstructure:"storage_type"` +} + +type BrowserConfig struct { + TabPool int `mapstructure:"tab_pool"` +} + +type WorkerPoolConfig struct { + WorkerCount int `mapstructure:"worker_count"` + WorkerTimeoutMs int `mapstructure:"worker_timeout_ms"` +} + +type DBConfig struct { + Host string `mapstructure:"host"` + Port int `mapstructure:"port"` + Username string `mapstructure:"username"` + Password string `mapstructure:"password"` + Database string `mapstructure:"database"` +} diff --git a/service/internal/pkg/viperpkg/viperpkg.go b/service/internal/pkg/viperpkg/viperpkg.go deleted file mode 100644 index 84807b1..0000000 --- a/service/internal/pkg/viperpkg/viperpkg.go +++ /dev/null @@ -1,20 +0,0 @@ -package viperpkg - -import ( - "log" - - "github.com/spf13/viper" -) - -func InitConfig() { - viper.SetConfigName("espressoconfig") // File name without extension - viper.SetConfigType("yaml") // File type - // Search paths relative to where the binary runs in container - viper.AddConfigPath("/app/espresso/configs") // Main config path in container - viper.AddConfigPath("../../configs") // For local development - viper.AddConfigPath("./configs") // Fallback path for local development - - if err := viper.ReadInConfig(); err != nil { - log.Fatalf("Error reading config file: %v", err) - } -} diff --git a/service/internal/service/generateDoc/generatePdf.go b/service/internal/service/generateDoc/generatePdf.go index 1d2acd3..52c73c8 100644 --- a/service/internal/service/generateDoc/generatePdf.go +++ b/service/internal/service/generateDoc/generatePdf.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "io" - "sync" "time" "github.com/Zomato/espresso/lib/browser_manager" @@ -13,8 +12,6 @@ import ( "github.com/Zomato/espresso/lib/renderer" "github.com/Zomato/espresso/lib/signer" "github.com/Zomato/espresso/lib/templatestore" - "github.com/Zomato/espresso/lib/workerpool" - "github.com/spf13/viper" svcUtils "github.com/Zomato/espresso/service/utils" "github.com/go-rod/rod/lib/proto" @@ -24,7 +21,13 @@ import ( // If signing is enabled, it will load the signing credentials in parallel and sign the PDF before storing it. // The generated PDF is stored in the file store with the provided output file path. // The function returns an error if anything goes wrong during generation, signing, or storage of the PDF. -func GeneratePDF(ctx context.Context, req *PDFDto, templateStoreAdapter *templatestore.StorageAdapter, fileStoreAdapter *templatestore.StorageAdapter) error { +func GeneratePDF( + ctx context.Context, + req *PDFDto, + templateStoreAdapter *templatestore.StorageAdapter, + fileStoreAdapter *templatestore.StorageAdapter, + credentialStore *certmanager.CredentialStore, +) error { startTime := time.Now() @@ -32,36 +35,18 @@ func GeneratePDF(ctx context.Context, req *PDFDto, templateStoreAdapter *templat content := req.Content viewPortConfig := req.ViewPort pdfParams := req.PdfParams - viewPort := getViewPort(viewPortConfig) - // Start loading credentials in parallel if signing is enabled - var credWg sync.WaitGroup - var credErr error + var credentials *certmanager.SigningCredentials var pdfReader io.Reader - toBeSigned := false - if req.SignParams != nil && req.SignParams.SignPdf { - toBeSigned = true - } + toBeSigned := req.SignParams != nil && req.SignParams.SignPdf if toBeSigned { - certConfig := &certmanager.CertificateConfig{ - CertFilePath: viper.GetString(req.SignParams.CertConfigKey + ".cert_filepath"), - KeyFilePath: viper.GetString(req.SignParams.CertConfigKey + ".key_filepath"), - KeyPassword: viper.GetString(req.SignParams.CertConfigKey + ".key_password"), - } - credWg.Add(1) - err := workerpool.Pool().SubmitTask( - func(args ...interface{}) { - defer credWg.Done() - ctxArg := args[0].(context.Context) - credentials, credErr = certmanager.LoadSigningCredentials(ctxArg, certConfig) - }, - ctx, - ) - - if err != nil { - return fmt.Errorf("failed to submit credential loading task: %v", err) + credKey := req.SignParams.CertConfigKey + var exists bool + credentials, exists = credentialStore.GetCredential(credKey) + if !exists { + return fmt.Errorf("signing credentials not found for key: %s", credKey) } } @@ -97,12 +82,6 @@ func GeneratePDF(ctx context.Context, req *PDFDto, templateStoreAdapter *templat duration = time.Since(startTime) if toBeSigned { - credWg.Wait() - - if credErr != nil { - return fmt.Errorf("failed to load signing credentials: %v", credErr) - } - signedPDF, err := signer.SignPdfStream(ctx, pdf, credentials.Certificate, credentials.PrivateKey) if err != nil { return fmt.Errorf("failed to sign pdf using SignPdfStream: %v", err) @@ -191,7 +170,12 @@ func getViewPort(viewPort *ViewportConfig) *browser_manager.ViewportConfig { return viewSettings } -func SignPDF(ctx context.Context, req *SignPDFDto, fileStoreAdapter *templatestore.StorageAdapter) error { +func SignPDF( + ctx context.Context, + req *SignPDFDto, + fileStoreAdapter *templatestore.StorageAdapter, + credentialStore *certmanager.CredentialStore, +) error { reqId := req.ReqId svcUtils.Logger.Info(ctx, "SignPDF called ", map[string]any{"req id": reqId}) @@ -205,38 +189,18 @@ func SignPDF(ctx context.Context, req *SignPDFDto, fileStoreAdapter *templatesto if err != nil { return fmt.Errorf("failed to get input file: %v", err) } - // Start loading credentials in parallel if signing is enabled - var credWg sync.WaitGroup - var credErr error + var credentials *certmanager.SigningCredentials var pdfReader io.Reader if req.SignParams.SignPdf { - credWg.Add(1) - certConfig := &certmanager.CertificateConfig{ - CertFilePath: viper.GetString(req.SignParams.CertConfigKey + ".cert_filepath"), - KeyFilePath: viper.GetString(req.SignParams.CertConfigKey + ".key_filepath"), - KeyPassword: viper.GetString(req.SignParams.CertConfigKey + ".key_password"), - } - err := workerpool.Pool().SubmitTask( - func(args ...interface{}) { - defer credWg.Done() - ctxArg := args[0].(context.Context) - credentials, credErr = certmanager.LoadSigningCredentials(ctxArg, certConfig) - }, - ctx, - ) - - if err != nil { - return fmt.Errorf("failed to submit credential loading task: %v", err) + credKey := req.SignParams.CertConfigKey + var exists bool + credentials, exists = credentialStore.GetCredential(credKey) + if !exists { + return fmt.Errorf("signing credentials not found for key: %s", credKey) } - } - if req.SignParams.SignPdf { - credWg.Wait() - if credErr != nil { - return fmt.Errorf("failed to load signing credentials: %v", credErr) - } // convert pdfreader to *rod.StreamReader signedPDF, err := signer.SignPdfStream(ctx, freader, credentials.Certificate, credentials.PrivateKey) if err != nil { diff --git a/service/main.go b/service/main.go index 3cebab0..e785d8d 100644 --- a/service/main.go +++ b/service/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "fmt" "log" "net/http" "time" @@ -11,32 +12,34 @@ import ( logger "github.com/Zomato/espresso/lib/logger" "github.com/Zomato/espresso/lib/workerpool" "github.com/Zomato/espresso/service/controller/pdf_generation" - "github.com/Zomato/espresso/service/internal/pkg/viperpkg" + "github.com/Zomato/espresso/service/internal/pkg/config" "github.com/Zomato/espresso/service/utils" - "github.com/spf13/viper" ) func main() { ctx := context.Background() - viperpkg.InitConfig() + config, err := config.Load() + if err != nil { + log.Fatalf("Error loading config: %v", err) + } // Replace ZeroLog with any logging library by implementing ILogger interface. - zeroLog := utils.NewZeroLogger() + zeroLog := utils.NewZeroLogger(config.AppConfig.LogLevel) logger.Initialize(zeroLog) - templateStorageType := viper.GetString("template_storage.storage_type") - zeroLog.Info(ctx, "Template storage type ", map[string]any{"type": templateStorageType}) + log.Printf("Template storage type: %s", config.TemplateStorageConfig.StorageType) + log.Printf("File storage type: %s", config.FileStorageConfig.StorageType) - fileStorageType := viper.GetString("file_storage.storage_type") - zeroLog.Info(ctx, "File storage type ", map[string]any{"type": fileStorageType}) + tabpool := config.BrowserConfig.TabPool + browserPath := config.AppConfig.RodBrowserBin - tabpool := viper.GetInt("browser.tab_pool") - if err := browser_manager.Init(ctx, tabpool); err != nil { + if err := browser_manager.Init(ctx, tabpool, browserPath); err != nil { log.Fatalf("Failed to initialize browser: %v", err) } - workerCount := viper.GetInt("workerpool.worker_count") - workerTimeout := viper.GetInt("workerpool.worker_timeout") + + workerCount := config.WorkerPoolConfig.WorkerCount + workerTimeout := config.WorkerPoolConfig.WorkerTimeoutMs initializeWorkerPool(workerCount, workerTimeout) @@ -44,12 +47,13 @@ func main() { // Create a new ServeMux mux := http.NewServeMux() - pdf_generation.Register(mux) + pdf_generation.Register(mux, config) // Wrap the entire mux with the CORS middleware corsHandler := enableCORS(mux) - log.Println("Starting PDF client server on :8081") - if err := http.ListenAndServe(":8081", corsHandler); err != nil { + port := fmt.Sprintf(":%d", config.AppConfig.ServerPort) + log.Printf("Starting PDF client server on: %s\n", port) + if err := http.ListenAndServe(port, corsHandler); err != nil { log.Fatal(err) } diff --git a/service/model/config.go b/service/model/config.go new file mode 100644 index 0000000..418bea6 --- /dev/null +++ b/service/model/config.go @@ -0,0 +1,51 @@ +package model + +import ( + "github.com/Zomato/espresso/lib/s3" +) + +type Config struct { + AppConfig AppConfig `mapstructure:"app"` + TemplateStorageConfig StorageConfig `mapstructure:"template_storage"` + FileStorageConfig StorageConfig `mapstructure:"file_storage"` + BrowserConfig BrowserConfig `mapstructure:"browser"` + WorkerPoolConfig WorkerPoolConfig `mapstructure:"workerpool"` + S3Config s3.Config `mapstructure:"s3"` + AWSConfig s3.AwsCredConfig `mapstructure:"aws"` + CertConfig map[string]CertConfig `mapstructure:"certificates"` + DBConfig DBConfig `mapstructure:"db"` +} + +type AppConfig struct { + LogLevel string `mapstructure:"log_level"` + ServerPort int `mapstructure:"server_port"` + EnableUI bool `mapstructure:"enable_ui"` + RodBrowserBin string `mapstructure:"rod_browser_bin"` +} + +type StorageConfig struct { + StorageType string `mapstructure:"storage_type"` +} + +type BrowserConfig struct { + TabPool int `mapstructure:"tab_pool"` +} + +type WorkerPoolConfig struct { + WorkerCount int `mapstructure:"worker_count"` + WorkerTimeoutMs int `mapstructure:"worker_timeout_ms"` +} + +type CertConfig struct { + CertPath string `mapstructure:"cert_path"` + KeyPath string `mapstructure:"key_path"` + KeyPassword string `mapstructure:"key_password"` +} + +type DBConfig struct { + Host string `mapstructure:"host"` + Port int `mapstructure:"port"` + Username string `mapstructure:"username"` + Password string `mapstructure:"password"` + Database string `mapstructure:"database"` +} diff --git a/service/utils/zerolog.go b/service/utils/zerolog.go index ef5ed9e..fb217c8 100644 --- a/service/utils/zerolog.go +++ b/service/utils/zerolog.go @@ -18,13 +18,22 @@ var ( Logger ZeroLog ) -func NewZeroLogger() ZeroLog { - log.Logger = log.Output(zerolog.ConsoleWriter{ - Out: os.Stderr, - TimeFormat: time.RFC3339, - }) +func NewZeroLogger(level string) ZeroLog { + log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}) + // zerolog.SetGlobalLevel(zerolog.DebugLevel) - zerolog.SetGlobalLevel(zerolog.DebugLevel) + switch level { + case "debug": + zerolog.SetGlobalLevel(zerolog.DebugLevel) + case "info": + zerolog.SetGlobalLevel(zerolog.InfoLevel) + case "warn": + zerolog.SetGlobalLevel(zerolog.WarnLevel) + case "error": + zerolog.SetGlobalLevel(zerolog.ErrorLevel) + default: + zerolog.SetGlobalLevel(zerolog.InfoLevel) + } zeroLog := ZeroLog{ logger: log.Logger,