Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

27 linhas
598 B

  1. package middleware
  2. import (
  3. "github.com/QuantumNous/new-api/common"
  4. "github.com/gin-contrib/cors"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func CORS() gin.HandlerFunc {
  8. config := cors.DefaultConfig()
  9. config.AllowAllOrigins = false
  10. config.AllowOriginFunc = func(origin string) bool {
  11. return true
  12. }
  13. config.AllowCredentials = true
  14. config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}
  15. config.AllowHeaders = []string{"*"}
  16. return cors.New(config)
  17. }
  18. func PoweredBy() gin.HandlerFunc {
  19. return func(c *gin.Context) {
  20. c.Header("X-New-Api-Version", common.Version)
  21. c.Next()
  22. }
  23. }