golang/gin

Go言語のフレームワークのひとつを紹介したいと思います。 公式だと英語なのと検証結果など情報が多いので、使い方とかシンプルに紹介したいと思います。

gin flamework

ginはGo言語で記述されたHTTPのWebフレームワークです。

martiniライク(https://github.com/go-martini/martini)なAPIで、よりパフォーマンスに特化しており、40倍以上速いとのことです。

それはHttpRouterというGo用の軽量でハイパフォーマンスなHttpリクエストルータ(https://github.com/julienschmidt/httprouter)を利用することによる恩恵で速いとのことです。

パフォーマンスを求め、良いプロダクティビティを求めるならGinを愛せるでしょう

API Examples

package main

import "github.com/gin-gonic/gin"

func main() {
    r := gin.Default()
    r.GET("/ping", func(c *gin.Context) {
        c.JSON(200, gin.H{
            "message": "pong",
        })
    })
    r.Run() // listen and server on 0.0.0.0:8080
}

導入の方法

  1. Download->install

$ go get github.com/gin-gonic/gin

  1. コードにインポートする

import "github.com/gin-gonic/gin"

  1. (オプション) net/httpをインポートすることで、http.StatusOKといった、ステータスコード を利用できる。

import "net/http"


参考(https://github.com/gin-gonic/gin)

今回はここまで!! また、いろんなこと紹介していこうと思います。