Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to import cue.mod in .go file #3552

Open
ningan123 opened this issue Nov 5, 2024 · 0 comments
Open

How to import cue.mod in .go file #3552

ningan123 opened this issue Nov 5, 2024 · 0 comments
Labels
Triage Requires triage/attention

Comments

@ningan123
Copy link

I wanna import cue.mod in mian.go file, but got error:

# go run main.go
package "mod.test/pkg:bar" imported but not defined in :
    3:8

scheme: 
_|_ // package "mod.test/pkg:bar" imported but not defined in  (and 1 more errors)

How to fix it?

main.go

package main

import (
	"errors"
	"fmt"
	"os"
	"path/filepath"

	"cuelang.org/go/cue"
	"cuelang.org/go/cue/cuecontext"
	cueerror "cuelang.org/go/cue/errors"
	// "cuelang.org/go/mod/module"
)

func main() {

	ctx := cuecontext.New()

	clusterVal := ctx.NewList()

	confPath := "xxx"
	fileData, err := os.ReadFile(filepath.Join(confPath, "in.cue"))
	if err != nil {
		fmt.Println(err.Error())
	}

	// fmt.Println(module.Version.Path())
	scheme := ctx.CompileBytes(fileData, cue.Scope(clusterVal))
	if scheme.Err() != nil {
		msg := cueerror.Details(scheme.Err(), nil)
		fmt.Println(errors.New(msg))
	}
	fmt.Printf("scheme: \n%s\n", scheme)
}

in.cue

package foo

import "mod.test/pkg:bar"

bar
z: 3

cue.mod/module.cue

module: "mod.test"
language: version: "v0.9.0"

pkg/bar.cue

package bar

import "mod.test/pkg:baz"

foo: {
	baz
	y: 2
}
foo

pkg/baz.cue

package baz

x: 1
@ningan123 ningan123 added the Triage Requires triage/attention label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Triage Requires triage/attention
Projects
None yet
Development

No branches or pull requests

1 participant