Golang net/http.Request.UserAgent() and Referer() functions example
package net/http
Golang net/http.Request.UserAgent() and Referer() functions usage example
package main
import (
"fmt"
"net/http"
)
func home(w http.ResponseWriter, r *http.Request) {
fmt.Println("User Agent : ", r.UserAgent())
fmt.Println("Referrer : ", r.Referer())
}
func main() {
http.HandleFunc("/", home)
http.ListenAndServe(":8080", nil)
}
Sample output :
User Agent : Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36
Referrer :
References :
Advertisement
Something interesting
Tutorials
+22k Find and replace a character in a string in Go
+72.7k Golang : How to return HTTP status code?
+3.2k Javascript : Empty an array example
+6.8k Golang : get the current working directory of a running program
+4.8k Linux : Disable and enable IPv4 forwarding
+61.4k Golang : Convert HTTP Response body to string
+29.9k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+5.1k Golang : Extract XML attribute data with attr field tag example
+14.9k Golang : convert string or integer to big.Int type
+4.6k Golang : Get S3 or CloudFront object or file information
+15.2k Golang : Convert slice to array