Skip to content

Instantly share code, notes, and snippets.

@goofmint

goofmint/index.go

Created Dec 12, 2018
Embed
What would you like to do?
func getTodos(domain string) ([]string, error) {
// 構造体の定義
var todos []string
// HTTPリクエスト
res, err := http.Get(domain)
// エラー処理
if err != nil {
return todos, err
}
// HTTPセッションのクローズ
defer res.Body.Close()
// レスポンスボディの読み込み
body, err := ioutil.ReadAll(res.Body)
// エラー処理
if err != nil {
return todos, err
}
// JSONを文字列の配列に変換
err = json.Unmarshal([]byte(body), &todos)
// 返却
return todos, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.