練習題 3

step 0. install

$ go get -u github.com/gin-gonic/gin
$ go mod vendor

step 1. Gin basic

package main

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

func main() {
    r := gin.Default()
    r.GET(
        "/ping", 
        func(c *gin.Context) {
            c.JSON(200, gin.H{"message": "pong"})
        }
    )
    r.Run() // @ 0.0.0.0:8080
}

step 2. Prototype (without db)

main.go

todos/routers.go

todos/models.go

step 3. handler register

main.go

router.go

step 4. serializer

serializers.go

routers.go

step 5. gorm

main.go

todos/model.go

common/database.go

Last updated