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

  1. package initialize
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/jinzhu/gorm"
  5. )
  6. type Plug interface {
  7. InitRouter(*gin.Engine) error
  8. InitModel(*gorm.DB) error
  9. }
  10. func InstallPlug(db *gorm.DB, router *gin.Engine, p ...Plug) (err error) {
  11. for _, v := range p {
  12. err = v.InitModel(db)
  13. if err != nil {
  14. return err
  15. }
  16. err = v.InitRouter(router)
  17. if err != nil {
  18. return err
  19. }
  20. }
  21. return nil
  22. }