run.go 582 B

12345678910111213141516171819202122232425262728
  1. // +build examples
  2. package main
  3. import (
  4. "github.com/go-admin-team/go-admin-core/sdk"
  5. "log"
  6. "github.com/gin-gonic/gin"
  7. "gorm.io/gorm"
  8. myCasbin "github.com/go-admin-team/go-admin-core/sdk/pkg/casbin"
  9. "gorm.io/driver/mysql"
  10. )
  11. func main() {
  12. db, err := gorm.Open(mysql.Open("root:123456@tcp/inmg?charset=utf8&parseTime=True&loc=Local"), &gorm.Config{})
  13. if err != nil {
  14. panic(err)
  15. }
  16. syncEnforce := myCasbin.Setup(db, "sys_")
  17. sdk.Runtime.SetDb("*", db)
  18. sdk.Runtime.SetCasbin("*", syncEnforce)
  19. e := gin.Default()
  20. sdk.Runtime.SetEngine(e)
  21. log.Fatal(e.Run(":8000"))
  22. }