I'm learning Go ad I'm trying to build go file:
package main
import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"net/http"
)
func main() {
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("welcome"))
})
http.ListenAndServe(":3000", r)
}
But when I build the program with the command go build main.go
, it outputs:
go: github.com/go-chi/chi/@v1.5.4: missing go.sum entry; to add it:
go mod download github.com/go-chi/chi/
go.mod
:
module exprog
go 1.16
require github.com/go-chi/chi/ v1.5.4
when I execute go mod download github.com/go-chi/chi/
, I get this error:
go: github.com/go-chi/chi/@v1.5.4: malformed module path "github.com/go-chi/chi/": trailing slash
What I should do?
CodePudding user response:
Assuming you're looking to download this module, You should do go mod download github.com/go-chi/chi/v5
. The name of the module is the header in the dependency's go.mod file.
You can remove the entry from go.mod and simply do go mod download github.com/go-chi/chi/v5
or
You can remove the entry from go.mod, and do go mod tidy
. Go will fill your go.mod file based on your imports. You can do go mod download
then.