removed all the footers; formated all the files

This commit is contained in:
Oling Cat
2012-11-01 16:10:44 +08:00
parent 77b8677ae0
commit c059171e15
73 changed files with 4576 additions and 4782 deletions

51
6.1.md
View File

@@ -29,27 +29,27 @@ cookie是有时间限制的根据生命期不同分成两种会话cookie
### Go设置cookie
Go语言中通过net/http包中的SetCookie来设置
http.SetCookie(w ResponseWriter, cookie *Cookie)
w表示需要写入的responsecookie是一个struct让我们来看一下cookie对象是怎么样的
type Cookie struct {
Name string
Value string
Path string
Domain string
Expires time.Time
RawExpires string
Name string
Value string
Path string
Domain string
Expires time.Time
RawExpires string
// MaxAge=0 means no 'Max-Age' attribute specified.
// MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'
// MaxAge>0 means Max-Age attribute present and given in seconds
MaxAge int
Secure bool
HttpOnly bool
Raw string
Unparsed []string // Raw text of unparsed attribute-value pairs
// MaxAge=0 means no 'Max-Age' attribute specified.
// MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'
// MaxAge>0 means Max-Age attribute present and given in seconds
MaxAge int
Secure bool
HttpOnly bool
Raw string
Unparsed []string // Raw text of unparsed attribute-value pairs
}
我们来看一个例子如何设置cookie
@@ -57,21 +57,21 @@ w表示需要写入的responsecookie是一个struct让我们来看一下co
expiration := *time.LocalTime()
expiration.Year += 1
cookie := http.Cookie{Name: "username", Value: "astaxie", Expires: expiration}
http.SetCookie(w, &cookie)
http.SetCookie(w, &cookie)
  
### Go读取cookie
上面的例子演示了如何设置cookie数据我们这里来演示一下如何读取cookie
cookie, _ := r.Cookie("username")
fmt.Fprint(w, cookie)
fmt.Fprint(w, cookie)
还有另外一种读取方式
for _, cookie := range r.Cookies() {
fmt.Fprint(w, cookie.Name)
}
可以看到通过request获取cookie非常方便。
## session
@@ -93,10 +93,7 @@ session机制本身并不复杂然而其实现和配置上的灵活性却使
通过上面的一些简单介绍我们了解了cookie和session的一些基础知识知道他们之间的联系和区别做web开发之前有必要将一些必要知识了解清楚才不会在用到时捉襟见肘或是在调bug时候如无头苍蝇乱转。接下来的几小节我们将详细介绍session相关的知识。
## links
* [目录](<preface.md>)
* 上一节: [session和数据存储](<6.md>)
* 下一节: [Go如何使用session](<6.2.md>)
## LastModified
* $Id$
## links
* [目录](<preface.md>)
* 上一节: [session和数据存储](<6.md>)
* 下一节: [Go如何使用session](<6.2.md>)