Skip to content

Latest commit

 

History

History
 
 

cueutils

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

cueutils

Go Reference

Provides helpers to work with Cue.

Import: github.com/DavidGamba/dgtools/cueutils

Examples

//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)
	}