12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- 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)
- gr.GET("/log", config.Log)
- }
- func newEngine() *gin.Engine {
- isDebug := common.GetConfig().Service.IsDebug
- if isDebug {
- gin.SetMode(gin.DebugMode)
- } else {
- gin.SetMode(gin.ReleaseMode)
- }
- return gin.Default()
- }
|