codec

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package codec provides capabilities for marshalling and unmarshalling OpenCLI documents.

It supports JSON and YAML formats and automatically validates specs against the official OpenCLI schema definitions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalJSON

func MarshalJSON(doc *spec.Document) ([]byte, error)

MarshalJSON encodes a spec.Document into JSON bytes.

Example:

data, err := codec.MarshalJSON(doc)
if err != nil {
    log.Fatal(err)
}
fmt.Println(string(data))

func MarshalYAML

func MarshalYAML(doc *spec.Document) ([]byte, error)

MarshalYAML encodes a spec.Document into YAML bytes.

Example:

data, err := codec.MarshalYAML(doc)
if err != nil {
    log.Fatal(err)
}
fmt.Println(string(data))

func UnmarshalJSON

func UnmarshalJSON(data []byte) (*spec.Document, error)

UnmarshalJSON decodes a JSON-encoded OpenCLI document into a spec.Document.

Example:

doc, err := codec.UnmarshalJSON([]byte(`{"opencliVersion": "0.1.0", ...}`))
if err != nil {
	log.Fatal(err)
}

func UnmarshalYAML

func UnmarshalYAML(data []byte) (*spec.Document, error)

UnmarshalYAML decodes a YAML-encoded OpenCLI document into a spec.Document.

Example:

doc, err := codec.UnmarshalYAML([]byte("opencliVersion: 0.1.0\n..."))
if err != nil {
    log.Fatal(err)
}

Types

type Format

type Format string

Format represents a supported serialization format for OpenCLI documents.

const (
	// FormatYAML is the YAML serialization format.
	FormatYAML Format = "yaml"
	// FormatJSON is the JSON serialization format.
	FormatJSON Format = "json"
)

Jump to

Keyboard shortcuts

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