在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/ GO問(wèn)答
朽鹿 回答

stack.Push沒(méi)這個(gè)函數(shù)啊。PushStack這個(gè)結(jié)構(gòu)體的一個(gè)方法。你應(yīng)該寫(xiě)成s.Push。

話寡 回答

https://segmentfault.com/q/10...
——————————————————————————————
第一次回復(fù)時(shí)沒(méi)看你的內(nèi)容,只回應(yīng)了標(biāo)題所以貼了個(gè)網(wǎng)址
下面正式回復(fù)
你的問(wèn)題不是cookies的問(wèn)題,我根據(jù)那篇文章改了下運(yùn)行成功了,你自己對(duì)照下

package main

import (
    "fmt"
    "io"
    "io/ioutil"
    "log"
    "net/http"
    "net/http/cookiejar"
    "net/url"
    "regexp"
    "strings"
)

var cookies_lagou []*http.Cookie

const (
    login_url_lagou string = "https://passport.lagou.com/login/login.html"

    post_login_info_url_lagou string = "https://passport.lagou.com/login/login.json"

    username_lagou string = "13330295142"
    password_lagou string = "4525674692ac06e619cdb3f1b4b65b08"
)

func getToken(contents io.Reader) (string, string) {

    data, _ := ioutil.ReadAll(contents)

    regCode := regexp.MustCompile(`X_Anti_Forge_Code = '(.*?)';`)
    if regCode == nil {
        log.Fatal("解析Code出錯(cuò)...")
    }

    //提取關(guān)鍵信息
    code := regCode.FindAllStringSubmatch(string(data), -1)[0][1]

    regToken := regexp.MustCompile(`X_Anti_Forge_Token = '(.*?)';`)
    if regToken == nil {
        fmt.Println("MustCompile err")
    }

    //提取關(guān)鍵信息
    token := regToken.FindAllStringSubmatch(string(data), -1)[0][1]

    return token, code
}

func login_lagou() {
    //獲取登陸界面的cookie
    jar, _ := cookiejar.New(nil)
    client := &http.Client{
        Jar: jar,
    }
    req, _ := http.NewRequest("GET", login_url_lagou, nil)
    res, _ := client.Do(req)
    // for k, v := range res.Cookies() {
    //     fmt.Printf("%v=%v\n", k, v)
    // }
    token, code := getToken(res.Body)
    fmt.Println(token, code)
    //post數(shù)據(jù)
    postValues := url.Values{}
    postValues.Add("isValidate", "true")
    postValues.Add("username", username_lagou)
    postValues.Add("password", password_lagou)
    postValues.Add("request_form_verifyCode", "")
    postValues.Add("submit", "")
    // body := ioutil.NopCloser(strings.NewReader(postValues.Encode())) //把form數(shù)據(jù)編下碼
    // requ, _ := http.NewRequest("POST", post_login_info_url_lagou, nil)

    requ, _ := http.NewRequest("POST", post_login_info_url_lagou, strings.NewReader(postValues.Encode()))
    requ.Header.Set("Referer", "https://passport.lagou.com/login/login.html")
    requ.Header.Set("X-Requested-With", "XMLHttpRequest")
    requ.Header.Set("X-Anit-Forge-Token", token)
    requ.Header.Set("X-Anit-Forge-Code", code)
    requ.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:51.0) Gecko/20100101 Firefox/51.0")
    requ.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")

    //for _, v := range res.Cookies() {
    //    requ.AddCookie(v)
    //}

    res, _ = client.Do(requ)
    //cookies_lagou = res.Cookies()
    data, _ := ioutil.ReadAll(res.Body)
    res.Body.Close()
    fmt.Println(string(data))
}

func main() {
    login_lagou()
}

運(yùn)行結(jié)果

15f131a3-74b0-4914-bd6e-2672f36675e1 28747049
{"content":{"rows":[]},"message":"該帳號(hào)不存在或密碼(驗(yàn)證碼)誤,請(qǐng)重新輸入","state":400,"submitCode":23207051,"submitToken":"666f51d4-ccef-462a-bb56-55cb97c5231a"}

Process finished with exit code 0
鹿惑 回答

可以看下這個(gè)源碼 http://bazaar.launchpad.net/+...:/session.go#L195

Dial 方法調(diào)用 DialWithTimeout 方法,然后又調(diào)用 DialWithInfo 方法,所以是有連接池的。 只是Dita方法為你做了方便方便的wrapper。

然后用 session.New() 或者 session.Copy() 獲取一個(gè)Diat返回的鏈接

黑與白 回答

已經(jīng)解決! 吐槽一下:審核真慢
嵌套結(jié)構(gòu)體:

