codec

package module
v0.0.0-...-a33e76d Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: MIT Imports: 22 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SupportedFileTypes = []Encoding{
	{JSON, json.Unmarshal, jsonMarshalIndent},
	{YAML, yaml.Unmarshal, yaml.Marshal},
	{YML, yaml.Unmarshal, yaml.Marshal},
	{TOML, toml.Unmarshal, tomlMarshal},
	{HCL, hclUnmarshal, hclMarshal},
	{TF, hclUnmarshal, hclMarshal},
	{CSV, csvUnmarshal, jsonMarshalIndent},
	{XML, xmlUnmarshal, xmlMarshal},
	{INI, iniUnmarshal, iniMarshal},
	{GRON, gronUnmarshal, gronMarshal},
}

Functions

func Marshal

func Marshal(v interface{}, outputFileType EncodingType) ([]byte, error)

func PrettyFormat

func PrettyFormat(s string, fileType EncodingType, raw bool) (string, error)

func Unmarshal

func Unmarshal(input []byte, inputFileType EncodingType, data interface{}) error

Types

type Encoding

type Encoding struct {
	Ext       EncodingType
	Unmarshal func([]byte, interface{}) error
	Marshal   func(interface{}) ([]byte, error)
}

type EncodingType

type EncodingType int

EncodingType represents the supported encoding types as an enum with a string representation

const (
	JSON EncodingType = iota
	YAML
	YML
	TOML
	HCL
	TF
	CSV
	XML
	INI
	GRON
)

func GetEncodingType

func GetEncodingType(fileType string) (EncodingType, error)

func (EncodingType) String

func (e EncodingType) String() string

Jump to

Keyboard shortcuts

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