Go Cookie 练习

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已经修复

posted @ 2014-08-11 23:30  梦想's技术人员  阅读(316)  评论(0编辑  收藏  举报