1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Go】GitHub Markdown APIを叩いてみる

Last updated at Posted at 2019-09-14

はじめに

GitHub Markdown APIの使い方に関しては、以下の記事を参照。

サンプルコード

package main

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

func main() {
	apiURL := "https://api.github.com/markdown/raw"
	markdown := "# Hello World"

	// リクエストを生成
	req, err := http.NewRequest("POST", apiURL, strings.NewReader(markdown))
	if err != nil {
		panic(err)
	}
	req.Header.Add("Content-Type", "text/plain")

	// POSTリクエストを送信
	client := &http.Client{}
	res, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	// レスポンスを読み取り
	bytes, err := ioutil.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}

	fmt.Println(string(bytes))
	// => <h1>
	//    <a id="user-content-hello-world" class="anchor" href="#hello-world" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Hello World</h1>
}

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?