transcribe

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: Apache-2.0 Imports: 19 Imported by: 17

README

Transcribe for Go

License Go Reference Go Report Card

Go programs often need to output data in a structured representation format, such as JSON or YAML. But why not provide wider compatibility and support all common formats, letting the user choose? This library provides a unified API over conversion to several formats.

It also supports "pretty" printing to terminals with semantic colorization (including "it just works" support for colorizing Windows terminals, which defy common standards).

Supported formats:

  • YAML
  • JSON, including a convention for extending JSON to support additional type differentiation
  • XML via a conventional schema
  • CBOR
  • MessagePack

The binary formats (CBOR, MessagePack) can be output as is (incompatible with terminals) or textualized into Base64.

Documentation

Index

Constants

View Source
const DIRECTORY_WRITE_PERMISSIONS = 0700
View Source
const FILE_WRITE_PERMISSIONS = 0600

Variables

View Source
var YAMLNodeKinds = map[yaml.Kind]string{
	yaml.DocumentNode: "Document",
	yaml.SequenceNode: "Sequence",
	yaml.MappingNode:  "Mapping",
	yaml.ScalarNode:   "Scalar",
	yaml.AliasNode:    "Alias",
}

Functions

func ColorizeYAML

func ColorizeYAML(code string, writer io.Writer) error

func DumpYAMLNode

func DumpYAMLNode(writer io.Writer, node *yaml.Node, indent int)

func DumpYAMLNodes

func DumpYAMLNodes(writer io.Writer, node *yaml.Node)

func NewJSONColorFormatter

func NewJSONColorFormatter(indent int) *prettyjson.Formatter

func OpenFileForWrite

func OpenFileForWrite(path string) (*os.File, error)

Types

type Transcriber added in v0.2.0

type Transcriber struct {
	Indent    string
	Strict    bool
	Pretty    bool // only applies to Print; when true then Indent is ignored
	Base64    bool
	Reflector *ard.Reflector
}

func NewTranscriber added in v0.2.0

func NewTranscriber() *Transcriber

func (*Transcriber) NewUtterConfig added in v0.2.0

func (self *Transcriber) NewUtterConfig() *utter.ConfigState

func (*Transcriber) Print added in v0.2.0

func (self *Transcriber) Print(value any, writer io.Writer, format string) error

When Pretty is true, takes into account terminal.Colorize and uses terminal.Indent or terminal.IndentSpaces, overriding our Indent.

If value is a [string] will print it as is, ignoring the format argument.

If value is a *etree.Document will use Transcriber.PrintXMLDocument, ignoring the format argument.

func (*Transcriber) PrintCBOR added in v0.2.0

func (self *Transcriber) PrintCBOR(value any, writer io.Writer) error

func (*Transcriber) PrintGo added in v0.2.0

func (self *Transcriber) PrintGo(value any, writer io.Writer) error

func (*Transcriber) PrintJSON added in v0.2.0

func (self *Transcriber) PrintJSON(value any, writer io.Writer) error

func (*Transcriber) PrintMessagePack added in v0.2.0

func (self *Transcriber) PrintMessagePack(value any, writer io.Writer) error

func (*Transcriber) PrintString added in v0.2.0

func (self *Transcriber) PrintString(value any, writer io.Writer) error

func (*Transcriber) PrintXJSON added in v0.2.0

func (self *Transcriber) PrintXJSON(value any, writer io.Writer) error

func (*Transcriber) PrintXML added in v0.2.0

func (self *Transcriber) PrintXML(value any, writer io.Writer) error

func (*Transcriber) PrintXMLDocument added in v0.2.0

func (self *Transcriber) PrintXMLDocument(xmlDocument *etree.Document, writer io.Writer) error

func (*Transcriber) PrintYAML added in v0.2.0

func (self *Transcriber) PrintYAML(value any, writer io.Writer) error

func (*Transcriber) Stringify added in v0.2.0

func (self *Transcriber) Stringify(value any, format string) (string, error)

func (*Transcriber) StringifyCBOR added in v0.2.0

func (self *Transcriber) StringifyCBOR(value any) (string, error)

Note: will always use base64.

func (*Transcriber) StringifyGo added in v0.2.0

func (self *Transcriber) StringifyGo(value any) (string, error)

func (*Transcriber) StringifyJSON added in v0.2.0

func (self *Transcriber) StringifyJSON(value any) (string, error)

func (*Transcriber) StringifyMessagePack added in v0.2.0

func (self *Transcriber) StringifyMessagePack(value any) (string, error)

Note: will always use base64.

func (*Transcriber) StringifyXJSON added in v0.2.0

func (self *Transcriber) StringifyXJSON(value any) (string, error)

func (*Transcriber) StringifyXML added in v0.2.0

func (self *Transcriber) StringifyXML(value any) (string, error)

func (*Transcriber) StringifyYAML added in v0.2.0

func (self *Transcriber) StringifyYAML(value any) (string, error)

func (*Transcriber) WithIndent added in v0.2.0

func (self *Transcriber) WithIndent(indent string) *Transcriber

func (*Transcriber) Write added in v0.2.0

func (self *Transcriber) Write(value any, writer io.Writer, format string) error

func (*Transcriber) WriteCBOR added in v0.2.0

func (self *Transcriber) WriteCBOR(value any, writer io.Writer) error

func (*Transcriber) WriteGo added in v0.2.0

func (self *Transcriber) WriteGo(value any, writer io.Writer) error

func (*Transcriber) WriteJSON added in v0.2.0

func (self *Transcriber) WriteJSON(value any, writer io.Writer) error

func (*Transcriber) WriteMessagePack added in v0.2.0

func (self *Transcriber) WriteMessagePack(value any, writer io.Writer) error

func (*Transcriber) WriteOrPrint added in v0.2.0

func (self *Transcriber) WriteOrPrint(value any, writer io.Writer, output string, format string) error

Convenience function. If output is an empty string will be identical to Transcriber.Print, otherwise will call Transcriber.WriteToFile on the output, ignoring the writer argument.

func (*Transcriber) WriteToFile added in v0.2.0

func (self *Transcriber) WriteToFile(value any, output string, format string) error

Opens the output file for write and calls Transcriber.Write on it.

func (*Transcriber) WriteXJSON added in v0.2.0

func (self *Transcriber) WriteXJSON(value any, writer io.Writer) error

func (*Transcriber) WriteXML added in v0.2.0

func (self *Transcriber) WriteXML(value any, writer io.Writer) error

func (*Transcriber) WriteXMLDocument added in v0.2.0

func (self *Transcriber) WriteXMLDocument(xmlDocument *etree.Document, writer io.Writer) error

func (*Transcriber) WriteYAML added in v0.2.0

func (self *Transcriber) WriteYAML(value any, writer io.Writer) error

Jump to

Keyboard shortcuts

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