From 7da7d7ac645c942df474354e6eeb473a6bef1b63 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 7 Mar 2020 23:56:57 +0800 Subject: [PATCH] =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=A9=E3=82=A4=E3=83=88?= =?UTF-8?q?=E3=81=AE=E6=8C=87=E5=AE=9A=E3=81=AE=E4=BB=95=E6=96=B9=E3=82=92?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content/labs/golang/2020-02-09-how-to-use-nexmo-api.md | 2 +- content/labs/golang/2020-03-07-how-to-use-net-http.md | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/content/labs/golang/2020-02-09-how-to-use-nexmo-api.md b/content/labs/golang/2020-02-09-how-to-use-nexmo-api.md index 9fb5e7c..9c87bea 100644 --- a/content/labs/golang/2020-02-09-how-to-use-nexmo-api.md +++ b/content/labs/golang/2020-02-09-how-to-use-nexmo-api.md @@ -84,4 +84,4 @@ curl -X "POST" "https://rest.nexmo.com/sms/json" \ ``` ## 参考 -- [GolangでAPI使ってSMS送信 - Qiita](https://qiita.com/KokiAsano/items/fffa3c64a1599ffc53ed) \ No newline at end of file +- [GolangでAPI使ってSMS送信 - Qiita](https://qiita.com/KokiAsano/items/fffa3c64a1599ffc53ed) diff --git a/content/labs/golang/2020-03-07-how-to-use-net-http.md b/content/labs/golang/2020-03-07-how-to-use-net-http.md index b92075b..3fb00e5 100644 --- a/content/labs/golang/2020-03-07-how-to-use-net-http.md +++ b/content/labs/golang/2020-03-07-how-to-use-net-http.md @@ -11,7 +11,7 @@ Golang標準ライブラリの`net/http`でREST APIをたたく時に必要と ## 基本のお作法 基本はこんな感じになります: -```go +``` package main import ( @@ -63,7 +63,7 @@ func run(args []string) int { ### ヘッダーを追加したい 以下のように、生成した`HTTP Requst`オブジェクトにヘッダーを追加します: -```go +``` header := http.Header{} header.Set("Content-Length", "10000") header.Add("Content-Type", "application/json") @@ -75,7 +75,7 @@ func run(args []string) int { ### HTTPリクエストボディーを指定したい `http.NewRequest`で`HTTP Request`オブジェクト作成時の3番目の引数に指定します: -```go +``` req, err := http.NewRequest("POST", "ここにエンドポイントのURL", byte.NewBuffer(“foo”)) ``` @@ -84,7 +84,7 @@ func run(args []string) int { ### HTTPリクエストボディーにJSONを指定したい `encoding/json`の`json.Marshal`関数で`JSON`オブジェクトを作成し、`byte`オブジェクトに変換します。以下抜粋です: -```go +``` type RequestBody struct { EventId string `json:"eventId"` Message string `json:"message"` @@ -111,7 +111,7 @@ type RequestBody struct { ### HTTPレスポンスで受け取ったJSONを扱いたい 受け取るレスポンスに対応する構造体を定義して、`json.Unmarsha()`を利用します。[JSON-to-Go: Convert JSON to Go instantly](https://mholt.github.io/json-to-go/)を使うと幸せになれるよ。 -```go +``` type Response struct { Timestamp int64 `json:"timestamp"` Status int `json:"status"`