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

An error will be reported when using third-party packages on Windows #153

Closed
xiayudeshijie opened this issue Dec 5, 2023 · 2 comments
Closed
Assignees

Comments

@xiayudeshijie
Copy link

vm.go file
package main

import (
"github.com/gin-gonic/gin"
)

func Gin() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})

r.Run()

}

and main.go file
content, err := ioutil.ReadFile("vm.go")
if err != nil {
fmt.Println("read file failed")
}
source := string(content)
src := strings.NewReader(source)
// int gomacro
interp := fast.New()
// check code
if _, err := interp.EvalReader(src); err != nil {
fmt.Println("-------------")
}
interp.ChangePackage("main", "main")
interp.Eval(Gin())

then run main.go
// debug: running "go get github.com/gin-gonic/gin" ...
// warning: created files in "C:\Users\Administrator\go\src\github.com\cosmos72\gomacro\imports/thirdparty", recompile gomacro to use it
repl.go:8:7: undefined "gin" in gin.Default <*ast.SelectorExpr>
Error: repl.go:17:1: undefined identifier: Gin

How to resolve this problem?

@cosmos72
Copy link
Owner

cosmos72 commented Dec 6, 2023

Hello @xiayudeshijie,

Importing third-party packages at runtime is not supported on Windows, because the plugin Go package required for such feature does not (yet) work on Windows.

Such limitation is documented in the main README: https://github.com/cosmos72/gomacro#other-systems

As a workaround, you can use gomacro inside a virtual machine running a Linux guest operating system.
Some examples of free virtual machine programs are:

  • WSL i.e. Windows Subsystem for Linux, is preinstalled on Windows 11
  • Docker
  • Oracle VirtualBox
  • Microsoft Parallels (trial version is free)
  • VMware Workstation Player
    etc.

@xiayudeshijie
Copy link
Author

Thanks

@cosmos72 cosmos72 closed this as completed Jan 7, 2024
@cosmos72 cosmos72 changed the title An error will be reported when using third-party packages An error will be reported when using third-party packages on Windows Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants