utils

package
v0.0.0-...-96457a2 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2025 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AES256KeySize = 32
)

Variables

This section is empty.

Functions

func AesDecrypt

func AesDecrypt(key, ciphertext []byte) ([]byte, error)

AesDecrypt decrypts data using AES-GCM with the provided key.

func AesEncrypt

func AesEncrypt(key, data []byte) ([]byte, error)

AesEncrypt encrypts data using AES-GCM with the provided key.

func AssertEquals

func AssertEquals(firstValue, secondValue any)

func AssertNotNil

func AssertNotNil(value any)

func AssertTrue

func AssertTrue(condition bool, message string)

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

CheckPasswords - compare hash password with user password

func DeriveECDHSharedSecret

func DeriveECDHSharedSecret(privKeyBytes []byte, peerPublicKeyBytes []byte) ([]byte, error)

func GenerateAES256Key

func GenerateAES256Key() ([]byte, error)

GenerateAES256Key returns a 32-byte AES key.

func GenerateECDHKeyPair

func GenerateECDHKeyPair() ([]byte, []byte, error)

Using a P256 curve to generate the public and private keys

func GetEnvBool

func GetEnvBool(key string, fallback bool) bool

func GetEnvInt

func GetEnvInt(key string, fallback int) int

func GetEnvString

func GetEnvString(key string, fallback string) string

func HashPassword

func HashPassword(password string) (string, error)

HashPassword - hashes the password of the users

func LoadAssembly

func LoadAssembly(filePath string) ([]byte, error)

func MapToStruct

func MapToStruct(input interface{}, output interface{}) error

MapToStruct converts a map to a struct

func NormalizeToSlice

func NormalizeToSlice(input any) []string

func RandomString

func RandomString(length int) string

func Unzip

func Unzip(src string, dest string) error

Unzip decompresses a zip archive to the specified destination.

func WithResultTimeout

func WithResultTimeout[T any](
	ctx context.Context,
	db *sql.DB,
	query string,
	timeout int,
	fn func(context.Context, *sql.Stmt) (T, error),
) (T, error)

For simple db operations that make only one query

func WithTimeout

func WithTimeout(
	ctx context.Context,
	db *sql.DB,
	query string,
	timeout int,
	fn func(context.Context, *sql.Stmt) error,
) error

For simple db operations that make only one query

func WithTransactionResultTimeout

func WithTransactionResultTimeout[T any](
	ctx context.Context,
	db *sql.DB,
	timeout int,
	txOpts sql.TxOptions,
	fn func(context.Context, *sql.Tx) (T, error),
) (T, error)

func WithTransactionTimeout

func WithTransactionTimeout(
	ctx context.Context,
	db *sql.DB,
	timeout int,
	txOpts sql.TxOptions,
	fn func(context.Context, *sql.Tx) error,
) error

func Zip

func Zip(src string, dest string) error

Zip compresses the specified source directory to a zip archive.

Types

type ModuleConfig

type ModuleConfig struct {
	Module interface{} `json:"module"`
}

func LoadModuleConfig

func LoadModuleConfig(path string) (*ModuleConfig, error)

type Validate

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

Validate struct holds a validator instance

func NewValidatorService

func NewValidatorService() *Validate

NewValidatorService creates and returns a new Validate instance

func (*Validate) ValidateStruct

func (v *Validate) ValidateStruct(s interface{}) error

ValidateStruct validates a struct and returns an error if validation fails

type XORUtil

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

func NewXorUtil

func NewXorUtil() (*XORUtil, error)

func (*XORUtil) Decrypt

func (x *XORUtil) Decrypt(input string) (string, error)

func (*XORUtil) Encrypt

func (x *XORUtil) Encrypt(input string) (string, error)

func (*XORUtil) GenerateRandomKey

func (x *XORUtil) GenerateRandomKey() ([]byte, error)

Jump to

Keyboard shortcuts

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