gpt4 book ai didi

google-app-engine - GAE Go 用户服务登录 url 包含 %A(MISSING)

转载 作者:IT王子 更新时间:2023-10-29 01:37:17 27 4
gpt4 key购买 nike

所以这个问题让我困惑了一会儿!

这是控制台中的一些代码:

 func GetLoginLinks(w *http.ResponseWriter, r *http.Request) (string, error) {
c := appengine.NewContext(r)
u := user.Current(c)
if u == nil {
url, err := user.LoginURL(c, r.URL.String())
if err != nil {
http.Error(*w, err.Error(), http.StatusInternalServerError)
return "", err
}

c.Debugf("Return url: " + r.URL.String())
c.Debugf("login url: " + url)
c.Debugf("url type: %T", url)
v := LoginItem(url, "Login")
return v, nil
}
}

它给出了以下输出:

2013/06/17 21:48:28 DEBUG: Return url: /
2013/06/17 21:48:28 DEBUG: login url: /_ah/login?continue=http%A(MISSING)//localhost%A(MISSING)8080/
2013/06/17 21:48:28 DEBUG: url type: string

当上传到应用引擎本身时,这也会失败。

我遇到的问题是该函数的前 4 行直接来自开发人员指南。

最佳答案

package fmt

Format errors:

If an invalid argument is given for a verb, such as providing a string to %d, the generated string will contain a description of the problem, as in these examples:

Wrong type or unknown verb: %!verb(type=value)
Printf("%d", hi): %!d(string=hi)
Too many arguments: %!(EXTRA type=value)
Printf("hi", "guys"): hi%!(EXTRA string=guys)
Too few arguments: %!verb(MISSING)
Printf("hi%d"): hi %!d(MISSING)
Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC)
Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi
Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi

All errors begin with the string "%!" followed sometimes by a single character (the verb) and end with a parenthesized description.

If an Error or String method triggers a panic when called by a print routine, the fmt package reformats the error message from the panic, decorating it with an indication that it came through the fmt package. For example, if a String method calls panic("bad"), the resulting formatted message will look like

%s(PANIC=bad)

The %s just shows the print verb in use when the failure occurred.

您的格式字符串无效。您有格式字符串中的转义 URL 查询字符串:“:”转义为“%3A”。缺少“%3A”动词的格式参数。为了安全起见,切勿使用任意字符串作为格式字符串。例如,

package main

import "fmt"

func main() {
url := "/_ah/login?continue=http%3A//localhost%3A8080/"
fmt.Printf("login url: " + url)
fmt.Println()
fmt.Printf("login url: %s", url)
fmt.Println()
}

输出:

login url: /_ah/login?continue=http%A(MISSING)//localhost%A(MISSING)8080/
login url: /_ah/login?continue=http%3A//localhost%3A8080/

写:

c.Debugf("login url: %s", url)

关于google-app-engine - GAE Go 用户服务登录 url 包含 %A(MISSING),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17157836/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com