英文:
referer-parser Golang: Production setting instead of using placeholder value?
问题
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")
}
请注意,这只是一个示例代码,你需要根据实际情况进行修改。
英文:
referer-parser
read placeholder value in the example, while the production setting is not documented.
I need referer-parser
to read real referer value instead of placeholder value.
Below is my code (the referer_url
read placeholder value):
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")
}
答案1
得分: 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)
})
英文:
Read the value you want from the http headers inside your handler:
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)
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论