// gin.H は map[string]interface{} へのショートカットです。
router.GET("/someJSON", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK})
router.GET("/moreJSON", func(c *gin.Context) {
Name string `json:"user"`
// msg.Name は JSON 内で "user" となることに注意してください
// 右記が出力されます : {"user": "Lena", "Message": "hey", "Number": 123}
c.JSON(http.StatusOK, msg)
router.GET("/someXML", func(c *gin.Context) {
c.XML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK})
router.GET("/someYAML", func(c *gin.Context) {
c.YAML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK})
router.GET("/someProtoBuf", func(c *gin.Context) {
reps := []int64{int64(1), int64(2)}
// protobuf の定義は testdata/protoexample にかかれています。
data := &protoexample.Test{
// データはレスポンス時にバイナリデータになることに注意してください。
// protoexample.Test の protobuf でシリアライズされたデータが出力されます。
c.ProtoBuf(http.StatusOK, data)
// 0.0.0.0:8080 でサーバーを立てます。