Thanks to all for trying to find a solution, I simply found that I was registering middleware after routes: in this way, routes declared before middleware are not "covered" by the same middleware.
This code is correctly working:
package main
import (
"github.com/gin-gonic/gin"
"github.com/zsais/go-gin-prometheus"
"net/http"
)
func main() {
router1 := gin.New()
router2 := gin.New()
p := ginprometheus.NewPrometheus("test")
router1.Use(p.HandlerFunc())
p.SetMetricsPath(router2)
router1.GET("/test", func(c *gin.Context) {
c.String(http.StatusOK, "it works")
})
go func() { router2.Run(":7100") }()
router1.Run(":8000")
}