utils

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal added in v0.0.22

func Equal(value1, value2 *structpb.Value) bool

Equal checks if two structpb.Value are equal

func FromProtoRecord added in v0.0.22

func FromProtoRecord(protoRecord *dbdata.Record) (map[string]interface{}, error)

fromProtoRecord converts a protobuf record to a map record. It iterates over the fields in the protobuf record, converts each protobuf value to a Go value using fromProtoValue function, and adds the converted value to the map record. It returns the converted map record and an error if the conversion of any value fails.

func FromProtoValue added in v0.0.22

func FromProtoValue(protoValue *structpb.Value) (any, error)

fromProtoValue converts a protobuf value to a Go value. It supports conversion for protobuf string value and protobuf number value. For protobuf string value, it attempts to parse the string as an int and returns the int value if the parsing is successful. If the parsing fails, it returns the string value. For protobuf number value, it returns the number value. For other types, it directly returns the value as interface{}. It returns the converted Go value and an error if the conversion fails.

func ToProtoRecord added in v0.0.22

func ToProtoRecord(record map[string]interface{}) (*dbdata.Record, error)

ToProtoRecord converts a map record to a protobuf record. It iterates over the fields in the map record, converts each Go value to a protobuf value using toProtoValue function, and adds the converted value to the protobuf record. It returns the converted protobuf record and an error if the conversion of any value fails.

func ToProtoValue added in v0.0.22

func ToProtoValue(value interface{}) (*structpb.Value, error)

toProtoValue converts a given value to a protobuf value. It supports conversion for int, int32, int64, float32, float64 and other types that can be directly converted to a protobuf value. For int, int32 and int64, it converts the value to a string and then to a protobuf string value. For float32 and float64, it converts the value to a protobuf number value. For other types, it directly converts the value to a protobuf value. It returns the converted protobuf value and an error if the conversion fails.

Types

type Utils

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

Utils is a utility structure that holds the AES key.

func NewUtils

func NewUtils() (*Utils, error)

NewUtils creates a new Utils instance with the AES key from the environment variable. The AES key must be exactly 32 bytes (256 bits) long.

func (*Utils) Decrypt

func (u *Utils) Decrypt(data string) ([]byte, error)

Decrypt decrypts the given base64 encoded data using AES encryption in CTR mode. The IV is extracted from the ciphertext and used to initialize the cipher.

func (*Utils) Encrypt

func (u *Utils) Encrypt(data []byte) (string, error)

Encrypt encrypts the given data using AES encryption in CTR mode. A random Initialization Vector (IV) is generated for each encryption operation. The IV is prepended to the ciphertext and base64 encoded.

Jump to

Keyboard shortcuts

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