gin icon indicating copy to clipboard operation
gin copied to clipboard

Strange, the router is not registered

Open RedCrazyGhost opened this issue 1 year ago • 5 comments

Description

The gin code doesn't work, the router isn't registered and printed, and it doesn't panic

How to reproduce

package main

import (
    "net/http"
    
    "github.com/gin-gonic/gin"
)

func main(){
    r := gin.Default()
	
    r.GET("/", func(c *gin.Context) {
        c.String(http.StatusOK,"i'm ok!")
    })
	
    if err := r.Run(":8080");err != nil{
        panic(err)
    }
}

Expectations

[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

output router context...

Actual result

[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

Environment

  • go version: go1.21.3 darwin/amd64
  • gin version (or commit ref): 1.10.0
  • operating system: macOS 14.5

RedCrazyGhost avatar Jun 30 '24 09:06 RedCrazyGhost

I tried using the new version of go and was able to start the service successfully

use go version go1.22.5 darwin/amd64 output:

[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /                         --> main.main.func1 (3 handlers)
[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details.
[GIN-debug] Listening and serving HTTP on :8080

RedCrazyGhost avatar Jul 07 '24 15:07 RedCrazyGhost

I can't reproduce this issue on the conditions you provided

1911860538 avatar Jul 15 '24 10:07 1911860538

Indeed, this is a very strange question

RedCrazyGhost avatar Jul 15 '24 13:07 RedCrazyGhost

yea i couldn't replicate it either

akhaled01 avatar Oct 28 '24 06:10 akhaled01

I think you are using air for live reload and your new code did not complied yet I have the same problem

nelsonpoon avatar Feb 11 '25 02:02 nelsonpoon