如何在Golang中制作Curl Store Cookie?

I want send a post/get request and can store cookies in a file near on Program.

Sample Php Code:

$___path="";
function send($url,$fields=array(),$reffer=false,$get=false)
{
    global $___path;
    $cookie_file_path = $___path."cookie.txt";//this file of cookies.
    $agent            = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1";
    $ch = curl_init(); 
    $headers[] = "Accept: */*";
    $headers[] = "Connection: Keep-Alive";
    curl_setopt($ch, CURLOPT_HTTPHEADER,  $headers);
    curl_setopt($ch, CURLOPT_HEADER,  0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);         
    if($reffer == false){}
    else
    {
        curl_setopt($ch,CURLOPT_REFERER,$reffer);
    }
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); 
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); 
    curl_setopt($ch, CURLOPT_URL, $url);
    if($get)
    {
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); 
    }
    else
    {
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POST, 1);
        if(count($fields) >= 1)
        {
            $POSTFIELDS = http_build_query($fields);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $POSTFIELDS);
        }
    }
    $result = curl_exec($ch); 
    return $result;
}

may help me to work with cookie jar store?

this not have a sample : https://github.com/juju/persistent-cookiejar

may a person write a sample about https://golang.org/pkg/net/http/#CookieJar ?

You don't need to save cookies to a file, just keep your go process running. If you really wanted to, you would do something like:

import "net/http/cookiejar"
import "net/http"
import "encoding/json"
import "io/ioutil"

cookies := make(map[string][]*http.Cookie)
jar, _ := cookiejar.New(nil)
client := http.Client{Jar: jar}
r, _ := client.Get(/* do whatever */)
siteCookies := jar.Cookies(r.Request.URL)
cookies[r.Request.URL.String()] = siteCookies
data, _ := json.Marshal(cookies)
ioutil.WriteFile("/path/to/cookies.txt", data, 0644)

And then when you start, you would read that file, for each key call url.Parse, and then use that to call jar.SetCookies.

https://play.golang.org/p/gQ_n6rPsdl