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

Support go module #259

Open
zliang-min opened this issue Jul 24, 2019 · 4 comments
Open

Support go module #259

zliang-min opened this issue Jul 24, 2019 · 4 comments
Labels
area/core enhancement New feature or request

Comments

@zliang-min
Copy link

Expecte when run yaegi in a folder that contains go.mod, one can use import to import the packages defined in the module in go.mod. Currently when I do that, it will report unable to find source related to: "github.com/Gimi/my-module/pkg".

@ldez ldez added area/core enhancement New feature or request labels Jul 24, 2019
@ldez
Copy link
Contributor

ldez commented Jul 24, 2019

Hello, yes for now the only way to manage dependencies is to use the vendor directory.

@AdamSLevy
Copy link

Can you expand on how to manage dependencies?

Let's say I have a local package on my system that I want to import, how do I achieve that?

@ldez
Copy link
Contributor

ldez commented Jul 25, 2019

Something like that:

package main

import (
	"go/build"

	"github.com/containous/yaegi/interp"
	"github.com/containous/yaegi/stdlib"
)

func main() {
	// Create an interpreter and setup a GOPATH
	i := interp.New(interp.Options{GoPath: build.Default.GOPATH})
	// import stdlib
	i.Use(stdlib.Symbols)

	if _, err := i.Eval(`import "github.com/foo/bar"`); err != nil {
		b.Fatal(err)
	}

	fnHello, err := i.Eval(`bar.Hello`)
	if err != nil {
		b.Fatal(err)
	}
  
	// ...
}

$GOPATH/github.com/foo/bar/bar.go

package bar

import github.com/foo/boo

func Hello(){
  boo.Hi()
}

$GOPATH/github.com/foo//bar/vendor/github.com/foo/boo/boo.go

package bar

import fmt

func Hello(){
  fmt.Println("Hello")
}

or you can use the old GOPATH way (no vendor folder)

@lucafabbian
Copy link

any news on this? because right now it is not working.
Even by pointing the interpreter to the right go env GOMODCACHE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants