Golang html/template.URL type examples
package html/template
URL encapsulates a known safe URL or URL substring (see RFC 3986). A URL like
javascript:checkThatFormNotEditedBeforeLeavingPage()
from a trusted source should go in the page, but by default dynamicjavascript:
URLs are filtered out since they are a frequently exploited injection vector.
Golang html/template.URL type usage examples
Example 1:
func (_ codeGooglePresenter) Image() template.URL {
return "https://github.com/images/gravatars/gravatar-user-420.png"
}
Example 2:
package main
import (
"fmt"
"html/template"
"net/url"
)
func main() {
search := url.Values{
"q": {"wikipedia"},
}
url := url.URL{
Scheme: "https",
Host: "google.com",
Path: "/",
RawQuery: search.Encode(),
}
s := url.String()
tURL := template.URL(s)
fmt.Println(tURL)
}
Output :
https://google.com/?q=wikipedia
References :
https://github.com/shurcooL/Go-Package-Store/blob/master/presenter/codegoogle.go
Advertisement
Something interesting
Tutorials
+13.4k Golang : Read from buffered reader until specific number of bytes
+17.7k Golang : Read data from config file and assign to variables
+19.2k Golang : Check whether a network interface is up on your machine
+10.6k Golang : Bubble sort example
+7.4k Golang : Hue, Saturation and Value(HSV) with OpenCV example
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+6.8k Swift : substringWithRange() function example
+21.2k Golang : Clean up null characters from input data
+15.6k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+11.7k How to tell if a binary(executable) file or web application is built with Golang?
+17.9k Golang : Qt image viewer example
+14.5k Golang : Find network of an IP address