golang 1.5 坑一枚

Kiyor | Created: 08-25-15 07:24:48, Last Update: 08-28-15 11:18:50



golang 1.5 在常用的net/http包里新增了Request.Cancel, 导致原来可以直接把request给json化的方式出现了json: unsupported type: <-chan struct {}. 在debug的时候看不到请求了. 解决方式也十分坑…

type Req struct {
    Method           string
    URL              *url.URL
    Proto            string
    ProtoMajor       int
    ProtoMinor       int
    Header           http.Header
    ContentLength    int64
    TransferEncoding []string
    Close            bool
    Host             string
    Form             url.Values
    PostForm         url.Values
    MultipartForm    *multipart.Form
    Trailer          http.Header
    RemoteAddr       string
    RequestURI       string
    TLS              *tls.ConnectionState
}
func CopyReq(req *http.Request) *Req {
    return &Req{
        Method:           req.Method,
        URL:              req.URL,
        Proto:            req.Proto,
        ProtoMajor:       req.ProtoMajor,
        ProtoMinor:       req.ProtoMinor,
        Header:           req.Header,
        ContentLength:    req.ContentLength,
        TransferEncoding: req.TransferEncoding,
        Close:            req.Close,
        Host:             req.Host,
        Form:             req.Form,
        PostForm:         req.PostForm,
        MultipartForm:    req.MultipartForm,
        Trailer:          req.Trailer,
        RemoteAddr:       req.RemoteAddr,
        RequestURI:       req.RequestURI,
        TLS:              req.TLS,
    }
}


Category: none

Tags: golang