Answer the question
In order to leave comments, you need to log in
How to display Cyrillic in the browser on GO?
Good afternoon, there is a code, an example from the Internet, that displays text from the address bar.
Let 's say
1. Going to example.com/test will display "Hello test"
2. Going to example.com/test will display "Hello %D1%82%D0%B5%D1%81%D1%82"
Google says to use "net /url", but when I try I get an error:
./index.go:16:35: url.PathUnescape undefined (type string has no field or method PathUnescape)
package main
import (
"net/http"
"strings"
"net/url"
)
func sayHello(w http.ResponseWriter, r *http.Request) {
name := "World"
url := strings.Trim(r.RequestURI, "/")
if len(url) > 0 {
name = strings.Split(url, "/")[0]
name = strings.ToUpper(name[0:1]) + name[1:] // change first symbol to Uppercase
}
w.Write([]byte("Hello, " + url.PathUnescape(name) + "!"))
}
func main() {
http.HandleFunc("/", sayHello)
err := http.ListenAndServe(":9001", nil)
if err != nil {
panic(err.Error())
}
}
Answer the question
In order to leave comments, you need to log in
The problem is in the url variable declared before calling url.QueryUnescape.
Read RFC , Luke.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question