Reputation: 1218
Trying to run
go mod init `pwd`
On a trivial example
package main
import (
"net/http"
"github.com/labstack/echo/v4"
)
func main() {
// Echo instance
e := echo.New()
// Route => handler
e.GET("/", func(c echo.Context) error {
return c.HTML(http.StatusOK, "Hello, World!\n")
})
// Start server
e.Logger.Fatal(e.Start(":1323"))
}
Gives an error
go malformed import path (path to file) empty path element
Yet if I create a manual go.mod like this
module <path>
go 1.12
require github.com/labstack/echo/v4 v4.1.6
Then I can build / run the code normally.
Any idea why go mod init fails? Mostly for future reference as creating the go.mod solves the immediate issue.
Upvotes: 5
Views: 18080
Reputation: 11
As suggested above, go mod init but without / at the beginning of your path works. Perhaps outside of GOPATH relative paths should be used instead of absolute paths(?)
Upvotes: 1
Reputation: 11
Try initializing the modules in the console. The syntax for that is go mod init <mod_name>
where mod_name can be github.com/labstack/echo/v4.
Upvotes: 1