Help us shape the future of Go! Take the 2026 Go Developer Survey

fileconvert

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package fileconvert provides functions for marshalling Minder proto objects to and from on-disk formats like YAML.

Package fileconvert provides functions for marshalling Minder proto objects to and from on-disk formats like YAML.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadFromPath added in v0.3.0

func ReadFromPath(printer Printer, file util.ExpandedFile) ([]minderv1.ResourceMeta, error)

ReadFromPath reads a _single_ file (possibly expanded) and returns a set of Minder resources (often 1, but YAML files may include multiple documents) decoded by file type. If "-" is passed as the filename, stdin will be read as a YAML document.

TODO: do we want to return minderv1.ErrNotAResource or minderv1.ErrInvalidResource on parse erros? Right now, we simply skip them (from ResourcesFromPaths' behavior).

func ReadResource

func ReadResource(input Decoder) (minderv1.ResourceMeta, error)

ReadResource reads a single resource from the specified Decoder. Only known resource types are supported; others will return an error. Given that multiple resources can be stored in a single file, the the input may not be fully consumed. ReadResource will always return either a (pointer to) resource or an error; it will never return a nil resource.

The resource is returned as a proto.Message, which can be type-asserted to the appropriate type (see also ReadResourceTyped). Like WriteResource, this uses proto JSON serialization in addition to naive decoding to handle proto-specific encoding features.

func ReadResourceTyped

func ReadResourceTyped[T proto.Message](input Decoder) (T, error)

ReadResourceTyped reads a single resource from the specified Decoder and returns it as the specified subtype of proto.Messsage. Given that T is pointer, this will always return either a non-nil pointer or an error.

This is a convenience wrapper around ReadResource that handles the type assertion for you.

func ResourcesFromPaths

func ResourcesFromPaths(printer Printer, paths ...string) ([]minderv1.ResourceMeta, error)

ResourcesFromPaths collects

func WriteResource

func WriteResource(output Encoder, resource minderv1.ResourceMeta) error

WriteResource outputs a Minder proto resource to an existing Encoder. Only known resource types are supported; others will return an error.

This uses the proto JSON serialization to convert the resource to an object, as a naive transformation from proto to YAML does not nicely deal with Structs and other proto features. In the case of JSON, this *does* mean that we encode to JSON twice, but this is not expected to be a high-performance path.

Types

type Decoder

type Decoder interface {
	Decode(v any) error
}

Decoder is a superset of the yaml.Decoder and json.Decoder interfaces.

func DecoderForFile

func DecoderForFile(path string) (Decoder, io.Closer)

DecoderForFile returns a Decoder for the file at the specified path, or nil if the file is not of the appropriate type.

type Encoder

type Encoder interface {
	Encode(v any) error
}

Encoder is a superset of the yaml.Encoder and json.Encoder interfaces.

type Printer

type Printer func(string, ...any)

Printer provides an interface for passing a printf-like function.

Jump to

Keyboard shortcuts

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