fileconvert

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: Apache-2.0 Imports: 11 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 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.

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. 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