Skip to content
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

Example with Gin #28

Closed
dingdayu opened this issue Oct 30, 2020 · 1 comment
Closed

Example with Gin #28

dingdayu opened this issue Oct 30, 2020 · 1 comment

Comments

@dingdayu
Copy link

dingdayu commented Oct 30, 2020

If you are using Gin, I hope the following content can help you:

router = gin.New()
router.GET("/debug/statsviz/*filepath", func(context *gin.Context) {
	if context.Param("filepath") == "/ws" {
		statsviz.Ws(context.Writer, context.Request)
		return
	}
	statsviz.IndexAtRoot("/debug/statsviz").ServeHTTP(context.Writer, context.Request)
})
router.Run(":8080")

Failed example

Fail one: "Not Found."

router = gin.New()
router.GET("/debug/statsviz/ws", gin.WrapF(statsviz.Ws))
router.GET("/debug/statsviz/",  gin.WrapH(statsviz.Index))
router.Run(":8080")

Because /debug/statsviz/ is a static directory, Need to register with router.StaticFS("/more_static", http.Dir("my_file_system"))

gin#serving-static-files

Fail two: "wildcard route conflicts with existing children"

router = gin.New()
router.GET("/debug/statsviz/ws", gin.WrapF(statsviz.Ws))
router.GET("/debug/statsviz/*filepath",  gin.WrapH(statsviz.Index))
router.Run(":8080")

panic: '/ws' in new path '/debug/statsviz/ws' conflicts with existing wildcard '/*filepath' in existing prefix '/debug/statsviz/*filepath'

Related issue:

gin-gonic/gin#2016
gin-gonic/gin#1681

Good debugging tool, hope to help more people.

@arl
Copy link
Owner

arl commented Nov 8, 2020

Thank you @dnnnvx
I added the example with your code 👍

@arl arl closed this as completed in c426591 Nov 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants