transforms

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2025 License: MPL-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package transforms provides utility functions for data transformation operations like JSON normalization, base64 encoding/decoding, and gzip compression/decompression.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyContent = errors.New("empty content")
	ErrEmptyJSON    = errors.New("empty JSON content")
)

Functions

func Base64Decode

func Base64Decode(content string) (string, error)

Base64Decode decodes a base64 encoded string.

func Base64Encode

func Base64Encode[T string | []byte](content T) (string, error)

Base64Encode encodes a string or byte slice to base64.

func Base64GzipDecode

func Base64GzipDecode(content string) (string, error)

Base64GzipDecode decodes and decompresses base64 gzipped content.

func Base64GzipEncode

func Base64GzipEncode(content string) (string, error)

Base64GzipEncode compresses and base64 encodes content.

func IsJSON

func IsJSON(content string) bool

IsJSON checks if a string contains valid JSON.

func JSONBase64GzipDecode

func JSONBase64GzipDecode(content string) (any, error)

JSONBase64GzipDecode decodes, decompresses and unmarshals base64 gzipped JSON content.

func JSONBase64GzipEncode

func JSONBase64GzipEncode(content string) (string, error)

JSONBase64GzipEncode normalizes, compresses, and base64 encodes JSON content.

func JSONNormalize

func JSONNormalize(content string) (string, error)

JSONNormalize normalizes JSON content to a compact format.

func JSONNormalizePretty

func JSONNormalizePretty(content string) (string, error)

JSONNormalizePretty normalizes JSON content to a human-readable format with indentation.

func PayloadToGzip

func PayloadToGzip(content string) (string, diag.Diagnostics)

PayloadToGzip transforms a base64 encoded content string to a gzip compressed base64 string. If the content is valid JSON, it uses JSON-specific encoding.

func SourceFileToPayload

func SourceFileToPayload(srcPath string, tokens map[string]string) (string, string, diag.Diagnostics)

SourceFileToPayload transforms a source file into a base64 encoded payload and calculates its SHA256 hash. It optionally processes the file as a template with the provided tokens.

Types

This section is empty.

Jump to

Keyboard shortcuts

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