New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: Move Print Debug to Run() functions? #3922
Comments
if you insert Enter environment variables you get Expected result |
I think a new Gin instance has been New and should be set up around it
|
Unless you're saying, what you put with g2.SetMode is how you THINK it should be. If so, I could get behind that. |
The point I'm making is just that it's confusing to use the current API and it feels more natural to set up each instance.(for discussion purposes) Regardless of current usage.(Maybe I should open a new issue) |
Alright, yeah then you're further proving my point that it isnt so straight forward. Cause even in your suggested design, you would still get the Debug mention when you do g1 := gin.New() because the Gin MOde is declared after, which isnt what one would expect (At least isnt waht I would expect) I think that debug warning shouldnt be called until the gin server is actually called upon to ListenAndServe. I can also see a value in it being on a per instance basis like you're suggesting as well. |
Yes, I agree with your point too. I hope that while improving the API, I will also correct the debug information you mentioned. |
There is a problem with the execution location of package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
gin.SetMode(gin.ReleaseMode)
g := gin.New()
g.GET("/", func(c *gin.Context) {
c.JSON(http.StatusOK,"ok")
})
g.Run(":9000")
} I have tried a variety of assignment methods, but the effect is not ideal. I may only be able to achieve consistent and good results under package main
import (
"fmt"
"net/http"
"sync"
"github.com/gin-gonic/gin"
)
var w sync.WaitGroup
func main() {
for _,p := range []struct {
port string
mod string
}{
{
port: ":9000",
mod: gin.ReleaseMode,
},
{
port: ":9001",
mod: gin.DebugMode,
},
}{
w.Add(1)
go func(port,mod string) {
gin.Engine{}
gin.SetMode(mod)
fmt.Println(gin.Mode())
r := gin.New()
r.GET("/"+port, func(c *gin.Context) {
c.JSON(http.StatusOK,"ok")
})
r.Run(port)
}(p.port,p.mod)
}
w.Wait()
} |
Description
Currently, the debugPrintWARNINGNew() function runs when you call gin.New(). This can, under the right circumstances, cause confusions to the developer if they call gin.New() and then call gin.SetMode(gin.ReleaseMode) after that .New().
The debug warning will print, even though the developer did set the mode to release mode before actually running the gin server.
Would it not make more sense to check and print the debug message when we actually go to run the server?
How to reproduce
Expectations
Actual result
Environment
The text was updated successfully, but these errors were encountered: