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

鍍金池/ 問答/ GO問答
萢萢糖 回答

先計(jì)算好一批偽隨機(jī)值放在Redis中,調(diào)用來了之后直接從Redis中返回?

清夢 回答

code:

package main

import "fmt"

type Node struct {
    _  int
    id int
}

func main() {
    n := Node{
        id: 1,
    }
    fmt.Println(n)
}

這個(gè)補(bǔ)位字段,它不能讀取,不能賦值,作用就是占個(gè)位置。

話寡 回答

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

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)證碼)誤,請重新輸入","state":400,"submitCode":23207051,"submitToken":"666f51d4-ccef-462a-bb56-55cb97c5231a"}

Process finished with exit code 0
放開她 回答

不建議直接添加到git

你用下glide, 把glide的兩個(gè)配置文件上傳就好了

其它人直接glide install 就可以了

PS: 再推薦個(gè)將來可能成為官方工具的dep (而且現(xiàn)在的Star數(shù)是最多的吧)

尕筱澄 回答

同意Cedrus.

package main

import (
    "fmt"
    "sort"
)

func main() {
    a := []int{2, 1, 3}

    m := make(map[int]int, len(a))
    for i, v := range a {
        m[v] = i
    }

    sort.Ints(a)
    for _, v := range a {
        fmt.Printf("%d's old index is %d\n", v, m[v])
    }
}
生性 回答
import (
"github.com/gin-contrib/cors"
)



gin.Use(cors.New(cors.Config{
        AllowOriginFunc:  func(origin string) bool { return true },
        AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "PATCH"},
        AllowHeaders:     []string{"Origin", "Content-Length", "Content-Type"},
        AllowCredentials: true,
        MaxAge:           12 * time.Hour,
}))

這樣就行了

朕略萌 回答

用cookiejar

func main() {
    client := &http.Client{}
    req, _ := http.NewRequest("GET", "http://192.168.1.89/dvwa", nil)

    jar, _ := cookiejar.New(nil)
    jar.SetCookies(req.URL, []*http.Cookie{
        &http.Cookie{Name: "PHPSESSID", Value: "26c2tkqumv2a2l4o34qtdcbs80", HttpOnly: true},
        &http.Cookie{Name: "security", Value: "impossible", HttpOnly: true},
    })
    client.Jar = jar

    resp, err := client.Do(req)
    if err != nil {
        panic(err.Error())
    }
    b, err := ioutil.ReadAll(resp.Body)
    resp.Body.Close()
    fmt.Printf("%s", b)
}
命于你 回答

因?yàn)槟闶褂檬堑模?/p>

Find(&user)

其中,&user 是一個(gè) stuct ,肯定是一個(gè)完整的結(jié)構(gòu),沒有值的字段會(huì)有默認(rèn)值

如果不想顯示那些的話,可以使用 Scan

type Result struct {
  Name string
  Age  int
}

var result Result
db.Table("users").Select("name, age").Where("name = ?", 3).Scan(&result)

// Raw SQL
db.Raw("SELECT name, age FROM users WHERE name = ?", 3).Scan(&result)

文檔,見這里

柒槿年 回答

可以設(shè)置代理

不將就 回答

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

不討喜 回答

你在使用exec.Cmd時(shí)這樣子填參數(shù):

...go

[]string{"curl",`"http://localhost:8080/api/download?fileidstr=2d905c2162b50d0e12b2213323b34bd4.xlsx&iswindows=0&optuser=test"`,"params"}
so。。。。

夕顏 回答
type SaleLink struct {
    BaseModel
    WareroomID int      `json:"wareroom_id"`
    ProductID  int      `json:"product_id"`
    Quantity   int      `json:"quantity"`
    Product    Product  `json:"product,omitempty"`
    Wareroom   Wareroom `json:"wareroom,omitempty"`
}

加上omitempty,如果你不給struct賦上這兩個(gè)值,json序列化的時(shí)候,就不會(huì)有這兩個(gè)字段

夢囈 回答

那個(gè)是參數(shù)名提示。其實(shí)不太建議關(guān), 因?yàn)間o本來就可以不聲明類型什么的。 連參數(shù)名都不提示看代碼更費(fèi)力。

非要關(guān)閉的話, 按alt + ctrl + shift + s (設(shè)置file->setting) ,然后搜索Show parameter name hints 去掉鉤就行了

伴謊 回答

build 前 set GOARCH、GOOS 兩個(gè)變量,一般是寫個(gè)腳本23333

囍槑 回答

golang的 database/sql 看包名可以知道是跟關(guān)系數(shù)據(jù)庫有關(guān)的。只提供一套抽象接口,go-sql-driver是實(shí)現(xiàn)了這套接口的驅(qū)動(dòng),用的時(shí)候我們還是直接用database/sql就可以了,這叫面向接口編程

mgo是Mongodb的連接程序,跟database/sql接口沒有關(guān)系。

兔囡囡 回答

可以提供一個(gè)思路,一個(gè)可用的服務(wù)列表,一個(gè)一場服務(wù)列表,每次只從可用服務(wù)列表頂部去拿服務(wù),這里可以按照不同的規(guī)則給權(quán)重排序什么的,異常的服務(wù)列表,可以開一個(gè)線程去檢測恢復(fù)情況,如果判斷恢復(fù)了,重新移回正常的服務(wù)列表~

拽很帥 回答

range results 這個(gè)操作只有在關(guān)閉管道之后,才會(huì)繼續(xù)往下執(zhí)行。否則會(huì)一直阻塞。

薔薇花 回答

確實(shí)去查源了,如果這個(gè)源不存在了,你可以用vendor模式build你的包go build -getmode=vendor xxx.go