referer-parser Golang:生产设置而不是使用占位符值?

时间:2015-05-21 16:50:36

标签: go http-referer

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")
}

1 个答案:

答案 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)
})