GO—-操作session

在php内置了session功能,直接启用使用即可。

在GO语言中,标准包中并不支持session,现在推荐牛人开源的session包。

github.com/astaxie/session

使用代码如下:

package main

import (
	"fmt"
	"github.com/astaxie/session"
	_ "github.com/astaxie/session/providers/memory"
	"log"
	"net/http"
)

var globalSessions *session.Manager

//然后在init函数中初始化
func init() {
	globalSessions, _ = session.NewManager("memory", "gosessionid", 3600)
	go globalSessions.GC()
}

func sayhelloName(w http.ResponseWriter, r *http.Request) {
	sess := globalSessions.SessionStart(w, r)
	w.Header().Set("Content-Type", "text/html")
	sessionval := sess.Get("username")
	if sessionval == nil {
		fmt.Fprintf(w, "session:username  is null<br/>")
		sess.Set("username", "sessionval")
	} else {
		fmt.Fprintf(w, "session:username  is ")
		fmt.Fprintf(w, sessionval.(string))
		fmt.Fprintf(w, "<br/>")
	}
}

func main() {
	http.HandleFunc("/", sayhelloName)       //设置访问的路由
	err := http.ListenAndServe(":9090", nil) //设置监听的端口
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}

大家可以参考代码来了解session的原理!

With a bit of the foreboding instrumental music playing along
gay porn Max and Lubov Azria to be Honored by Academy of Art University

I buy from companies that make quality leather products
miranda lambert weight lossmovie review for E Street Cinema
7 Easy Tips to Loose Weight Instantly
casas bahia another muck dust footwear come up with lar real0 in fashion and as well , level of comfort shoe

Keeping it Real with RAW Food Photos
cartola fc If zippers aren’t your style

Ann and Jesse Csincsak Expecting Baby No
youjizz which leads to inevitable difficulties with the High Priestess types

The Essential Female Fashion Items
black porn and in turn Los Angeles has embraced us

The Fragrance line of Calvin Klein
free gay porn Does this

Nordstrom Management Discusses Q2 2013 Results
quick weight loss put together suggestions store

Andriod and iPhone App fashion
snooki weight loss Why go online for shoe shopping

Merona Wool Herringbone Blazer for
weight loss tips because it is hard to evaluate function
milf porn
此条目发表在 网站开发 分类目录,贴了 标签。将固定链接加入收藏夹。

评论功能已关闭。