golang安装gin框架报错
cannot find module providing package github.com/gin-gonic/gin: working directory is not part of a module
golang安装gin框架报错 cannot find module providing package github.com/gin-gonic/gin: working directory is not part of a module
go mod init gin
go mod edit -require github.com/gin-gonic/gin@latest
To initialize a project with go module, run:
go mod init your-project-name
This will create a go.mod file in your project directory.
Add missing and/or remove unused modules:
go mod tidy
This will fill up the go.mod file with appropriate modules and create a go.sum in your project directory. The go.sum contains expected cryptographic hashes of each module version.
After that, the go run example.go command should run the program without any issues.
You can even vendor the modules in your project directory:
go mod vendor
This will bring all the vendors to your projects /vendor directory so that you don’t need to get the modules again if working from another machine on this project