Skip to content

Instantly share code, notes, and snippets.

@xuanvan229
Created February 9, 2018 04:48
Show Gist options
  • Save xuanvan229/2d935597fdc0aedd39d13f9db21abffb to your computer and use it in GitHub Desktop.
Save xuanvan229/2d935597fdc0aedd39d13f9db21abffb to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.Writer.Header().Set("Content-Type", "application/json")
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
c.JSON(200, gin.H{
"message": "pong",
"id": "10",
})
})
r.POST("/post", func(c *gin.Context) {
fmt.Printf("hello")
})
r.Run() // listen and serve on 0.0.0.0:8080
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment