本文整理汇总了Golang中net/url.QueryUnescape函数的典型用法代码示例。如果您正苦于以下问题:Golang QueryUnescape函数的具体用法?Golang QueryUnescape怎么用?Golang QueryUnescape使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了QueryUnescape函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
keyPrice := getKeyPrice()
fmt.Printf("Key price: %f\n", keyPrice)
fileName := os.Args[1]
fmt.Printf("Processing csv file: %s\n", fileName)
fh, err := os.Open(fileName)
if err != nil {
fmt.Printf("Error: can't open file: %s, msg: %s\n", fileName, err)
os.Exit(1)
}
csvReader := csv.NewReader(fh)
records, err := csvReader.ReadAll()
if err != nil {
fmt.Printf("Error: can't parse file: %s, msg: %s\n", fileName, err)
os.Exit(1)
}
fmt.Println(len(records))
for _, row := range records {
url1, _ := url.QueryUnescape(row[0])
url2, _ := url.QueryUnescape(row[1])
fmt.Printf("url: %s url2: %s\n", url1, url2)
}
}
示例2: parseQuery
func parseQuery(m queryMap, query string) (err error) {
for query != "" {
key := query
if i := strings.Index(key, "&"); i >= 0 {
key, query = key[:i], key[i+1:]
} else {
query = ""
}
if key == "" {
continue
}
value := ""
if i := strings.Index(key, "="); i >= 0 {
key, value = key[:i], key[i+1:]
}
key, err1 := url.QueryUnescape(key)
if err1 != nil {
if err == nil {
err = err1
}
continue
}
value, err1 = url.QueryUnescape(value)
if err1 != nil {
if err == nil {
err = err1
}
continue
}
m[key] = value
}
return err
}
示例3: restRemovePoolVirtualIP
// restRemovePoolVirtualIP deletes virtualip
func restRemovePoolVirtualIP(w *rest.ResponseWriter, r *rest.Request, ctx *requestContext) {
ip, err := url.QueryUnescape(r.PathParam("ip"))
if err != nil {
glog.Errorf("Could not get virtual ip (%v): %v", ip, err)
restBadRequest(w, err)
return
}
poolId, err := url.QueryUnescape(r.PathParam("poolId"))
if err != nil {
glog.Errorf("Could not get virtual ip poolId (%v): %v", poolId, err)
restBadRequest(w, err)
return
}
glog.V(0).Infof("Remove virtual ip=%v (in pool %v)", ip, poolId)
client, err := ctx.getMasterClient()
if err != nil {
restServerError(w, err)
return
}
request := pool.VirtualIP{PoolID: poolId, IP: ip}
if err := client.RemoveVirtualIP(request); err != nil {
glog.Errorf("Failed to remove virtual IP(%+v): %v", request, err)
restServerError(w, err)
return
}
restSuccess(w)
}
示例4: findHandler
func findHandler(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
expr := r.Form.Get("expr")
source := r.Form.Get("source")
var err error
expr, err = url.QueryUnescape(expr)
source, err = url.QueryUnescape(source)
//fmt.Println(expr);
//fmt.Println(source);
re, err := regexp.Compile(expr)
if nil != err {
log.Println(err)
} else if len(expr) > 0 {
markTmpl := fmt.Sprintf("%s%s%s$0%s/%s%s",
openTag, markTag, closeTag, openTag, markTag, closeTag)
source = re.ReplaceAllString(source, markTmpl)
}
source = html.EscapeString(source)
source = strings.Replace(source, "%", "%%", -1)
source = strings.Replace(source, openTag, "<", -1)
source = strings.Replace(source, closeTag, ">", -1)
source = strings.Replace(source, "\n", "<br/>", -1)
respMsg := source
fmt.Fprintf(w, respMsg)
}
示例5: google
func google(paginas int) []string {
fmt.Println("[+]Buscador Google em função beta...")
fmt.Println("[+]CAPTCHA aparece de vez em quando...")
regex_google = `"><a href="/url\?q=(.*?)&sa=U&`
dork_escaped := url.QueryEscape(dork_comando)
if paginas <= 1 {
recebe_download := html_download("https://www.google.com.br/search?q=" + dork_escaped + "&oq=" + dork_escaped + "&gws_rd=cr,ssl&client=ubuntu&ie=UTF-8")
resultado := parser(recebe_download, regex_google)
for i := range resultado {
url_unescaped, err := url.QueryUnescape(resultado[i][1])
erro(err)
resultado_slice_2 = append(resultado_slice_2, url_unescaped)
}
} else if paginas > 1 {
for pa := 1; pa <= paginas; pa++ {
pa_str := strconv.Itoa(pa)
url_paginas := ("https://www.google.com.br/search?q=" + dork_escaped + "&start=" + pa_str + "0") //ulr pa google
recebe_download := html_download(url_paginas)
resultado := parser(recebe_download, regex_google)
for i := range resultado {
url_unescaped, err := url.QueryUnescape(resultado[i][1])
erro(err)
resultado_slice_2 = append(resultado_slice_2, url_unescaped)
}
}
}
return resultado_slice_2
}
示例6: prevHandler
func prevHandler(w http.ResponseWriter, r *http.Request, urlpath string) {
ok, err := regexp.MatchString(
"^"+protocol+"://"+*host+picpattern+".*$", (*r).Referer())
httpErr(err)
if !ok {
http.NotFound(w, r)
return
}
prefix := len(protocol + "://" + *host)
picPath := (*r).Referer()[prefix:]
if path.IsAbs(picPath) {
picPath = picPath[1:]
}
words := strings.Split(picPath, string(filepath.Separator))
file, err := url.QueryUnescape(path.Join(words[2:]...))
httpErr(err)
tag, err := url.QueryUnescape(words[1])
httpErr(err)
s := getPrev(file, tag)
if s == "" {
s = file
}
s = path.Join(picpattern, tag, s)
http.Redirect(w, r, s, http.StatusFound)
}
示例7: parseQuery
//
// Парсит строку запроса
//
func parseQuery(s string) (query, error) {
q := make(query, 0)
for s != "" {
key := s
if i := strings.IndexAny(key, "&;"); i >= 0 {
key, s = key[:i], key[i+1:]
} else {
s = ""
}
if key == "" {
continue
}
value := ""
if i := strings.Index(key, "="); i >= 0 {
key, value = key[:i], key[i+1:]
}
key, err := url.QueryUnescape(key)
if err != nil {
return q, err
}
value, err = url.QueryUnescape(value)
if err != nil {
return q, err
}
q = append(q, map[string]string{
key: value,
})
}
return q, nil
}
示例8: ParseQueryParameters
// Parse query parameters and return them in the right order
func ParseQueryParameters(query string) (params []QueryParameter, err error) {
for query != "" {
key := query
if i := strings.IndexAny(key, "&;"); i >= 0 {
key, query = key[:i], key[i+1:]
} else {
query = ""
}
if key == "" {
continue
}
value := ""
if i := strings.Index(key, "="); i >= 0 {
key, value = key[:i], key[i+1:]
}
key, err1 := url.QueryUnescape(key)
if err1 != nil {
if err == nil {
err = err1
}
continue
}
value, err1 = url.QueryUnescape(value)
if err1 != nil {
if err == nil {
err = err1
}
continue
}
params = append(params, QueryParameter{key, value})
}
return params, err
}
示例9: SplitLDAPQuery
// SplitLDAPQuery splits the query in the URL into the substituent parts. All sections are optional.
// Query syntax is attribute?scope?filter?extensions
func SplitLDAPQuery(query string) (attributes, scope, filter, extensions string, err error) {
parts := strings.Split(query, "?")
switch len(parts) {
case 4:
extensions = parts[3]
fallthrough
case 3:
if v, err := url.QueryUnescape(parts[2]); err != nil {
return "", "", "", "", err
} else {
filter = v
}
fallthrough
case 2:
if v, err := url.QueryUnescape(parts[1]); err != nil {
return "", "", "", "", err
} else {
scope = v
}
fallthrough
case 1:
if v, err := url.QueryUnescape(parts[0]); err != nil {
return "", "", "", "", err
} else {
attributes = v
}
return attributes, scope, filter, extensions, nil
case 0:
return
default:
err = fmt.Errorf("too many query options %q", query)
return "", "", "", "", err
}
}
示例10: JoinTraceFromHeader
// NewSpanFromHeader decodes a Span with operation name `operationName` from
// `h`, expecting that header values are URL-escpaed.
//
// If `operationName` is empty, the caller must later call
// `Span.SetOperationName` on the returned `Span`.
func JoinTraceFromHeader(
operationName string,
h http.Header,
propagator SpanPropagator,
) (Span, error) {
contextIDMap := make(map[string]string)
tagsMap := make(map[string]string)
for key, val := range h {
if strings.HasPrefix(key, ContextIDHTTPHeaderPrefix) {
// We don't know what to do with anything beyond slice item v[0]:
unescaped, err := url.QueryUnescape(val[0])
if err != nil {
return nil, err
}
contextIDMap[strings.TrimPrefix(key, ContextIDHTTPHeaderPrefix)] = unescaped
} else if strings.HasPrefix(key, TagsHTTPHeaderPrefix) {
// We don't know what to do with anything beyond slice item v[0]:
unescaped, err := url.QueryUnescape(val[0])
if err != nil {
return nil, err
}
tagsMap[strings.TrimPrefix(key, TagsHTTPHeaderPrefix)] = unescaped
}
}
return propagator.JoinTraceFromText(operationName, contextIDMap, tagsMap)
}
示例11: TestV1Metric
func TestV1Metric(t *testing.T) {
r := startV1API(getDefaultMockConfig(), "metric")
Convey("Test Metric REST API V1", t, func() {
Convey("Get metrics - v1/metrics", func() {
resp, err := http.Get(
fmt.Sprintf("http://localhost:%d/v1/metrics", r.port))
So(err, ShouldBeNil)
So(resp.StatusCode, ShouldEqual, 200)
body, err := ioutil.ReadAll(resp.Body)
So(err, ShouldBeNil)
resp1, err := url.QueryUnescape(string(body))
So(err, ShouldBeNil)
So(
fmt.Sprintf(fixtures.GET_METRICS_RESPONSE, r.port),
ShouldResemble,
resp1)
})
Convey("Get metrics from tree - v1/metrics/*namespace", func() {
resp, err := http.Get(
fmt.Sprintf("http://localhost:%d/v1/metrics/*namespace", r.port))
So(err, ShouldBeNil)
So(resp.StatusCode, ShouldEqual, 200)
body, err := ioutil.ReadAll(resp.Body)
So(err, ShouldBeNil)
resp1, err := url.QueryUnescape(string(body))
So(err, ShouldBeNil)
So(
fmt.Sprintf(fixtures.GET_METRICS_RESPONSE, r.port),
ShouldResemble,
resp1)
})
})
}
示例12: SignUp
func SignUp(w http.ResponseWriter, r *http.Request) {
var err error
var tmpl *plate.Template
params := r.URL.Query()
error := params.Get("error")
error, _ = url.QueryUnescape(error)
fname := params.Get("fname")
fname, _ = url.QueryUnescape(fname)
lname := params.Get("lname")
lname, _ = url.QueryUnescape(lname)
email := params.Get("email")
email, _ = url.QueryUnescape(email)
username := params.Get("username")
username, _ = url.QueryUnescape(username)
var submitted bool
submitted, err = strconv.ParseBool(params.Get("submitted"))
if err != nil {
submitted = false
}
server := plate.NewServer()
tmpl, err = server.Template(w)
if err != nil {
plate.Serve404(w, err.Error())
return
}
tmpl.Bag["PageTitle"] = "Register"
tmpl.Bag["Error"] = strings.ToTitle(error)
tmpl.Bag["Fname"] = strings.TrimSpace(fname)
tmpl.Bag["Lname"] = strings.TrimSpace(lname)
tmpl.Bag["Email"] = strings.TrimSpace(email)
tmpl.Bag["Username"] = strings.TrimSpace(username)
tmpl.Bag["CurrentYear"] = time.Now().Year()
tmpl.Bag["Submitted"] = submitted
tmpl.Bag["userID"] = 0
tmpl.FuncMap["isNotNull"] = func(str string) bool {
if strings.TrimSpace(str) != "" && len(strings.TrimSpace(str)) > 0 {
return true
}
return false
}
tmpl.FuncMap["isLoggedIn"] = func() bool {
return false
}
templates := append(TemplateFiles, "templates/auth/signup.html")
tmpl.DisplayMultiple(templates)
}
示例13: handler
func handler(f func(w http.ResponseWriter, r *http.Request, jobPath, body string)) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
debug("http:", r.Method, r.RequestURI)
var err error
jobPath := r.URL.Query().Get(":jobPath")
if jobPath == "" {
http.Error(w, "empty routing key", http.StatusBadRequest)
return
}
jobPath, err = url.QueryUnescape(jobPath)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
jobBody := r.URL.Query().Get(":jobBody")
if jobBody == "" {
http.Error(w, "empty job", http.StatusBadRequest)
return
}
jobBody, err = url.QueryUnescape(jobBody)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
f(w, r, jobPath, jobBody)
})
}
示例14: readLineKeyValue
func readLineKeyValue(br *bufio.Reader) (*KeyValue, error) {
k, err := br.ReadString('\t')
if err != nil {
return nil, err
}
k = strings.TrimRight(k, "\t")
keys := strings.SplitN(k, ",", 2)
var reduceKey string
var sortKey string
reduceKey, err = url.QueryUnescape(keys[0])
if err != nil {
return nil, err
}
if len(keys) == 2 {
sortKey, err = url.QueryUnescape(keys[1])
if err != nil {
return nil, err
}
}
v, err := br.ReadString('\n')
if err != nil {
return nil, err
}
v = strings.TrimRight(v, "\n")
return &KeyValue{reduceKey, sortKey, v}, nil
}
示例15: ParseQuery
// ParseQuery provides an alternative to url.ParseQuery when the order of parameters must be retained. ParseQuery
// parses the URL-encoded query string and returns a URLQueryParameters object that can be used to get the ordered list
// of parameters, a map of the parameters, or parameters by name. ParseQuery always returns a non-nil
// URLQueryParameters object containing all the valid query parameters found; err describes the first decoding error
// encountered, if any.
func ParseQuery(query string) (u URLQueryParameters, err error) {
// Replace ";" with "&" so we can split on a single character
query = strings.Replace(query, ";", "&", -1)
// Split it into parts (e.g., "foo=bar" is a part)
parts := strings.Split(query, "&")
// iterate the parts and add them to the URLQueryParameters
for _, part := range parts {
if i := strings.Index(part, "="); i >= 0 {
key, value := part[:i], part[i+1:]
key, keyErr := url.QueryUnescape(key)
if keyErr != nil {
if err == nil {
err = keyErr
}
continue
}
value, valueErr := url.QueryUnescape(value)
if valueErr != nil {
if err == nil {
err = valueErr
}
continue
}
u.Add(key, value)
}
}
return
}