utils

package
v0.0.0-...-0e64a8c Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(x int) int

Abs calculates the absolute value of an integer.

func Base64Decode

func Base64Decode(data string) ([]byte, error)

func Base64Encode

func Base64Encode(data []byte) string

func BlobToPEMString

func BlobToPEMString(blob []byte) string

func BytesToStr

func BytesToStr(byteArray []byte, delimiter string) string

func CalcHashPW

func CalcHashPW(password_A, password_B []byte) (string, string, error)

CalcHashPW returns a hash string value.

func CalcXorByteArrays

func CalcXorByteArrays(a, b []byte) ([]byte, error)

func CompareHashAndPassword

func CompareHashAndPassword(hashedPassword, password string) error

func GenerateHashFromPassword

func GenerateHashFromPassword(data []byte) ([]byte, error)

func GenerateRandom

func GenerateRandom(length int) ([]byte, error)

GenerateRandom returns random data from the rand package.

func GetCurrentTimestamp

func GetCurrentTimestamp() string

func LoadCertFromFile

func LoadCertFromFile(configDir, filename string) (*x509.Certificate, error)

LoadCertFromFile reads a yaml configuration file from the specified path and parse it into the certificate object.

Parameters:

  • configDir: The directory path of the Yaml configuration file.
  • filename: The filename.

Returns:

  • A pointer to the X509 certificate struct where the configuration will be parsed.
  • An error if there was an issue reading or unmarshaling the configuration file.

func LoadConfig

func LoadConfig(configDir, configFile string, v interface{}) error

LoadConfig reads a Yaml configuration file from the specified path with filename and unmarshals it into the provided struct (v).

Parameters:

  • configDir: The directory path of the Yaml configuration file.
  • configFile: The file path of the Yaml configuration file.
  • v: A pointer to the struct where the configuration will be unmarshaled.

Returns:

  • An error if there was an issue reading or unmarshaling the configuration file.

func LoadJSONConfig

func LoadJSONConfig(configPath string, v interface{}) error

LoadJSONConfig reads a JSON configuration file from the specified path and unmarshals it into the provided struct (v).

Parameters:

  • configPath: The file path of the JSON configuration file.
  • v: A pointer to the struct where the configuration will be unmarshaled.

Returns:

  • An error if there was an issue reading or unmarshaling the configuration file.

func NumToStr

func NumToStr(byteArray []byte, isBigEndian bool) string

func PrintVersion

func PrintVersion(exit bool) string

func ReadFile

func ReadFile(filename string) ([]byte, error)

ReadFile reads data from file. If succeed, ReadFile returns the data of the file as byte array; otherwise ReadFile returns an error.

func ReadFileFromDir

func ReadFileFromDir(configDir, filename string) ([]byte, error)

func WriteFile

func WriteFile(name string, data []byte, perm os.FileMode) error

WriteFile writes data to the named file, creating it if necessary. If the file does not exist, WriteFile creates it with permissions perm (before umask); otherwise WriteFile appends it before writing, without changing permissions.

func WriteFileToDir

func WriteFileToDir(configDir, filename string, data []byte) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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