Golang:杜松子酒:获取基本网址

问题描述

如果您看到我的评论我的意思是冒号之前的内容,我想打印路线的基本网址。更具体地说,它应该是此处router.Run(":3000")符号之前的东西。

[因此,根据我的注释代码,它应该是 localhost 。我只想打印 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")
}

因此,XY是从路由包返回路由的两个函数,我的api很好,响应可以通过 postman 测试。我只想在符号

之前打印字符串

在尝试中,我尝试使用router.BasePath()。但这只会打印 /

所以请帮助我做到这一点

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)