referer-parser
在示例中读取占位符值,而未记录生产设置。
我需要referer-parser
来读取真实的引用值而不是占位符值。
以下是我的代码(referer_url
读取占位符值):
package main
import (
"github.com/labstack/echo"
"github.com/snowplow/referer-parser/go"
"net/http"
)
func main() {
e := echo.New()
referer_url := "http://www.google.com/search?q=gateway+oracle+cards+denise+linn&hl=en&client=safari"
r := refererparser.Parse(referer_url)
e.Get("/users", func(c *echo.Context) *echo.HTTPError {
return c.String(http.StatusOK, "The search term is: "+r.SearchTerm)
})
e.Run(":4444")
}
答案 0 :(得分:1)
从处理程序中的http标头中读取您想要的值:
e.Get("/users", func(c *echo.Context) *echo.HTTPError {
refererURL := c.Request.Header.Get("Referer")
r := refererparser.Parse(refererURL)
return c.String(http.StatusOK, "The search term is: "+r.SearchTerm)
})