Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Transmute ¶
Transmute is a helper function for applying a series of sigils to data.
Example ¶
package main
import (
"fmt"
"log"
"github.com/Snider/Enchantrix/pkg/enchantrix"
)
func main() {
data := []byte("Hello, World!")
sigils := []enchantrix.Sigil{
&enchantrix.ReverseSigil{},
&enchantrix.HexSigil{},
}
transformed, err := enchantrix.Transmute(data, sigils)
if err != nil {
log.Fatalf("Transmute failed: %v", err)
}
fmt.Printf("Transformed data: %s\n", transformed)
}
Output: Transformed data: 21646c726f57202c6f6c6c6548
Types ¶
type Base64Sigil ¶
type Base64Sigil struct{}
Base64Sigil is a Sigil that encodes/decodes data to/from base64. The In method encodes the data, and the Out method decodes it.
type Enchantrix ¶
Enchantrix defines the interface for acceptance testing.
type GzipSigil ¶
type GzipSigil struct {
// contains filtered or unexported fields
}
GzipSigil is a Sigil that compresses/decompresses data using gzip. The In method compresses the data, and the Out method decompresses it.
type HashSigil ¶
HashSigil is a Sigil that hashes the data using a specified algorithm. The In method hashes the data, and the Out method is a no-op.
func NewHashSigil ¶
NewHashSigil creates a new HashSigil.
type HexSigil ¶
type HexSigil struct{}
HexSigil is a Sigil that encodes/decodes data to/from hexadecimal. The In method encodes the data, and the Out method decodes it.
type JSONSigil ¶
type JSONSigil struct{ Indent bool }
JSONSigil is a Sigil that compacts or indents JSON data. The Out method is a no-op.
type ReverseSigil ¶
type ReverseSigil struct{}
ReverseSigil is a Sigil that reverses the bytes of the payload. It is a symmetrical Sigil, meaning that the In and Out methods perform the same operation.
type Sigil ¶
type Sigil interface {
// In transforms the data.
In(data []byte) ([]byte, error)
// Out reverses the transformation.
Out(data []byte) ([]byte, error)
}
Sigil defines the interface for a data transformer. A Sigil is a reversible or irreversible transformation of a byte slice.
func NewSigil ¶
NewSigil is a factory function that returns a Sigil based on a string name. It is the primary way to create Sigil instances.
Example ¶
package main
import (
"fmt"
"log"
"github.com/Snider/Enchantrix/pkg/enchantrix"
)
func main() {
sigil, err := enchantrix.NewSigil("base64")
if err != nil {
log.Fatalf("Failed to create sigil: %v", err)
}
data := []byte("Hello, World!")
encoded, err := sigil.In(data)
if err != nil {
log.Fatalf("Sigil In failed: %v", err)
}
fmt.Printf("Encoded data: %s\n", encoded)
decoded, err := sigil.Out(encoded)
if err != nil {
log.Fatalf("Sigil Out failed: %v", err)
}
fmt.Printf("Decoded data: %s\n", decoded)
}
Output: Encoded data: SGVsbG8sIFdvcmxkIQ== Decoded data: Hello, World!