Session 使用gorilla工具包的golang go端点会话

Session 使用gorilla工具包的golang go端点会话,session,cookies,go,google-cloud-endpoints,gorilla,Session,Cookies,Go,Google Cloud Endpoints,Gorilla,我正在尝试实现会话处理,并将其与go endpoints包相结合 我用来处理会话的包是Gorilla会话(github.com/Gorilla/Sessions),我需要一些帮助 我可以将cookie存储到客户端。。当我调用端点时,可以看到cookie被发送到服务器 问题是,当调用api时,我试图从会话存储中获取会话值,但无法将其扔到cookie中。。端点包会从额外内容或其他内容中剥离http.Request吗 我尝试获取cookie的位置在服务器中。转到 func (s *Server) Se

我正在尝试实现会话处理,并将其与go endpoints包相结合

我用来处理会话的包是Gorilla会话(github.com/Gorilla/Sessions),我需要一些帮助

我可以将cookie存储到客户端。。当我调用端点时,可以看到cookie被发送到服务器

问题是,当调用api时,我试图从会话存储中获取会话值,但无法将其扔到cookie中。。端点包会从额外内容或其他内容中剥离http.Request吗

我尝试获取cookie的位置在服务器中。转到

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request){

     var store = sessions.NewCookieStore([]byte("secret123"));

     session, _ := store.Get(r, "session-name");

     // Get the previously flashes, if any.

     c.Infof("foo value is : %v",r.Cookies());

     if flashes := session.Flashes(); len(flashes) > 0 {

     // Just print the flash values.

     c.Infof("this is the testing post message with cookie from the ServeHTTP    : 
      %v",flashes);
      } 

      else {

      // Set a new flash.

      session.AddFlash("Hello, flash messages world!")

      c.Infof("No flashes found.");

      }

      session.Save(r, w)

      }
我得到的是一个空数组….:(

有人有线索吗


谢谢!!!!!

好吧,我想我把go端点的洞的想法搞错了。。 我对golang很陌生(~年)

我想写一些关于我发现了什么以及如何保护我的api的东西

第一步是按照go endpoints软件包的说明进行操作,说明如何在以下位置注册和发现api:,此软件包是使用Java或Python的最接近google app engine端点的软件包

现在,让我们假设api是在线的和可发现的。 如果我们不使用oauth2来保护api的安全,它们将是可发现的,并为所有用户授予访问权限。我只想在我的公共api中批准这一点,而不是在我的私人api中批准这一点。所以我尝试了gorilla会话,认为它可以解决我的问题

我所做的是尝试通过使用E中间件包装所有通过“/\u ah/api/…”的rout调用来侦听传入的api调用,你能想象吗..我花了一辈子的时间才明白,这条路径是google api保留的,我可以做我正在尝试的事情..最终..我得到了..后来

说到这里,在公开了api的名称和所有应该使用的info.clientId、info.Scopes之后

代码示例-->

现在剩下要做的就是在api函数中创建endpoint.NewContext,并请求适当的作用域获取user.user

}

好的,希望我把一些事情说清楚


不要忽略此错误。请检查它的含义。这样,您的“存储”变量将在每个请求中更新。它需要是全局变量(简单)或在应用程序范围的上下文中定义。好的!我将尝试并发布更新!谢谢!
const (
dummyClientID = "google appengine client id" 
dummyScope1   = "https://www.googleapis.com/auth/plus.login"
dummyScope2   = "https://www.googleapis.com/auth/plus.me"
dummyScope3   = "https://www.googleapis.com/auth/userinfo.email"
dummyScope4   = "https://www.googleapis.com/auth/userinfo.profile"
dummyAudience = "people"
)

var (
emptySlice = []string{}
clientIDs  = []string{dummyClientID}  // this is the clientId of the project
scopes     = []string{dummyScope1,dummyScope2,dummyScope3,dummyScope4} // >this are the req oauth2 scopes that the user hase to approve.
audiences  = []string{dummyAudience} // this is only for android !
)


info := manageApi.MethodByName("GetBusinessById").Info()
info.Name, info.HTTPMethod, info.Path, info.Desc = "GetBusinessById",   >"POST","GetBusinessById", "Get the business if bid is sent."
info.ClientIds, info.Scopes = clientIDs, scopes  
 func (ms *ManageService) GetBusinessById(r *http.Request, req >*JsonInGetBusinessById, resp *JsonOutEditBusiness) error {
 // go get the business by bid.
 DalInst := ManageDataAccessLayer.DALManagerFactory()

 context := endpoints.NewContext(r)

 u,err := >context.CurrentOAuthUser("https://www.googleapis.com/auth/userinfo.email")
 if err != nil {
     return err
 }else {

   var businessObj = DalInst.GetBusinessByBid(context, req.BidStr)


  resp.BidStr = u.Email //just for testing to see if the client is auth and >we can get client Email..

   resp.NameStr = businessObj.NameStr
   resp.AddressStr = businessObj.AddressStr
   resp.DescriptionStr = businessObj.DescriptionStr
   resp.DescriptionTwo = businessObj.DescriptionTwo
   resp.PhoneNumberStr = businessObj.PhoneNumberStr

   return nil