-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (44 loc) · 959 Bytes
/
main.go
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
package main
import (
"net/http"
"time"
"./database"
"github.com/gin-gonic/gin"
)
func main() {
db := database.GormConnect()
defer db.Close()
db.LogMode(true)
router := gin.Default()
router.LoadHTMLGlob("templates/*.html")
router.GET("/create_tanaka", func(c *gin.Context) {
user := database.People{}
now := time.Now()
user.Name = "tanaka"
user.CreatedAt = now
user.UpdatedAt = now
c.BindJSON(&user)
db.NewRecord(user)
db.Create(&user)
if db.NewRecord(user) == false {
c.JSON(http.StatusOK, user)
}
})
router.GET("/create_suzuki", func(c *gin.Context) {
user := database.People{}
now := time.Now()
user.Name = "suzuki"
user.CreatedAt = now
user.UpdatedAt = now
c.BindJSON(&user)
db.NewRecord(user)
db.Create(&user)
if db.NewRecord(user) == false {
c.JSON(http.StatusOK, user)
}
})
router.GET("/", func(ctx *gin.Context) {
ctx.HTML(200, "index.html", gin.H{})
})
router.Run(":80")
}