You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
409 B
25 lines
409 B
package initialize
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/jinzhu/gorm"
|
|
)
|
|
|
|
type Plug interface {
|
|
InitRouter(*gin.Engine) error
|
|
InitModel(*gorm.DB) error
|
|
}
|
|
|
|
func InstallPlug(db *gorm.DB, router *gin.Engine, p ...Plug) (err error) {
|
|
for _, v := range p {
|
|
err = v.InitModel(db)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = v.InitRouter(router)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|