This is a creation in Article, where the information may have evolved or changed.
1. How to display pictures in HTML?
Enable static server: for example:
Http.handle ("/", HTTP. Fileserver (http. Dir ("/A"))): The reason for including/A is to open access rights under the/a directory. This gives you access to the/a/xx.jpg in HTML.
2. parse the HTML page, the href contains Chinese, download the problem?
{{range .name}} <a href="{{.}}"></a></br> {{end}}
A): When the template parses the previous segment code, {{.}} assumes that it is replaced by "hello. txt", and HREF=%E4%BD%A0%E5%A5%BD is automatically encoded when the source is displayed in the browser.
b): When clicking on the link href=%e4%bd%a0%e5%a5%bd, the URL must be converted to a character string before being submitted to the Golang server and then using the URL. Queryunescape () to decode. in this way, the corresponding Chinese path or resource can be displayed in the background. Such as:
photoname := strings.TrimPrefix(r.URL.String(), "/") photoname, err := url.QueryUnescape(photoname)
Get the Photoname value: Hello. txt. ^.^