mirror of
https://github.com/kataras/iris.git
synced 2026-03-06 16:35:57 +00:00
Add a simple 'Context#GetReferrer', as requested by the People: adapt the goreferrer external package
Former-commit-id: 8f1dce93dd5a2449d806f0b28baf5a8c860193b5
This commit is contained in:
39
README.md
39
README.md
@@ -209,6 +209,45 @@ func main() {
|
||||
id: 1234; page: 1; name: manu; message: this_is_great
|
||||
```
|
||||
|
||||
### Extract Referer
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
app.Get("/", func(ctx context.Context) /* or iris.Context, it's the same for Go 1.9+. */ {
|
||||
|
||||
// request header "referer" or url parameter "referer".
|
||||
r := ctx.GetReferrer()
|
||||
switch r.Type {
|
||||
case context.ReferrerSearch:
|
||||
ctx.Writef("Search %s: %s\n", r.Label, r.Query)
|
||||
ctx.Writef("Google: %s\n", r.GoogleType)
|
||||
case context.ReferrerSocial:
|
||||
ctx.Writef("Social %s\n", r.Label)
|
||||
case context.ReferrerIndirect:
|
||||
ctx.Writef("Indirect: %s\n", r.URL)
|
||||
}
|
||||
})
|
||||
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
```
|
||||
|
||||
How to `curl`:
|
||||
|
||||
```bash
|
||||
curl http://localhost:8080?referer=https://twitter.com/Xinterio/status/1023566830974251008
|
||||
curl http://localhost:8080?referer=https://www.google.com/search?q=Top+6+golang+web+frameworks&oq=Top+6+golang+web+frameworks
|
||||
```
|
||||
|
||||
### Upload files
|
||||
|
||||
- [single file upload](_examples/http_request/upload-file/main.go)
|
||||
|
||||
Reference in New Issue
Block a user