added comments

This commit is contained in:
u80864958
2025-05-02 10:39:35 +02:00
parent fb7d5a623a
commit 14b57b57e8
16 changed files with 73 additions and 29 deletions

View File

@ -11,6 +11,7 @@ import (
"gorm.io/gorm/clause"
)
// Config defines a struct for configuration settings, often loaded from environment variables.
type Config struct {
Secret string `env:"SECRET"`
ValidDuration time.Duration `env:"VALID_DURATION"`
@ -19,11 +20,13 @@ type Config struct {
DefaultRole model.Role `env:"DEFAULT_ROLE"`
}
// Service Represents a service with configuration and database connection.
type Service struct {
cfg *Config
db *gorm.DB
}
// New creates a new Service instance, initializing a default admin user and saving it to the database.
func New(cfg *Config, db *gorm.DB) *Service {
user := model.NewUser()
var err error
@ -42,16 +45,20 @@ func New(cfg *Config, db *gorm.DB) *Service {
}
}
// Claims struct represents JWT claims, including role and user ID, extending the standard jwt.RegisteredClaims.
type Claims struct {
Role model.Role `json:"rl"`
UserID uint `json:"uid"`
jwt.RegisteredClaims
}
// Login struct represents user login credentials with a name and password.
type Login struct {
Name string `json:"name"`
Password string `json:"Password"`
}
// LoginResponse Represents the response from a login endpoint, containing a JWT token.
type LoginResponse struct {
Token string `json:"token"`
}