45 lines
966 B
Go
45 lines
966 B
Go
package config
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/TelegramExchange/tgex-parser/pkg/logger"
|
|
"github.com/TelegramExchange/tgex-parser/pkg/postgres"
|
|
"github.com/joho/godotenv"
|
|
"github.com/kelseyhightower/envconfig"
|
|
|
|
"github.com/TelegramExchange/tgex-parser/internal/controller/worker"
|
|
"github.com/TelegramExchange/tgex-parser/pkg/telegram"
|
|
)
|
|
|
|
type HTTP struct {
|
|
Addr string `envconfig:"HTTP__ADDR" default:":8080"`
|
|
}
|
|
|
|
type Config struct {
|
|
Logger logger.Config
|
|
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
|
|
}
|