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
+7.1k Golang : Squaring elements in array
+7.7k Golang : Generate human readable password
+13.4k Golang : Generate Code128 barcode
+9.9k Golang : Function wrapper that takes arguments and return result example
+13.4k Golang : Get constant name from value
+6.7k Golang : Derive cryptographic key from passwords with Argon2
+10.9k Golang : How to transmit update file to client by HTTP request example
+12.6k Golang : Transform comma separated string to slice example
+40.5k Golang : Convert to io.ReadSeeker type
+12.1k Golang : Split strings into command line arguments
+10.3k Golang : Convert file content to Hex