jwt

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Claims

type Claims struct {
	UserID   uint   `json:"user_id"`
	Username string `json:"username"`
	Role     string `json:"role"`
	jwt.RegisteredClaims
}

Claims represents the JWT claims

type Config

type Config struct {
	SecretKey string        `yaml:"secret_key"`
	Duration  time.Duration `yaml:"duration"`
}

Config represents the JWT configuration

type Service

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

Service represents the JWT service

func NewService

func NewService(config Config) *Service

NewService creates a new JWT service

func (*Service) GenerateToken

func (s *Service) GenerateToken(userID uint, username string, role string) (string, error)

GenerateToken generates a new JWT token

func (*Service) ValidateToken

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

ValidateToken validates a JWT token

Jump to

Keyboard shortcuts

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