12345678910111213141516171819202122232425 |
- package middleware
- import (
- "git.sxidc.com/go-tools/api_binding/http_binding/binding_context"
- "net/http"
- )
- func Cors() Func {
- return func(c *binding_context.Context) {
- method := c.Request.Method
- c.Header("Access-Control-Allow-Origin", "*")
- c.Header("Access-Control-Allow-Headers", "Content-Length, Content-Type, AccessToken, X-CSRF-Token, Authorization, Token")
- c.Header("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE,OPTIONS")
- c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, "+
- "Access-Control-Allow-Headers, Content-Type")
- c.Header("Access-Control-Allow-Credentials", "true")
- if method == "OPTIONS" {
- c.AbortWithStatus(http.StatusOK)
- }
- c.Next()
- }
- }
|