encoding

package
v1.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EncodingRegistry

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

func NewRegistry

func NewRegistry() *EncodingRegistry

NewRegistry creates a new instance of conversion registry.

func (*EncodingRegistry) Base32Decode

func (er *EncodingRegistry) Base32Decode(str string) (string, error)

Base32Decode decodes a Base32 encoded string back to its original form. Returns an error message if the input is not valid Base32.

Parameters:

str string - the Base32 encoded string to decode.

Returns:

string - the decoded string, or an error message if the decoding fails.
error - an error message if the decoding fails.

Example:

{{ "JBSWY3DPEBLW64TMMQQQ====" | base32Decode }} // Output: "Hello World"

func (*EncodingRegistry) Base32Encode

func (er *EncodingRegistry) Base32Encode(str string) string

Base32Encode encodes a string into its Base32 representation.

Parameters:

str string - the string to encode.

Returns:

string - the Base32 encoded string.

Example:

{{ "Hello World" | base32Encode }} // Output: "JBSWY3DPEBLW64TMMQQQ===="

func (*EncodingRegistry) Base64Decode

func (er *EncodingRegistry) Base64Decode(str string) (string, error)

Base64Decode decodes a Base64 encoded string back to its original form. Returns an error message if the input is not valid Base64.

Parameters:

str string - the Base64 encoded string to decode.

Returns:

string - the decoded string, or an error message if the decoding fails.
error - an error message if the decoding fails.

Example:

{{ "SGVsbG8gV29ybGQ=" | base64Decode }} // Output: "Hello World"

func (*EncodingRegistry) Base64Encode

func (er *EncodingRegistry) Base64Encode(str string) string

Base64Encode encodes a string into its Base64 representation.

Parameters:

str string - the string to encode.

Returns:

string - the Base64 encoded string.

Example:

{{ "Hello World" | base64Encode }} // Output: "SGVsbG8gV29ybGQ="

func (*EncodingRegistry) FromJson

func (er *EncodingRegistry) FromJson(v string) (any, error)

FromJson decodes a JSON string into a Go data structure, returning an error if decoding fails.

Parameters:

v string - the JSON string to decode.

Returns:

any - the decoded Go data structure.
error - error encountered during decoding, if any.

Example:

{{ `{"name":"John", "age":30}` | fromJson }} // Output: map[name:John age:30], nil

func (*EncodingRegistry) FromYAML

func (er *EncodingRegistry) FromYAML(str string) (any, error)

FromYAML deserializes a YAML string into a Go map.

Parameters:

str string - the YAML string to deserialize.

Returns:

any - a map representing the YAML data. Returns nil if deserialization fails.
error - an error message if the YAML content cannot be deserialized.

Example:

{{ "name: John Doe\nage: 30" | fromYaml }} // Output: map[name:John Doe age:30]

func (*EncodingRegistry) LinkHandler

func (or *EncodingRegistry) LinkHandler(fh sprout.Handler) error

LinkHandler links the handler to the registry at runtime.

func (*EncodingRegistry) RegisterAliases added in v0.6.0

func (er *EncodingRegistry) RegisterAliases(aliasesMap sprout.FunctionAliasMap) error

func (*EncodingRegistry) RegisterFunctions

func (er *EncodingRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error

func (*EncodingRegistry) RegisterNotices added in v0.6.0

func (er *EncodingRegistry) RegisterNotices(notices *[]sprout.FunctionNotice) error

func (*EncodingRegistry) ToJson

func (er *EncodingRegistry) ToJson(v any) (string, error)

ToJson encodes a Go data structure into a JSON string, returning an error if encoding fails.

Parameters:

v any - the Go data structure to encode.

Returns:

string - the JSON-encoded string.
error - error encountered during encoding, if any.

Example:

{{ {"name": "John", "age": 30} | toJson }} // Output: "{"age":30,"name":"John"}", nil

func (*EncodingRegistry) ToPrettyJson

func (er *EncodingRegistry) ToPrettyJson(v any) (string, error)

ToPrettyJson encodes a Go data structure into a pretty-printed JSON string, returning an error if encoding fails.

Parameters:

v any - the Go data structure to encode.

Returns:

string - the pretty-printed JSON string.
error - error encountered during encoding, if any.

Example:

{{ {"name": "John", "age": 30} | toPrettyJson }} // Output: "{\n  \"age\": 30,\n  \"name\": \"John\"\n}", nil

func (*EncodingRegistry) ToRawJson

func (er *EncodingRegistry) ToRawJson(v any) (string, error)

ToRawJson encodes a Go data structure into a JSON string without escaping HTML, returning an error if encoding fails.

Parameters:

v any - the Go data structure to encode.

Returns:

string - the raw JSON string.
error - error encountered during encoding, if any.

Example:

{{ {"content": "<div>Hello World!</div>"} | toRawJson }} // Output: "{\"content\":\"<div>Hello World!</div>\"}", nil

func (*EncodingRegistry) ToYAML

func (er *EncodingRegistry) ToYAML(v any) (out string, err error)

ToYAML serializes a Go data structure to a YAML string and returns any error that occurs during the serialization.

Parameters:

v any - the data structure to serialize.

Returns:

string - the YAML string representation of the data structure.
error - error if the serialization fails.

Example:

{{ $d := dict "name" "John Doe" "age" 30 }}
{{ $d | toYaml }} // Output: name: John Doe\nage: 30

func (*EncodingRegistry) Uid

func (or *EncodingRegistry) Uid() string

Uid returns the unique identifier of the registry.

Jump to

Keyboard shortcuts

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