iris/_examples/request-referrer/main.go
Gerasimos (Makis) Maropoulos b4fcaab459 minor: try to extract from both referer and referrer header and url query parameter
Former-commit-id: c0ed0916f35ee9cffe0b267e34d5708c1d38082b
2020-06-11 01:58:35 +03:00

29 lines
896 B
Go

package main
import (
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
app.Get("/", func(ctx iris.Context) {
// GetReferrer extracts and returns the information from the "Referer" (or "Referrer") header
// and url query parameter as specified in https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy.
r := ctx.GetReferrer()
switch r.Type {
case iris.ReferrerSearch:
ctx.Writef("Search %s: %s\n", r.Label, r.Query)
ctx.Writef("Google: %s\n", r.GoogleType)
case iris.ReferrerSocial:
ctx.Writef("Social %s\n", r.Label)
case iris.ReferrerIndirect:
ctx.Writef("Indirect: %s\n", r.URL)
}
})
// http://localhost:8080?referrer=https://twitter.com/Xinterio/status/1023566830974251008
// http://localhost:8080?referrer=https://www.google.com/search?q=Top+6+golang+web+frameworks&oq=Top+6+golang+web+frameworks
app.Listen(":8080")
}