Код: Выделить всё
--callback--
authCookieValue := objx.New(map[string]interface{}{
"name": user.Name(),
}).MustBase64()
http.SetCookie(w, &http.Cookie{
Name: "auth",
Value: authCookieValue,
Path: "/"})
log.Printf("user.name",user.Name())
w.Header()["Location"]=[]string{"/chat"}
w.WriteHeader(http.StatusTemporaryRedirect)
Код: Выделить всё
--serveHTTP--
func (t *templateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request){
....
data := map[string]interface{}{
"Host": r.Host,
}
if authCookie, err := r.Cookie("auth"); err == nil {
log.Printf("authCookie",authCookie)
data["UserData"] = objx.MustFromBase64(authCookie.Value)
}
t.templ.Execute(w,r)
Код: Выделить всё
--html--
{{.UserData.name}}:
Ожидаемое поведение
Пожалуйста, помогите нам.
Мне удалось подтвердить, что authCookie и имя пользователя были получены путем установки журнала.
Код: Выделить всё
2023/06/19 09:16:20 authCookie%!(EXTRA *http.Cookie=auth=eyJuYW1lIjoiZ2F0ZSBnYXRlIn0=)
2023/06/19 09:16:26 user.name%!(EXTRA string=gate gate)
2023/06/19 09:16:26 authCookie%!(EXTRA *http.Cookie=auth=eyJuYW1lIjoiZ2F0ZSBnYXRlIn0=)
Подробнее здесь: https://stackoverflow.com/questions/765 ... -user-name
Мобильная версия