Добавлен основные классы для сервиса авторизаци

This commit is contained in:
Ганеев Артем
2025-10-28 20:49:54 +03:00
parent def3552a67
commit 736b8031f8
26 changed files with 904 additions and 40 deletions

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

@@ -0,0 +1,42 @@
package config
import (
"os"
"gopkg.in/yaml.v3"
)
type Config struct {
Token TokenConfig `yaml:"token" json:"token"`
Server ServerConfig `yaml:"server" json:"server"`
DB DatabaseConfig `yaml:"db" json:"db"`
}
type ServerConfig struct {
Port string `yaml:"port" json:"port"`
}
type DatabaseConfig struct {
Username string `yaml:"username" json:"username"`
Host string `yaml:"host" json:"host"`
Port string `yaml:"port" json:"port"`
Sslmode string `yaml:"sslmode" json:"sslmode"`
DBname string `yaml:"dbname" json:"dbname"`
}
func LoadConfig(absolutePath string) (*Config, error) {
config := &Config{}
file, err := os.Open(absolutePath)
if err != nil {
return nil, err
}
defer file.Close()
decoder := yaml.NewDecoder(file)
if err := decoder.Decode(config); err != nil {
return nil, err
}
return config, nil
}

22
internal/config/token.go Normal file
View File

@@ -0,0 +1,22 @@
package config
import "time"
type TokenConfig struct {
AccessToken TokenSettings `yaml:"accessToken" json:"accessToken"`
RefreshToken TokenSettings `yaml:"refreshToken" json:"refreshToken"`
}
type TokenSettings struct {
TTLInMinutes int `yaml:"TTL-in-min" json:"TTL-in-min"`
SecretWord string `yaml:"secretWord" json:"secretWord"`
}
// Методы для удобства
func (t *TokenSettings) GetTTL() time.Duration {
return time.Duration(t.TTLInMinutes) * time.Minute
}
func (t *TokenSettings) GetSecretBytes() []byte {
return []byte(t.SecretWord)
}