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
+41k Golang : How to check if a string contains another sub-string?
+6.3k Golang : Detect face in uploaded photo like GPlus
+12.2k Golang : Get remaining text such as id or filename after last segment in URL path
+23k Golang : Calculate time different
+4.6k JavaScript : Rounding number to decimal formats to display currency
+15.2k Golang : Accurate and reliable decimal calculations
+18.6k Golang : Get download file size
+11.6k SSL : The certificate is not trusted because no issuer chain was provided
+18.7k Unmarshal/Load CSV record into struct in Go
+7.2k CloudFlare : Another way to get visitor's real IP address
+10.6k Golang : Select region of interest with mouse click and crop from image
+13k Swift : Convert (cast) Int to String ?