QueryUnescape undefined? [SOLVED]

Hey guys, was QueryUnescape function removed from net/url?

I’m importing this library and using with other stuff but QueryUnescape function seems not to be there…

It is highly unlikely that a function from the standard library gets removed, as this would break the Go 1 compatibility promise. More likely, there is a bug somewhere.

What error message do you get, and which code line triggers the message?

1 Like

Yea that was a bug.

Hi, It seems the error has returned.

Error when I try build:
./index.go:6:5: imported and not used: “net/url”
./index.go:16:35: url.QueryUnescape undefined (type string has no field or method QueryUnescape)

Details:
OS: CentOS Linux release 7.4.1708 (Core)
GO: tested on 1.10 linux/amd64, 1.10 linux/386 and 1.9.4 linux/amd64

Source code:
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.QueryUnescape(name) + “!”))
}

func main() {
http.HandleFunc("/", sayHello)
err := http.ListenAndServe(":9001", nil)
if err != nil {
panic(err.Error())
}
}

You are declaring a variable called url. After that point you can’t access the package url.

Thank you very much, I’m a stupid :man_facepalming:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.