Description
I just setup the gin and test very basic GET request. However, server always throwing an error http: proxy error: dial tcp [::1]:3001: connect: connection refused and couldn't figure out whats wrong with my code.
How to reproduce
package main
import (
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.GET("/", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run()
}
Expectations
$ curl http://localhost:3000/
{"message":"pong"}
Actual result
$ curl http://localhost:3000/
Received nothing in response
Environment
- go version: 1.19.3 darwin/arm64
- gin version (or commit ref): v1.8.1
- operating system: M1 Macbook Pro
Comment From: liuliqiang
Hi @Aashir1 ,
I think there might be a proxy setting in your env, can you show the output for following command executed in your command line?
# env | grep -i http
Comment From: Aashir1
@liuliqiang
Comment From: mstmdev
Can you provide the GIN-debug
log? If you are not setting up the PORT
environment, the default port should be 8080
, but you access the web server by 3000
port.
Comment From: Aashir1
SS after hitting on port 3000
and Yes, I have set the PORT=3000
in .env file. I think development mode is a Debug mode
right?
@mstmdev
Comment From: mstmdev
It looks like using github.com/codegangsta/gin
to implement live-reloading.
Please try to remove PORT=3000
in the .env file, because the default port of proxy server is 3000
.
Comment From: mstmdev
Or maybe the /User/aashirkhan/go/bin/gin/main.go
file is not your code.
I execute the gin run main.go
command in the $GOPATH/src/github.com/codegangsta/gin
path, and get the same error.
root@pc:/mnt/e/workspace/gowork/src/github.com/codegangsta/gin$ ./gin run main.go
[gin] Listening on port 3000
[gin] Building...
[gin] Build finished
[gin] Listening on port 3000
[gin] Building...
2022/11/22 16:21:12 http: proxy error: dial tcp 127.0.0.1:3001: connect: connection refused
Comment From: Aashir1
It looks like using
github.com/codegangsta/gin
to implement live-reloading. Please try to removePORT=3000
in the .env file, because the default port of proxy server is3000
. @Aashir1
It's working, I just removed PORT=3000
from .env file