從golang-gin-realworld-example-app項目學寫httpapi (七)
阿新 • • 發佈:2018-11-22
fun github lan () pac follow lob git gop
https://github.com/gothinkster/golang-gin-realworld-example-app/blob/master/hello.go
main調用
package main import ( "fmt" "gopkg.in/gin-gonic/gin.v1" "github.com/jinzhu/gorm" "github.com/wangzitian0/golang-gin-starter-kit/common" "github.com/wangzitian0/golang-gin-starter-kit/users" ) func Migrate(db *gorm.DB) { //users.AutoMigrate() db.AutoMigrate(&users.UserModel{}) db.AutoMigrate(&users.FollowModel{}) } func main() { db := common.Init() Migrate(db) defer db.Close() r := gin.Default() v1 := r.Group("/api") v1.Use(users.AuthMiddleware(true)) users.UsersRegister(v1.Group("/users")) users.UserRegister(v1.Group("/user")) users.ProfileRegister(v1.Group("/profiles")) r.Run() // listen and serve on 0.0.0.0:8080 }
從golang-gin-realworld-example-app項目學寫httpapi (七)