add authentication endpoints and Redis integration

This commit is contained in:
2025-08-06 02:58:15 +03:00
parent deab475eab
commit 416fefdb6b
14 changed files with 340 additions and 530 deletions

52
internal/config/config.go Normal file
View File

@ -0,0 +1,52 @@
package config
import (
"github.com/joho/godotenv"
"github.com/spf13/viper"
"log"
)
type Config struct {
App struct {
Port int
}
Redis struct {
Host string
Port int
DB int
Password string
}
Hydra struct {
Host string
Password string
}
}
var Cfg *Config
func Init() {
err := godotenv.Load()
if err != nil {
log.Println("Error loading .env file")
}
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
err = viper.ReadInConfig()
if err != nil {
log.Fatalf("Error reading config file, %s", err)
}
viper.AutomaticEnv()
var config Config
_ = viper.BindEnv("redis.password", "REDIS_PASSWORD")
_ = viper.BindEnv("hydra.password", "HYDRA_PASSWORD")
err = viper.Unmarshal(&config)
if err != nil {
log.Fatalf("Unable to decode config into struct, %v", err)
}
Cfg = &config
}