写什么呢

This commit is contained in:
suguo.yao 2020-03-24 22:03:21 +08:00
parent 4ffee0e6db
commit e3cd9e3c85
4 changed files with 54 additions and 9 deletions

View File

@ -1,7 +0,0 @@
package community
import "github.com/gin-gonic/gin"
func ListHandler(c *gin.Context) {
}

View File

@ -1,8 +1,26 @@
package community
type CommunityService struct {
import (
"github.com/jinzhu/gorm"
"yyjishu.com/rubbish-class/rubbish"
)
type CommunityModel struct {
gorm.Model
Name string `gorm:"type:varchar(20);"`
}
func (c *CommunityService) Map() {
type Community struct {
}
func (c *Community) Map() {
}
func (c *Community) Create(model *CommunityModel) error {
return nil
}
func (c *Community) Init() {
rubbish.DB.AutoMigrate(&CommunityModel{})
}

3
go.mod
View File

@ -4,6 +4,9 @@ go 1.13
require (
github.com/gin-gonic/gin v1.5.0
github.com/go-redis/redis/v7 v7.2.0
github.com/go-sql-driver/mysql v1.4.1
github.com/jinzhu/gorm v1.9.12
github.com/prometheus/common v0.9.1
github.com/silenceper/wechat v1.2.3
)

31
rubbish/database.go Normal file
View File

@ -0,0 +1,31 @@
package rubbish
import (
"log"
"time"
_ "github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"
)
var (
Addr *string
DB *gorm.DB
)
func Init() {
if *Addr != "" {
var err error
DB, err = gorm.Open("mysql", *Addr)
if err != nil {
log.Fatal(err)
}
DB.DB().SetMaxIdleConns(10)
DB.DB().SetMaxOpenConns(100)
DB.DB().SetConnMaxLifetime(10 * time.Minute)
err = DB.DB().Ping()
if err != nil {
log.Fatal(err)
}
}
}