cueutils

package module
v0.0.0-...-d95211f Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MPL-2.0 Imports: 8 Imported by: 2

README

= cueutils

image:https://pkg.go.dev/badge/github.com/DavidGamba/dgtools/cueutils.svg[Go Reference, link="https://pkg.go.dev/github.com/DavidGamba/dgtools/cueutils"]

Provides helpers to work with Cue.

Import: `github.com/DavidGamba/dgtools/cueutils`

== Examples

[source, go]
----
//go:embed schemas/schema.cue
var f embed.FS

	configs := []cueutils.CueConfigFile{}

	// Read embedded schemas
	schemaFilename := "schemas/schema.cue"
	schemaFH, err := f.Open(schemaFilename)
	if err != nil {
		return fmt.Errorf("failed to open '%s': %w", schemaFilename, err)
	}
	defer schemaFH.Close()
	configs = append(configs, cueutils.CueConfigFile{Data: schemaFH, Name: schemaFilename})

	// Read multiple config files
	for _, configFilename := range configFilenames {
		configFH, err := os.Open(configFilename)
		if err != nil {
			return fmt.Errorf("failed to open '%s': %w", configFilename, err)
		}
		defer configFH.Close()
		configs = append(configs, cueutils.CueConfigFile{Data: configFH, Name: configFilename})
	}

	// Unmarshal into local data structure
	d := MyDataStructe{}
	err = cueutils.Unmarshal(configs, &d)
	if err != nil {
		return fmt.Errorf("failed to unmarshal: %w", err)
	}
----

Documentation

Overview

Package cueutils provides helpers to work with Cue

Index

Constants

This section is empty.

Variables

View Source
var Logger = log.New(os.Stderr, "", log.LstdFlags)

Functions

func Unmarshal

func Unmarshal(configs []CueConfigFile, v any) error

Given a set of cue files, it will aggregate them into a single cue config and then Unmarshal it unto the given data structure.

Types

type CueConfigFile

type CueConfigFile struct {
	Data io.Reader
	Name string
}

Jump to

Keyboard shortcuts

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