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
+6.9k Golang : Normalize email to prevent multiple signups example
+33.6k Golang : How to check if slice or array is empty?
+21.6k Golang : Encrypt and decrypt data with TripleDES
+80.6k Golang : How to return HTTP status code?
+19.2k Golang : Populate dropdown with html/template example
+31.5k Golang : bufio.NewReader.ReadLine to read file line by line
+7.4k Golang : Scanf function weird error in Windows
+9.9k Golang : Turn string or text file into slice example
+14.8k Golang : Normalize unicode strings for comparison purpose
+21.6k Golang : GORM create record or insert new record into database example
+14.4k Golang : Find network of an IP address
+17.6k Golang : Upload/Receive file progress indicator