草庐IT

set_cookie

全部标签

go - 如何读取cookie?

我通过javascript设置了一个cookie,例如:setCookie("appointment",JSON.stringify({appointmentDate:selectedDay.date,appointmentStartMn:appointment.mnRange[0],appointmentId:appointment.id||0,appointmentUserId:appointment.user.id||0}));设置cookie后,我想将用户重定向到预订页面:window.location.href="https://localhost:8080/booking/

go - 设置 cookie 不被检测

我在尝试检索已设置的cookie时遇到问题,如果未设置,我想更新它然后检索它。首先,我有一个设置cookie的函数:funcIndexHandler(whttp.ResponseWriter,r*http.Request){...ck:=http.Cookie{Name:"id",Value:5,MaxAge:60,}}然后在另一个函数中我检查该cookie是否存在,如果它(抛出错误)然后我重新创建它funcCheckUpdateCookie(whttp.ResponseWriter,r*http.Request){val,err:=r.Cookie("id")iferr!=nil{c

go - -bash : set: -g: invalid option when I setting GOPATH

当我设置GOPATH时,使用:set-gxGOPATH/usr/local/Cellar/go/1.8.1我遇到了这个问题:-bash:set:-g:invalidoptionset:usage:set[--abefhkmnptuvxBCHP][-ooption][arg...] 最佳答案 bash命令set不支持g选项。此外,此命令不用于一起设置环境变量-您的代码段可能适用于不同的shell(fishshell?)。在bash中,按照建议使用export:exportGOPATH/usr/local/Cellar/go/1.8.1

google-app-engine - CookieJar 不捕获传入的 cookie

我正在尝试让Go在网页上为我提交一个表单来模拟登录。从那里我尝试使用cookie来保持持久session,以便再次调用子页面。我能够毫无问题地成功登录,我只是在捕获返回服务器设置的cookie时遇到了问题。我想知道是不是因为他们的登录脚本做了几次重定向?(我得到一个输出)。为什么我没有捕捉到返回的cookie有什么想法吗?这是我使用的代码:import("crypto/tls""fmt""io/ioutil""net/http""net/url""strings""sync")typeJarstruct{lksync.Mutexcookiesmap[string][]*http.Coo

去构建 : “Cannot find package” (even though GOPATH is set)

我的问题与this非常相似,不同的是我有最佳答案指出的目录层次结构,但我仍然遇到同样的问题,为什么?$echo$GOROOT/usr/local/go$echo$GOPATH/home/mitchell/go$cat/home/mitchell/go/src/main.gopackagemainimport"comment/create"funcmain(){}$cat/home/mitchell/go/src/comment/create/***.go(bunchofgofiles)packagecreate$gobuildmain.gomain.go:3:8:import"comm

mongodb - 如何将 BSON _Id 分配给 cookie(Go,Mongodb)

我正在尝试创建一个gocookie。我想从Mongodb分配Id以存储在Cookie中。但是在编译时出现如下错误:-“结构文字中的未知http.Cookie字段‘Id’”以下是我的代码:-getUser:=user.CheckDB()expiration:=time.Now().Add(365*24*time.Hour)//TheErrorisCausedbytheNextLinecookie:=http.Cookie{Id:getUser[0].Id,Name:getUser[0].Email,Value:getUser[0].Password,Expires:expiration}

Golang 中的正则表达式 : How to set character that makes the string not match?

我对正则表达式一窍不通(抱歉)。我试图制作一种非常简单的标记语言,匹配粗体和斜体,然后将它们转换为HTML。这是我使用的粗体示例:varbold=regexp.MustCompile("\\*([^\\*]+)\\*")它匹配两个星号之间的所有内容。现在,我希望它匹配*test*但不匹配\*test*。由于我对正则表达式知之甚少,但我正在尝试进行此实验,因此我想知道这样做的方法是什么。我到处搜索,但找不到完成这项工作的方法。 最佳答案 已更新Go不支持回顾。因此,解决方法可以是:(?:\A|(?:[^\\]+|\A)(\\{2})+

cookies - 使用 Go 客户端接收和发送 cookie?

我希望我的Go应用程序通过网站进行身份验证,然后使用收到的cookie访问安全位置。以下curl示例准确说明了我正在尝试做的事情:通过x-www-form-urlencoded对网站进行身份验证并保存cookie。数据自动进行urlencoded:curl'https://www.example.com/login'\--cookie-jarcookies.txt\--header'Content-Type:application/x-www-form-urlencoded'\--data'user=USERNAME&pass=PASS'现在身份验证cookie保存在cookies.t

rest - 在 API Rest golang 中发送 cookie

我在Golang工作,我正在构建一个API-Rest并且想知道,我可以使用restful设置cookies吗?我正在构建与用户身份验证相关的方法:登录、注销、注册等,现在我正在尝试使用生成的uuid在响应中设置cookie。我有这个:funcLogin(whttp.ResponseWriter,req*http.Request,pshttprouter.Params){...somecode....c:=&http.Cookie{Name:"session",Value:uuid.NewV4().String(),}http.SetCookie(w,c)w.Header().Set("

cookies - 用户 cookie 验证随机失败

我使用两个结构来保存用户信息//SecureDeviceholdsauser'sdevice'sinfostypeSecureDevicestruct{Namestring//DefinedbytheuserDeviceIPstringTokenstruct{TokenstringStartingDatetime.Time//Thetokenissupposedtolastonlyaweekbeforebecominginvalid}}//GlobalUserisastructdefiningalluser'sinfosregisteredinsidetheservertypeGlob