环境go1.17.8
mac m1
按pdf学习需要github.com/julienschmidt/httprouter这个包,
```go
package main
import (
"fmt"
"net/http"
"github.com/julienschmidt/httprouter"
)
func hello(w http.ResponseWriter,r *http.Request,p httprouter.Params){
fmt.Fprintf(w,"Hello world")
}
func main() {
mux := httprouter.New()
mux.GET("/hello/:name",hello)
server := http.Server{
Addr: "localhost:8080",
Handler: mux,
}
err := server.ListenAndServe()
if err!=nil{
fmt.Println(err.Error())
}
}
```
但是go mod tidy报错,
我的gopath设置是Users/xx/gopath这样的目录
![image.png](https://static.golangjob.cn/220427/e1d83452c2a4200978d7b6486146ed40.png)
go mod download好像没有任何错误
![image.png](https://static.golangjob.cn/220427/85c706d6871aa225af5ba16d8b070f17.png)
go run main.go的时候也能跑起来,不知道我goland包总是标红是什么情况
![image.png](https://static.golangjob.cn/220427/5260d39067e03376f1046227997f6529.png)
![image.png](https://static.golangjob.cn/220427/5b5a0ad3bc4a8b83747888f2601de248.png)
有疑问加站长微信联系(非本文作者)