How import package without .mod file?

Hello

I’m structuring my programs as Go modules. However, one of my programs needs to import the github.com/lxn/walk package. This package doesn’t have a go.mod file because it was written before Go modules were introduced. The usual go get and go get -u commands download it, but they don’t add it to my project. How can I use this package in my project? How do I import it correctly?

Hi @rizlirizlirizli, did you try this already:

  1. Import and use the package in one of your source files (the point is to have an import statement that shows go mod that your code actually uses the package)
  2. run go mod tidy

To use the github.com/lxn/walk package in your Go module, even though it lacks a go.mod file, you can still import it by running:
go get GitHub - lxn/walk: A Windows GUI toolkit for the Go Programming Language
Then, manually add the import path in your code. Go will handle dependencies even for non-module packages. You can also use go mod tidy to clean up and ensure it is properly listed in your go.mod file.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.