Goやっていきメモ

良い加減進捗なさすぎるので、少しずつやってメモをのこしておこうとおもいます(日本語がおかしい)

型情報の調べ方

import(
    "reflect"
)

..(省略)..

func main(){
    reflect.TypeOf(hoge) // これな
}

参考

Golangで型情報を調べる - Misc Notes

Getリクエス

実行

import (
    "net/http"
    "io/ioutil"
    "fmt"
    "reflect"
)

func main(){
    url := "http://hogehoge.com/api/v1/xxxxx"
    resp, _ := http.Get(url)
    defer resp.Body.Close()

    // htmlをstringで取得
    byteArray, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(byteArray))
}

レスポンスヘッダーを取得

import (
    "net/http"
    "net/http/httputil"
    "fmt"
    "reflect"
)

func main(){
    url := "http://hogehoge.com/api/v1/xxxxx"
    resp, _ := http.Get(url)
    defer resp.Body.Close()

    // レスポンスヘッダー取得
    dump, _ := httputil.DumpResponse(resp, true)
    fmt.Printf("%s", reflect.TypeOfdump) // 型:[]uint8
}

参考

Goでhttpリクエストを送信する方法 - Qiita

structの書き方について

// 階層ぽくかける
type Repos struct {
    Repo struct{
        id string
    }
}

やりのこし

レスポンス(json)データを扱えるようにしたい。この辺を参考にしてみる

stackoverflow.com