type SongSingle struct {
    Codes int `json:"code"`
    Date  struct {
        Song struct { // 音樂(lè)
            Count    int `json:"count"`
            Itemlist []struct {
                Albummid string `json:"albummid"`
                Docid    string `json:"docid"`
                Id       string `json:"id"`
                Mid      string `json:"mid"`
                Name     string `json:"name"`
                Singer   string `json:"singer"`
            } `json:"itemlist"`
            Name  string `json:"name"`
            Order int    `json:"order"`
            Type  int    `json:"type"`
        } `json:"song"`
        Album struct { // 專(zhuān)輯
            Count    int `json:"count"`
            Itemlist []struct {
                docid  string `json:"docid"`
                Id     string `json:"id"`
                Mid    string `json:"mid"`
                Name   string `json:"name"`
                Pic    string `json:"pic"`
                Singer string `json:"singer"`
            } `json:"itemlist"`
            Name  string `json:"name"`
            Order int    `json:"order"`
            Type  int    `json:"type"`
        } `json:"album"`
        Singer struct { // 歌手
            Count    int `json:"count"`
            Itemlist []struct {
                docid  string `json:"docid"`
                Id     string `json:"id"`
                Mid    string `json:"mid"`
                Name   string `json:"name"`
                Pic    string `json:"pic"`
                Singer string `json:"singer"`
            } `json:"itemlist"`
            Name  string `json:"name"`
            Order int    `json:"order"`
            Type  int    `json:"type"`
        } `json:"singer"`
        Mv struct { // mv
            Count    int `json:"count"`
            Itemlist []struct {
                docid  string `json:"docid"`
                Id     string `json:"id"`
                Mid    string `json:"mid"`
                Name   string `json:"name"`
                Singer string `json:"singer"`
                Vid    string `json:"vid"`
            } `json:"itemlist"`
            Name  string `json:"name"`
            Order int    `json:"order"`
            Type  int    `json:"type"`
        } `json:"mv"`
        Name  string `json:"name"`
        Order int    `json:"order"`
        Type  int    `json:"type"`
    } `json:"data"`
    Subcode int `json:"subcode"`
}

遍歷結(jié)構(gòu)體取值:

Sbody := string(body)
var arrayData SongSingle
if err := json.Unmarshal([]byte(Sbody), &arrayData); err == nil {

// fmt.Println("碼:", arrayData.Subcode)
// fmt.Println("子碼:", arrayData.Subcode)
for _, Songitem := range arrayData.Date.Song.Itemlist {
    fmt.Println("專(zhuān)輯ID:", Songitem.Albummid)
    fmt.Println("  ID  :", Songitem.Id)
    fmt.Println("歌曲ID:", Songitem.Mid)
    fmt.Println("歌  名:", Songitem.Name)
    fmt.Println("歌  手:", Songitem.Singer)
    fmt.Println("\n")
}

} else {

fmt.Println(err)

}

薔薇花 回答

decimal帶兩位小數(shù),更精準(zhǔn)一些

祈歡 回答

你的 HASH 用法搞錯(cuò)了,請(qǐng)參考下面的代碼

/*
數(shù)字簽名示例代碼。

@author: 李毅
*/
package main

import (
    "bytes"
    "crypto"
    "crypto/rand"
    "crypto/rsa"
    "crypto/sha512"
    "log"
)

type Demo struct {
    PriKey *rsa.PrivateKey
}

func (demo *Demo) LoadPrivateKey() {
    privateKey, err := rsa.GenerateKey(rand.Reader, 1024)
    if err != nil {
        log.Fatal(err)
    }
    demo.PriKey = privateKey
}

// 返回 digest, signature
func (demo *Demo) Sign(message string) ([]byte, []byte) {
    messageBytes := bytes.NewBufferString(message)
    hash := sha512.New()
    hash.Write(messageBytes.Bytes())
    digest := hash.Sum(nil)

    signature, err := rsa.SignPKCS1v15(rand.Reader, demo.PriKey, crypto.SHA512, digest)
    if err != nil {
        log.Fatalf("rsa.SignPKCS1v15 error: %v\n", err)
    }
    return digest, signature
}

func (demo *Demo) Check(digest, signature []byte) bool {
    err := rsa.VerifyPKCS1v15(&demo.PriKey.PublicKey, crypto.SHA512, digest, signature)
    if err != nil {
        log.Printf("rsa.VerifyPKCS1v15 error: %V\n", err)
        return false
    }
    return true
}

