123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package cmd
- import (
- "github.com/gin-gonic/gin"
- "github.com/spf13/cobra"
- "ppgo/common"
- "ppgo/module/api/controller"
- )
- var WebCmd = &cobra.Command{
- Use: "api",
- Short: "start api service",
- Long: `service`,
- Run: runCmd,
- }
- func init() {
- RootCmd.AddCommand(WebCmd)
- }
- func runCmd(cmd *cobra.Command, args []string) {
- r := newEngine()
- setupRouter(r)
- startHttp(r, common.GetConfig().Service.Httpport)
- }
- func setupRouter(r *gin.Engine) {
- gr := r.Group("/api")
- config := controller.ConfigCtrl{}
- gr.GET("/config/all", config.All)
- }
- func newEngine() *gin.Engine {
- isDebug := common.GetConfig().Service.IsDebug
- if isDebug {
- gin.SetMode(gin.DebugMode)
- } else {
- gin.SetMode(gin.ReleaseMode)
- }
- return gin.Default()
- }
|