49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package config
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/TelegramExchange/pkg/postgres"
|
|
"github.com/TelegramExchange/pkg/telegram"
|
|
"github.com/joho/godotenv"
|
|
"github.com/kelseyhightower/envconfig"
|
|
|
|
"github.com/TelegramExchange/tgex-backend/tg_parser/internal/controller/worker"
|
|
)
|
|
|
|
type HTTP struct {
|
|
Addr string `envconfig:"HTTP__ADDR" default:":8080"`
|
|
}
|
|
|
|
type LoggerConfig struct {
|
|
Level string `default:"info" envconfig:"PARSER__LOGGER__LEVEL"`
|
|
PrettyConsole bool `default:"true" envconfig:"PARSER__LOGGER__PRETTY_CONSOLE"`
|
|
}
|
|
|
|
type Config struct {
|
|
Logger LoggerConfig
|
|
Postgres postgres.Config
|
|
Telegram telegram.Config
|
|
ChannelWorker worker.ChannelConfig
|
|
ViewsWorker worker.ViewsConfig
|
|
HTTP HTTP
|
|
}
|
|
|
|
func New() (Config, error) {
|
|
var config Config
|
|
|
|
err := godotenv.Load(".env")
|
|
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
|
return config, fmt.Errorf("godotenv.Load: %w", err)
|
|
}
|
|
|
|
err = envconfig.Process("", &config)
|
|
if err != nil {
|
|
return config, fmt.Errorf("envconfig.Process: %w", err)
|
|
}
|
|
|
|
return config, nil
|
|
}
|