utils

package
v0.0.0-...-2dec208 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sha256Hex

func Sha256Hex(datas ...[]byte) (string, error)

Sha256Hex returns the Sha256 checksum of the data with HEX format

Types

type Alg

type Alg string

Alg represent jwt algorithm

const (
	// HS256 const
	HS256 Alg = "HS256"

	// RS256 const
	RS256 Alg = "RS256"
)

type Claim

type Claim struct {
	Issuer    string
	Audience  string
	Subject   string
	ExpiredAt int64
	IssuedAt  int64
	User      struct {
		ID       string
		FullName string
		Email    string
	}
	Alg Alg
}

Claim model

type JWT

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

JWT implementation from JwtService

func NewJWT

func NewJWT(hmacKey string) *JWT

NewJWT constructor

func (*JWT) Generate

func (r *JWT) Generate(payload *Claim, expired time.Duration) (string, error)

Generate token

func (*JWT) Validate

func (r *JWT) Validate(alg Alg, tokenString string) (*Claim, error)

Validate token

type JwtService

type JwtService interface {
	Generate(payload *Claim, expired time.Duration) (string, error)
	Validate(alg Alg, tokenString string) (*Claim, error)
}

JwtService represent jwt service

Jump to

Keyboard shortcuts

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