Начало реализации сервиса.

This commit is contained in:
Grbisba
2026-10-30 12:25:56 +03:00
parent 65003b6119
commit 20f2f00a60
52 changed files with 4351 additions and 1 deletions
+48
View File
@@ -0,0 +1,48 @@
package config
import (
"errors"
"time"
"github.com/spf13/viper"
)
type JWT struct {
AccessTokenLifetime time.Duration
RefreshTokenLifetime time.Duration
PublicKeyPath string
PrivateKeyPath string
}
func (c *JWT) Validate() error {
switch {
case c.AccessTokenLifetime == 0:
return wrapValidationError("jwt", errors.New("access_token_lifetime cannot be empty"))
case c.RefreshTokenLifetime == 0:
return wrapValidationError("jwt", errors.New("refresh_token_lifetime cannot be empty"))
case c.PrivateKeyPath == "":
return wrapValidationError("jwt", errors.New("private_key_path cannot be empty"))
case c.PublicKeyPath == "":
return wrapValidationError("jwt", errors.New("public_key_path cannot be empty"))
default:
return nil
}
}
func (c *JWT) loadConfig(v *viper.Viper) error {
v.SetEnvPrefix("JWT")
c.AccessTokenLifetime = v.GetDuration("ACCESS_TOKEN_LIFETIME")
c.RefreshTokenLifetime = v.GetDuration("REFRESH_TOKEN_LIFETIME")
c.PublicKeyPath = v.GetString("PUBLIC_KEY_PATH")
c.PrivateKeyPath = v.GetString("PRIVATE_KEY_PATH")
return nil
}
func (c *JWT) copy() *JWT {
return &JWT{
AccessTokenLifetime: c.AccessTokenLifetime,
RefreshTokenLifetime: c.RefreshTokenLifetime,
PublicKeyPath: c.PublicKeyPath,
PrivateKeyPath: c.PrivateKeyPath,
}
}