Add Wildberries product fetching and rate limiting functionality
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
package config
|
||||
|
||||
import "github.com/joho/godotenv"
|
||||
|
||||
type Config struct {
|
||||
DB string
|
||||
HTTP string
|
||||
GRPC string
|
||||
Kafka string
|
||||
Redis *RedisConfig
|
||||
Database *DatabaseConfig
|
||||
}
|
||||
|
||||
func Load() Config {
|
||||
return Config{
|
||||
DB: "dbname=test password=GjitkYf[eq user=postgres sslmode=disable",
|
||||
HTTP: ":8080",
|
||||
GRPC: ":50051",
|
||||
Kafka: "localhost:9092",
|
||||
func LoadConfig() (*Config, error) {
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
redisConfig := LoadRedisConfig()
|
||||
databaseConfig := LoadDatabaseConfig()
|
||||
return &Config{Redis: redisConfig, Database: databaseConfig}, nil
|
||||
}
|
||||
|
||||
23
internal/config/database.go
Normal file
23
internal/config/database.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package config
|
||||
|
||||
import "os"
|
||||
|
||||
type DatabaseConfig struct {
|
||||
Host string
|
||||
Port string
|
||||
Login string
|
||||
Password string
|
||||
Database string
|
||||
URL string
|
||||
}
|
||||
|
||||
func LoadDatabaseConfig() *DatabaseConfig {
|
||||
return &DatabaseConfig{
|
||||
Host: os.Getenv("POSTGRES_HOST"),
|
||||
Port: os.Getenv("POSTGRES_PORT"),
|
||||
Login: os.Getenv("POSTGRES_LOGIN"),
|
||||
Password: os.Getenv("POSTGRES_PASSWORD"),
|
||||
Database: os.Getenv("POSTGRES_DATABASE"),
|
||||
URL: os.Getenv("POSTGRES_URL"),
|
||||
}
|
||||
}
|
||||
23
internal/config/redis.go
Normal file
23
internal/config/redis.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package config
|
||||
|
||||
import "os"
|
||||
|
||||
type RedisConfig struct {
|
||||
Host string
|
||||
Port string
|
||||
Password string
|
||||
Addr string
|
||||
}
|
||||
|
||||
func LoadRedisConfig() *RedisConfig {
|
||||
host := os.Getenv("REDIS_HOST")
|
||||
port := os.Getenv("REDIS_PORT")
|
||||
password := os.Getenv("REDIS_PASSWORD")
|
||||
addr := os.Getenv("REDIS_ADDR")
|
||||
return &RedisConfig{
|
||||
Host: host,
|
||||
Port: port,
|
||||
Password: password,
|
||||
Addr: addr,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user