jwt

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package jwt provides JWT token generation and validation for the application.

The module covers:

  • token generation with HS256 algorithm,
  • token validation and claims extraction,
  • 24-hour token expiry,
  • integration with the users domain.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidConfig = errors.New("invalid config")
	ErrInvalidToken  = errors.New("invalid token")
	ErrExpiredToken  = errors.New("token has expired")
)

Functions

func Module

func Module() fx.Option

Module creates and returns an FX module for the jwt package.

The module provides:

  • JWTService for token generation and validation

Types

type Claims

type Claims struct {
	jwt.RegisteredClaims

	UserID int64        `json:"user_id"`
	Role   users.Role   `json:"role"`
	Status users.Status `json:"status"`
}

Claims represents the JWT token claims.

type Config

type Config struct {
	Secret    string
	AccessTTL time.Duration
	Issuer    string
}

func (Config) Validate

func (c Config) Validate() error

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service handles JWT token operations.

func NewService

func NewService(config Config) *Service

NewService creates and initializes a new JWT service.

func (*Service) GenerateToken

func (s *Service) GenerateToken(user *users.User) (string, error)

GenerateToken creates a new JWT token for the user.

func (*Service) ValidateToken

func (s *Service) ValidateToken(tokenString string) (*Claims, error)

ValidateToken validates and parses a JWT token. Returns the claims if valid, or an error if invalid/expired.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL