filebasics

package
v0.1.32 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deserialize added in v0.1.8

func Deserialize(data []byte) (map[string]interface{}, error)

Deserialize will deserialize data as a JSON or YAML object. Will return an error if deserializing fails or if it isn't an object.

func DeserializeFile added in v0.1.8

func DeserializeFile(filename string) (map[string]interface{}, error)

DeserializeFile will read a JSON or YAML file and return the top-level object. Will return an error if it fails reading or the content isn't an object. Reads from stdin if filename == "-".

func MustDeserialize

func MustDeserialize(data []byte) map[string]interface{}

MustDeserialize will deserialize data as a JSON or YAML object. Will panic if deserializing fails or if it isn't an object. Will never return nil.

func MustDeserializeFile

func MustDeserializeFile(filename string) map[string]interface{}

MustDeserializeFile will read a JSON or YAML file and return the top-level object. Will panic if it fails reading or the content isn't an object. Reads from stdin if filename == "-". This will never return nil.

func MustReadFile

func MustReadFile(filename string) []byte

MustReadFile reads file contents. Will panic if reading fails. Reads from stdin if filename == "-"

func MustSerialize

func MustSerialize(content map[string]interface{}, format OutputFormat) []byte

MustSerialize will serialize the result as a JSON/YAML. Will panic if serializing fails.

func MustWriteFile

func MustWriteFile(filename string, content []byte)

MustWriteFile writes the output to a file. Will panic if writing fails. Writes to stdout if filename == "-"

func MustWriteSerializedFile

func MustWriteSerializedFile(filename string, content map[string]interface{}, format OutputFormat)

MustWriteSerializedFile will serialize the data and write it to a file. Will panic if it fails. Writes to stdout if filename == "-"

func ReadFile added in v0.1.8

func ReadFile(filename string) ([]byte, error)

ReadFile reads file contents. Reads from stdin if filename == "-"

func Serialize added in v0.1.14

func Serialize(content map[string]interface{}, format OutputFormat) ([]byte, error)

Serialize will serialize the result as a JSON/YAML. Format parameter is case-insensitive.

func WriteFile added in v0.1.14

func WriteFile(filename string, content []byte) error

WriteFile writes the output to a file. Writes to stdout if filename == "-"

func WriteSerializedFile added in v0.1.14

func WriteSerializedFile(filename string, content map[string]interface{}, format OutputFormat) error

WriteSerializedFile will serialize the data and write it to a file. Writes to stdout if filename == "-"

Types

type OutputFormat added in v0.1.18

type OutputFormat string
const (
	OutputFormatYaml OutputFormat = "yaml"
	OutputFormatJSON OutputFormat = "json"
)

Jump to

Keyboard shortcuts

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