码迷,mamicode.com
首页 > 其他好文 > 详细

Go Cookie 练习

时间:2014-08-12 00:37:53      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   ar   问题   

package main

import (
    "io"
    "log"
    "net/http"
)

func main() {
    http.HandleFunc("/", Cookie)
    http.HandleFunc("/2", Cookie2)
    http.ListenAndServe(":8080", nil)
}

func Cookie(rw http.ResponseWriter, req *http.Request) {
    c := &http.Cookie{
        Name:  "mycookie",
        Value: "hello world",
        Path:  "/",
        //Domain: "localhost",
    }
    http.SetCookie(rw, c)

}
func Cookie2(rw http.ResponseWriter, req *http.Request) {
    //var c1 []*http.Cookie
    c1, err := req.Cookie("mycookie")
    if err != nil {
        //io.WriteString(rw, err.Error())
        log.Printf(err.Error())
        return
    }

    io.WriteString(rw, c1.Value)

}


主要是测试新版本cookie里有空格的问题,在go1.3已经修复

Go Cookie 练习,布布扣,bubuko.com

Go Cookie 练习

标签:style   blog   http   color   os   io   ar   问题   

原文地址:http://www.cnblogs.com/hellosun/p/3906074.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!