template

package
v0.15.8 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JsonToYaml

func JsonToYaml(js string) (string, error)

JsonToYaml converts a JSON string into a YAML string.

The function takes a JSON string as input and attempts to unmarshal it into an empty interface. If the unmarshalling is successful, it marshals the data back into a YAML string using the YAML package.

On success, the function returns the YAML string and a nil error. If there is any error during the conversion, it returns an empty string and the corresponding error.

func TryParse

func TryParse(tmpStr, jason string) string

TryParse attempts to parse and execute a template with the given JSON string.

The function takes two string inputs - a template string (tmpStr) and a JSON string. It attempts to parse the template string using the "text/template" package. If there is any error during parsing, the function returns the original JSON string.

If the template is parsed successfully, the function attempts to execute the template using the provided JSON string as input data. If there is any error during execution, the function returns the original JSON string.

On successful execution, the function returns the resulting string from the executed template.

func ValidJSON

func ValidJSON(s string) bool

ValidJSON checks if the provided string is a valid JSON object.

The function takes a string as input and attempts to unmarshal it into a map[string]any using the JSON package. If the unmarshalling is successful, it returns true, indicating that the string is a valid JSON object. Otherwise, it returns false.

Types

This section is empty.

Jump to

Keyboard shortcuts

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