forked from devfeel/dotweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cors.go
42 lines (36 loc) · 954 Bytes
/
cors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package feature
//CROS配置
type CROSConfig struct {
EnabledCROS bool
AllowedOrigins string
AllowedMethods string
AllowedHeaders string
AllowCredentials bool
AllowedP3P string
}
func NewCORSConfig() *CROSConfig {
return &CROSConfig{}
}
func (c *CROSConfig) UseDefault() *CROSConfig {
c.AllowedOrigins = "*"
c.AllowedMethods = "GET, POST, PUT, DELETE, OPTIONS"
c.AllowedHeaders = "Content-Type"
c.AllowedP3P = "CP=\"CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR\""
return c
}
func (c *CROSConfig) SetOrigin(origins string) *CROSConfig {
c.AllowedOrigins = origins
return c
}
func (c *CROSConfig) SetMethod(methods string) *CROSConfig {
c.AllowedMethods = methods
return c
}
func (c *CROSConfig) SetHeader(headers string) *CROSConfig {
c.AllowedHeaders = headers
return c
}
func (c *CROSConfig) SetAllowCredentials(flag bool) *CROSConfig {
c.AllowCredentials = flag
return c
}