golang - get current path
server쪽에서 현재의 path 정보를 가져오고 싶은 경우가 있다.
g.GET("/:id", func(c echo.Context) error {
r := c.Request()
baseURL := c.Scheme() + "://" + r.Host
currentURL := c.Scheme() + "://" + r.Host + r.URL.Path
}
예를 들어 url이 http://localhost:3000/open/5be24e26d230cc5f84002762 이라고 할 때, 위에서 위에서 baseURL의 값을 출력해보면 http://localhost:3000이 나오고, currentURL의 값을 출력해보면 http://localhost:3000/open/5be24e26d230cc5f84002762이 출력된다.
댓글
댓글 쓰기