草庐IT

asp.net-session

全部标签

go - net/http 呈现根路由,即使我转到不存在的路由

我有这些路线:http.HandleFunc("/",func(whttp.ResponseWriter,r*http.Request){renderAndExecuteTemplate(w,r,"page/index.tmpl",nil)})http.HandleFunc("/route1",func(whttp.ResponseWriter,r*http.Request){renderAndExecuteTemplate(w,r,"page/route1.tmpl",nil)})http.HandleFunc("/route2",func(whttp.ResponseWriter,

html - 通过 session 变量在 Golang layout.tpl 中有条件地呈现 HTML

我使用Gorillasession(通过negroni-sessions)将我的用户session存储在cookie中。我还使用github.com/unrolled/render进行HTML模板渲染:ma​​in.go:packagemainimport(..."github.com/codegangsta/negroni""github.com/goincremental/negroni-sessions""github.com/goincremental/negroni-sessions/cookiestore""github.com/julienschmidt/httprout

session - 如何在 golang 中保存 session

我正在尝试使用gorillasession和securecookie在我的golang后端中保存已登录的用户ID。这是我的打包session:packagesessionimport("fmt""net/http""github.com/gorilla/securecookie""github.com/gorilla/sessions")varstore=sessions.NewCookieStore(securecookie.GenerateRandomKey(32))//GetSessionLoggedIDreturnsloggedIDfuncGetSessionLoggedID(

unit-testing - 如何在不创建实际网络连接的情况下测试依赖于 net.Conn 的代码?

如果我有适用于net.Conn的代码,我如何在不实际创建与本地主机的网络连接的情况下为其编写测试?我在网上没有看到这个问题的解决方案;人们似乎要么忽略它(不进行测试),要么编写无法并行运行的测试(即使用实际的网络连接,这会耗尽端口),要么使用io.Pipe。不过,net.Conn定义了SetReadDeadline、SetWriteDeadline;而io.Pipe没有。net.Pipe也没有,尽管表面上声称要实现该接口(interface),但它只是通过以下方式实现:func(p*pipe)SetDeadline(ttime.Time)error{return&OpError{Op:

url - 使用 net/url 内置包解析带有矩阵参数的 URL

似乎URL不支持matrixparameters//Fromnet/urltypeURLstruct{SchemestringOpaquestring//encodedopaquedataUser*Userinfo//usernameandpasswordinformationHoststring//hostorhost:portPathstringRawQuerystring//encodedqueryvalues,without'?'Fragmentstring//fragmentforreferences,without'#'}为什么?如何从URL中提取矩阵参数?我什么时候应该使

当用户在 3 分钟内未向 Go Web 服务器发送数据时,Go session 超时

我将使用Go构建Web服务器。现在我想将sessionID返回给用户使用用户名和密码登录。而且我认为我可以接受登录程序。用户每次要发布数据时都会使用sessionID。但是,用户登录后,如果用户在3分钟内没有发送数据,我会尝试销毁session,使sessionid不再有效。那么,当用户在3分钟内未发布数据时,如何使session过期。(我将使用beego,beego有session超时,但它确实提到它会超时取决于发布数据间隔)谢谢。 最佳答案 您可以设置上次使用session的时间。假设cookie存储创建为Store:=sess

tcp - Golang 写 net.Dial 响应给浏览器

我正在玩网络包,我想做一个简单的代理。首先我在本地主机上创建一个监听器,然后我调用远程地址remote,err:=net.Dial("tcp","google.com:80")iferr!=nil{log.Fatal(err)}deferremote.Close()fmt.Fprint(remote,"GET/HTTP/1.0\r\n\r\n")如何通过管道将响应传递给浏览器?还是我需要使用默认网络服务器并复制响应正文?很想用netpackage什么的试试谢谢 最佳答案 要从远程复制连接,使用2个带有io.Copy的goroutin

node.js - 通过 POST 登录不会产生有效 session

我目前正在尝试将一个小型应用程序从nodejs转换为golang(因此有两个标签),但我在这样做时遇到了一些麻烦。本质上,这是一个非常简单的httpPOST登录,我似乎无法理解。背景是我的大学提供日历导出功能,我想提供这个日历作为可以添加到GoogleCal的提要。现在的问题是,我已经在node中完成了所有工作,但我真的很想也能在go中实现它。Node代码的重要部分是varquery=url.parse(req.url,true).query;vardata={u:query.user,//Usernamep:query.password,//Password};needle.post

go - 捕获传递给 http.Server.Serve 的 net.Listener

我想通过执行正常关闭和我将在我的HTTP服务中共享的其他一些小工具来扩展http.Server功能。目前我的代码或多或少说:typeMyServerstruct{server*http.Server//...}func(s*MyServer)ListenAndServe(){//Createlistenerandpasstos.server.Serve()}这很有效很好,但是需要手动公开http.Server的所有必要方法和变量。包装大多数方法不会是一个大问题,但我无法找到一种明智的方法来公开对http.Server.ListenAndServeTLS的访问,而无需实际从thesour

session - 为什么这个 gorilla session 代码不起作用?

我是一个golang菜鸟,所以我正在通过为基于gorilla的网络应用程序设置种子项目来制作我的第一个玩具应用程序。一切顺利,但session代码无法正常工作,hereisthefullcode,这里只是相关的片段:funcgetMyCounter(whttp.ResponseWriter,r*http.Request){session,_:=sessionStore.Get(r,counterSession)ifsession.IsNew{session.Values[myCounter]=0}val:=session.Values[myCounter].(int)log.Print