func main() {
    demo := &Demo{}
    demo.LoadPrivateKey()
    digest, signature := demo.Sign("hi")
    if demo.Check(digest, signature) {
        log.Printf("signature is good")
    } else {
        log.Printf("signature is bad")
    }
}
厭惡我 回答

golang 的時(shí)間格式確實(shí)困擾新人,需要一點(diǎn)適應(yīng)時(shí)間。

這里只需要調(diào)用 time.Parse(),然后讀取 time.Unix() 結(jié)果便可。
時(shí)間格式應(yīng)該是 "2006-01-02T15:04:05.999-0700",請(qǐng)參考下面的示例

package main

import (
    "fmt"
    "testing"
    "time"
)

func TestParseTime(t *testing.T) {
    str := "2018-06-07T20:14:03.368+0800"

    format := "2006-01-02T15:04:05.999-0700"
    tm, err := time.Parse(format, str)
    if err != nil {
        t.Fatal(err)
    }
    _, zoffset := tm.Zone()
    if tm.Year() != 2018 || tm.Month() != 6 || tm.Day() != 7 || tm.Hour() != 20 || tm.Minute() != 14 || tm.Second() != 3 || zoffset != 8*3600 {
        t.Fatal(tm)
    }
    fmt.Println(tm.Unix())
}

要將 a 轉(zhuǎn)換成接口 I,可以這樣 a.(I)。

redis 返回值類(lèi)型與 go 類(lèi)型關(guān)系

Redis type              Go type
error                   redis.Error
integer                 int64
simple string           string
bulk string             []byte or nil if value not present.
array                   []interface{} or nil if value not present.

參考代碼

package main

import (
    "fmt"

    "github.com/gomodule/redigo/redis"
)

func main() {
    c, _ := redis.Dial("tcp", ":6379")
    var script = redis.NewScript(2, `
        local rst={};
        for i,v in pairs(KEYS) do
          rst[i]=redis.call('get', v)
        end;
        return rst`)
    reply, _ := script.Do(c, "key1", "key2")

    array := reply.([]interface{})
    for i, item := range array {
        if item != nil {
            // 假設(shè) key1,key2 均返回 bulk string
            fmt.Println(i, string(item.([]byte)))
        }
    }
}
安于心 回答

那用交叉編譯啊,配置 OS 和 ARCH 這 2 個(gè)環(huán)境變量

風(fēng)畔 回答

已經(jīng)解決,解決方法,使用和linux本機(jī)相同的文件系統(tǒng),不能使用,win共享的文件夾,掛載到linux

不將就 回答

從語(yǔ)法角度上講:傳值只是改變的副本,得傳指針才能修改。

薄荷綠 回答

select a.*,a.salary-b.salary as diff from salaries a left join salaries b on a.from_date=b.to_date where a.emp_no=10001 and b.emp_no=10001 order by from_date;


**行轉(zhuǎn)列很容易,自己百度下就行,但我覺(jué)得意義不大,你大可以在頁(yè)面展現(xiàn)的時(shí)候?qū)崿F(xiàn),而不是糾結(jié)于sql語(yǔ)句。**
墨沫 回答

當(dāng)然是寫(xiě)一個(gè)新的結(jié)構(gòu)體啊,protoc生成的文件是不建議改的

女流氓 回答

。。。參見(jiàn)鏈接:https://blog.lab99.org/post/d...

兔囡囡 回答

Scan, Fscan, Sscan treat newlines in the input as spaces.

fmt

這就是他工作的機(jī)制,了解了原理,要繼續(xù)采用這個(gè)方式的話,可以先格式化一下,把換行替換成空格,在交給Fscanf

離夢(mèng) 回答
    type Serverslice2 struct {
        Total int `json:"total"`
        Count int `json:"count"`
        Start int `json:"start"`
    }

    var s Serverslice2
    str := `{"count": 10,"start": 0,"total": 1626}`
    err := json.Unmarshal([]byte(str), &s)
    fmt.Println(s, err)
悶騷型 回答

首先需要關(guān)閉其中一個(gè),你程序的外部要能找到你所需要關(guān)閉的協(xié)程,這個(gè)時(shí)候就需要注入一下標(biāo)識(shí)什么的,比如用map存儲(chǔ)這些標(biāo)識(shí),每一個(gè)協(xié)程注入一個(gè)channel,然后使用select在協(xié)程內(nèi)部運(yùn)行,判斷channel是否close掉,如果close掉,則退出協(xié)程~

朕略傻 回答

正則版的來(lái)了:

"李某平".replace(/^(.+).(.)$/, "$1*$2");
"慕容某霜".replace(/^(.+).(.)$/, "$1*$2");
假灑脫 回答

依賴(lài),net依賴(lài)于net/http