2018-08-04 14:19:17 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
2018-08-04 14:19:17 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := iris.New()
|
|
|
|
|
2019-08-11 14:43:47 +02:00
|
|
|
app.Get("/", func(ctx iris.Context) {
|
2020-06-07 14:26:06 +02:00
|
|
|
// GetReferrer extracts and returns the information from the "Referrer" header as specified
|
|
|
|
// in https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy or by the URL query parameter "referrer".
|
2018-08-04 14:19:17 +02:00
|
|
|
r := ctx.GetReferrer()
|
|
|
|
switch r.Type {
|
2019-08-11 14:43:47 +02:00
|
|
|
case iris.ReferrerSearch:
|
2018-08-04 14:19:17 +02:00
|
|
|
ctx.Writef("Search %s: %s\n", r.Label, r.Query)
|
|
|
|
ctx.Writef("Google: %s\n", r.GoogleType)
|
2019-08-11 14:43:47 +02:00
|
|
|
case iris.ReferrerSocial:
|
2018-08-04 14:19:17 +02:00
|
|
|
ctx.Writef("Social %s\n", r.Label)
|
2019-08-11 14:43:47 +02:00
|
|
|
case iris.ReferrerIndirect:
|
2018-08-04 14:19:17 +02:00
|
|
|
ctx.Writef("Indirect: %s\n", r.URL)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-06-07 14:26:06 +02:00
|
|
|
// 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
|
2020-04-28 04:22:58 +02:00
|
|
|
app.Listen(":8080")
|
2018-08-04 14:19:17 +02:00
|
|
|
}
|