티스토리 뷰

module helloGin

go 1.12

require (
	cloud.google.com/go v0.43.0 // indirect
	github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
	github.com/denisenkom/go-mssqldb v0.0.0-20190720212816-23f0cad53f5c // indirect
	github.com/gin-gonic/contrib v0.0.0-20190526021735-7fb7810ed2a0
	github.com/gin-gonic/gin v1.4.0
	github.com/gorilla/sessions v1.2.0 // indirect
	github.com/jinzhu/gorm v1.9.10
	github.com/lib/pq v1.2.0 // indirect
	github.com/mattn/go-sqlite3 v1.11.0 // indirect
	golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect
	golang.org/x/exp v0.0.0-20190718202018-cfdd5522f6f6 // indirect
	golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9 // indirect
	golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028 // indirect
	golang.org/x/net v0.0.0-20190628185345-da137c7871d7 // indirect
	golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 // indirect
	golang.org/x/tools v0.0.0-20190719005602-e377ae9d6386 // indirect
	google.golang.org/grpc v1.22.0 // indirect
)

go.mod

 

main.go

package main

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

func HomePage(c *gin.Context) {
	c.JSON(200, gin.H{
		"message": "Hello world",
	})
}

func PostHomePage(c *gin.Context) {
	c.JSON(200, gin.H{
		"message": "PostHomePage",
	})
}

func OptionsHomePage(c *gin.Context) {
	c.JSON(200, gin.H{
		"message": "OptionsHomePage",
	})
}

func QueryStrings(c *gin.Context) {
	var name = c.Param("name")
	var age = c.Param("age")

	c.JSON(200, gin.H{
		"name": name,
		"age":  age,
	})
}

func main() {
	var router = gin.Default()
	router.GET("/welcome", HomePage)
	router.POST("/", PostHomePage)
	router.OPTIONS("/", OptionsHomePage)
	router.GET("/query/:name/:age", QueryStrings)

	// GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS

	router.Run()
}

 

 

 

 

gin-gonic/gin

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin. - ...

github.com

 

댓글
댓글쓰기 폼