I want to print base url of my routes, if you see my comments i mean the thing before colon sign : . More specifically its should be the thing before : sign of router.Run(":3000")
here.
[ So according to my commented code it should be localhost. I just want to print localhost ]
package main
import (
"fmt"
"r/p/routes"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
routes.X(router) // localhost:3000/getpens
routes.Y(router) // localhost:3000/getpencils
router.Use(cors.Default())
fmt.Println("this is base path : "+router.BasePath())
router.Run(":3000")
}
So here X
and Y
are two functions that return routes from routes package, my api is fine, response ok tested by postman. I just want to print the string before : sign
In my attempts, I tried using router.BasePath()
. But that only prints /
So please help me to do this