referer-parser Golang:在生产环境中是否可以使用占位符值而不是使用默认值?

huangapple go评论80阅读模式
英文:

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

huangapple
  • 本文由 发表于 2015年5月22日 00:50:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/30379822.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定