route.go 864 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package route
  4. import (
  5. "net/http"
  6. "github.com/gin-gonic/gin"
  7. v1_0 "adm-data-gateway/controller/v1.0"
  8. _ "adm-data-gateway/docs"
  9. "adm-data-gateway/route/middware"
  10. )
  11. func SetupRoute(engine *gin.Engine) {
  12. // 404页面
  13. engine.NoRoute(func(c *gin.Context) {
  14. c.String(http.StatusNotFound, "Not Found")
  15. })
  16. // 服务健康检查
  17. engine.GET("/ping", func(c *gin.Context) {
  18. c.String(http.StatusOK, "pong")
  19. })
  20. // version 1
  21. apiv1_0 := engine.Group("/api/v1.0")
  22. {
  23. c := v1_0.NewController()
  24. apiv1_0.Use(middware.Cors(), middware.Sign(), middware.Verify())
  25. query := apiv1_0.Group("/query")
  26. {
  27. query.OPTIONS("/", func(ctx *gin.Context) {
  28. ctx.AbortWithStatus(http.StatusNoContent)
  29. return
  30. })
  31. query.POST("/", c.Query)
  32. }
  33. }
  34. }