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
+32.7k Golang : Regular Expression for alphanumeric and underscore
+15.4k Golang : invalid character ',' looking for beginning of value
+4.7k MariaDB/MySQL : Form select statement or search query with Chinese characters
+9.6k Golang : How to extract video or image files from html source code
+16k Golang : How to reverse elements order in map ?
+9.3k Golang : Temperatures conversion example
+17.5k Golang : Find smallest number in array
+14.5k Golang : How to determine if user agent is a mobile device example
+12.1k Golang : Decompress zlib file example
+20.7k Golang : Saving private and public key to files
+35.1k Golang : Upload and download file to/from AWS S3
+9.2k Golang : How to control fmt or log print format?