enterprise/server/server.go

56 lines
2.0 KiB
Go

package server
import (
"enterprise/common/config"
"enterprise/server/controller"
"github.com/gin-gonic/gin"
)
func initRoutge(engine *gin.Engine) {
base := new(controller.Base)
apiGroup := engine.Group("/api")
noTokenGroup := engine.Group("/api")
group := engine.Group("/").Use(base.Recovery).Use(base.Before)
apiGroup.Use(base.Recovery).Use(base.Before).Use(base.Token)
noTokenGroup.Use(base.Recovery).Use(base.Before)
noTokenGroup.POST("/pay", controller.NewPay().Pay)
noTokenGroup.Any("/qyweixin/approve/:cid", controller.NewQyWeixin().Approve)
noTokenGroup.Any("/qyweixin/handle/refund", controller.NewQyWeixin().HandleRefund)
apiGroup.GET("/checkin", controller.NewStaffCheckin().List)
apiGroup.DELETE("/checkin", controller.NewStaffCheckin().Delete)
apiGroup.Any("/checkin/sync", controller.NewStaffCheckin().Sync)
group.GET("/staff/salary", controller.NewStaff().Salary)
group.GET("/staff/sync/salary", controller.NewStaff().SyncStaffSalary)
noTokenGroup.POST("/staff/login", controller.NewStaff().Login)
apiGroup.GET("/staff/salary", controller.NewSalary().List)
apiGroup.POST("/staff/salary", controller.NewSalary().Create)
apiGroup.PUT("/staff/salary", controller.NewSalary().Update)
apiGroup.DELETE("/staff/salary", controller.NewSalary().Delete)
apiGroup.GET("/staff/suggest", controller.NewStaff().Suggest)
apiGroup.POST("/staff", controller.NewStaff().Create)
apiGroup.PUT("/staff", controller.NewStaff().Update)
apiGroup.DELETE("/staff", controller.NewStaff().Delete)
apiGroup.GET("/staff", controller.NewStaff().List)
apiGroup.GET("/calculator", controller.NewCalculator().List)
apiGroup.POST("/calculator", controller.NewCalculator().Create)
apiGroup.PUT("/calculator", controller.NewCalculator().Update)
apiGroup.DELETE("/calculator", controller.NewCalculator().Delete)
engine.LoadHTMLGlob("conf/template/*")
}
func Start() error {
cfg := config.GetConfig()
engine := gin.New()
initRoutge(engine)
return engine.Run(cfg.Server.Address)
}