helper

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2025 License: MIT Imports: 31 Imported by: 0

Documentation

Overview

Package helper contains helper functions

Package helper provides helper functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CryptoRandomInt added in v0.1.0

func CryptoRandomInt(limit int64) (int64, error)

CryptoRandomInt returns a crypto random integer between 0 and limit, inclusive Copried from https://github.com/go-gitea/gitea/blob/main/modules/util/util.go#L59

func CryptoRandomString added in v0.1.0

func CryptoRandomString(length int64) (string, error)

CryptoRandomString generates a crypto random alphanumerical string, each byte is generated by [0,61] range Copied from https://github.com/go-gitea/gitea/blob/main/modules/util/util.go#L70

func GenerateSecureToken added in v0.1.0

func GenerateSecureToken(length int) string

GenerateSecureToken generates a cryptographically secure random token

func GenerateTOTPQRCode added in v0.2.0

func GenerateTOTPQRCode(username, secret string) (string, error)

GenerateTOTPQRCode generates a QR code for TOTP setup with the UnderNET logo

func GetClaimsFromRefreshToken added in v0.0.4

func GetClaimsFromRefreshToken(refreshToken string) (jwt.MapClaims, error)

GetClaimsFromRefreshToken gets the claims from the refresh token

func GetEchoJWTConfig added in v0.0.4

func GetEchoJWTConfig() echojwt.Config

GetEchoJWTConfig returns the echo JWT config

func GetJWTPublicKey added in v0.0.4

func GetJWTPublicKey() interface{}

GetJWTPublicKey gets the JWT public key

func GetJWTRefreshSigningKey added in v0.0.4

func GetJWTRefreshSigningKey() interface{}

GetJWTRefreshSigningKey gets the JWT refresh signing key

func GetJWTSigningKey added in v0.0.4

func GetJWTSigningKey() interface{}

GetJWTSigningKey gets the JWT signing key

func GetRequestID added in v0.3.0

func GetRequestID(c echo.Context) string

GetRequestID extracts the request ID from the Echo context. Returns "unknown" if no request ID is found.

func GetRequestLogger added in v0.3.0

func GetRequestLogger(c echo.Context) *slog.Logger

GetRequestLogger returns a slog.Logger that automatically includes the request ID from the Echo context in all log entries. If no request ID is found, it uses "unknown".

func InArray added in v0.0.6

func InArray(needle string, haystack []string) bool

func SafeAtoi32 added in v0.0.8

func SafeAtoi32(s string) (int32, error)

SafeAtoi32 converts a string to int32 with bounds checking

func StrPtr2Str

func StrPtr2Str(str *string) string

Types

type JwtClaims

type JwtClaims struct {
	UserID      int32  `json:"user_id"`
	Username    string `json:"username"`
	RefreshUUID string `json:"refresh_uuid"` // If 2FA is enabled, this will be false until the user has authenticated with TOTPa
	Scope       string `json:"scope,omitempty"`
	Adm         int32  `json:"adm,omitempty"`
	jwt.RegisteredClaims
}

JwtClaims defines the default claims for JWT

func GetClaimsFromContext

func GetClaimsFromContext(c echo.Context) *JwtClaims

GetClaimsFromContext gets the JWT claims from the echo context

func (*JwtClaims) HasScope added in v0.0.6

func (c *JwtClaims) HasScope(scope string) bool

type TokenDetails

type TokenDetails struct {
	AccessToken  string
	RefreshToken string
	RefreshUUID  string
	AtExpires    *jwt.NumericDate
	RtExpires    *jwt.NumericDate
}

TokenDetails defines the details of the tokens

func GenerateToken

func GenerateToken(claims *JwtClaims, t time.Time) (*TokenDetails, error)

GenerateToken generates a JWT token

type Validator added in v0.0.2

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

Validator is a wrapper around the validator package

func NewValidator added in v0.0.2

func NewValidator() *Validator

NewValidator returns a new Validator

func (*Validator) Validate added in v0.0.2

func (v *Validator) Validate(i interface{}) error

Validate validates a struct based on the tags

Jump to

Keyboard shortcuts

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