1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| package main
import ( "net/http"
"github.com/gin-gonic/gin" )
func getting(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"method": "GET"}) }
type User struct { ID uint Name string }
func posting(c *gin.Context) { c.JSON(http.StatusOK, User{ ID: 1, Name: "Tom", }) }
func putting(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"method": "PUT"}) }
func deleting(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"method": "DELETE"}) }
func patching(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"method": "PATCH"}) }
func head(c *gin.Context) { c.Status(http.StatusOK) }
func options(c *gin.Context) { c.Status(http.StatusOK) }
func main() { router := gin.Default()
router.GET("/someGet", getting) router.POST("/somePost", posting) router.PUT("/somePut", putting) router.DELETE("/someDelete", deleting) router.PATCH("/somePatch", patching) router.HEAD("/someHead", head) router.OPTIONS("/someOptions", options)
router.Run() }
|