mirror of
https://github.com/kataras/iris.git
synced 2025-12-21 03:47:04 +00:00
reorganization of _examples and add some new examples such as iris+groupcache+mysql+docker
Former-commit-id: ed635ee95de7160cde11eaabc0c1dcb0e460a620
This commit is contained in:
28
_examples/request-referrer/main.go
Normal file
28
_examples/request-referrer/main.go
Normal file
@@ -0,0 +1,28 @@
|
||||
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 "Referrer" header as specified
|
||||
// in https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy or by the URL query parameter "referrer".
|
||||
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")
|
||||
}
|
||||
Reference in New Issue
Block a user