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
+4.1k Javascript : Empty an array example
+11.1k Golang : Fix go.exe is not compatible with the version of Windows you're running
+19.2k Golang : Execute shell command
+12.8k Golang : Listen and Serve on sub domain example
+7.3k Golang : Of hash table and hash map
+11.1k Golang : Web routing/multiplex example
+13.8k Golang : Convert spaces to tabs and back to spaces example
+5.8k Golang : Markov chains to predict probability of next state example
+12.1k Golang : Decompress zlib file example
+10.8k Android Studio : Checkbox for user to select options example
+12.7k Golang : Remove or trim extra comma from CSV