Skip to content

Commit d6ce928

Browse files
committed
Refactor cors
1 parent 2e128c4 commit d6ce928

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

cors/cors.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ import (
66
)
77

88
type AllowConfig struct {
9-
Origins string `mapstructure:"origins" json:"origins,omitempty" gorm:"column:origins" bson:"origins,omitempty" dynamodbav:"origins,omitempty" firestore:"origins,omitempty"`
10-
Methods string `mapstructure:"methods" json:"methods,omitempty" gorm:"column:methods" bson:"methods,omitempty" dynamodbav:"methods,omitempty" firestore:"methods,omitempty"`
11-
Headers string `mapstructure:"headers" json:"headers,omitempty" gorm:"column:headers" bson:"headers,omitempty" dynamodbav:"headers,omitempty" firestore:"headers,omitempty"`
12-
Credentials bool `mapstructure:"credentials" json:"credentials,omitempty" gorm:"column:credentials" bson:"credentials,omitempty" dynamodbav:"credentials,omitempty" firestore:"credentials,omitempty"`
13-
MaxAge *int `mapstructure:"max_age" json:"maxAge,omitempty" gorm:"column:maxage" bson:"maxAge,omitempty" dynamodbav:"maxAge,omitempty" firestore:"maxAge,omitempty"`
14-
ExposedHeaders string `mapstructure:"exposed_headers" json:"exposedHeaders,omitempty" gorm:"column:exposedheaders" bson:"exposedHeaders,omitempty" dynamodbav:"exposedHeaders,omitempty" firestore:"exposedHeaders,omitempty"`
15-
PrivateNetwork *bool `mapstructure:"private_network" json:"privateNetwork,omitempty" gorm:"column:privatenetwork" bson:"privateNetwork,omitempty" dynamodbav:"privateNetwork,omitempty" firestore:"privateNetwork,omitempty"`
16-
OptionsPassthrough *bool `mapstructure:"options_passthrough" json:"optionsPassthrough,omitempty" gorm:"column:optionsPassthrough" bson:"optionsPassthrough,omitempty" dynamodbav:"optionsPassthrough,omitempty" firestore:"optionsPassthrough,omitempty"`
17-
OptionsSuccessStatus *int `mapstructure:"options_success_status" json:"optionsSuccessStatus,omitempty" gorm:"column:optionssuccessstatus" bson:"optionsSuccessStatus,omitempty" dynamodbav:"optionsSuccessStatus,omitempty" firestore:"optionsSuccessStatus,omitempty"`
9+
Origins string `mapstructure:"origins" json:"origins,omitempty" gorm:"column:origins" bson:"origins,omitempty" dynamodbav:"origins,omitempty" firestore:"origins,omitempty"`
10+
Methods string `mapstructure:"methods" json:"methods,omitempty" gorm:"column:methods" bson:"methods,omitempty" dynamodbav:"methods,omitempty" firestore:"methods,omitempty"`
11+
Headers string `mapstructure:"headers" json:"headers,omitempty" gorm:"column:headers" bson:"headers,omitempty" dynamodbav:"headers,omitempty" firestore:"headers,omitempty"`
12+
Credentials bool `mapstructure:"credentials" json:"credentials,omitempty" gorm:"column:credentials" bson:"credentials,omitempty" dynamodbav:"credentials,omitempty" firestore:"credentials,omitempty"`
13+
MaxAge *int `mapstructure:"max_age" json:"maxAge,omitempty" gorm:"column:maxage" bson:"maxAge,omitempty" dynamodbav:"maxAge,omitempty" firestore:"maxAge,omitempty"`
14+
ExposedHeaders string `mapstructure:"exposed_headers" json:"exposedHeaders,omitempty" gorm:"column:exposedheaders" bson:"exposedHeaders,omitempty" dynamodbav:"exposedHeaders,omitempty" firestore:"exposedHeaders,omitempty"`
15+
OptionsPassthrough *bool `mapstructure:"options_passthrough" json:"optionsPassthrough,omitempty" gorm:"column:optionsPassthrough" bson:"optionsPassthrough,omitempty" dynamodbav:"optionsPassthrough,omitempty" firestore:"optionsPassthrough,omitempty"`
1816
}
1917

2018
func New(conf AllowConfig) *cors.Cors {
@@ -34,14 +32,8 @@ func New(conf AllowConfig) *cors.Cors {
3432
if len(conf.ExposedHeaders) > 0 {
3533
opts.ExposedHeaders = strings.Split(conf.ExposedHeaders, ",")
3634
}
37-
if conf.PrivateNetwork != nil {
38-
opts.AllowPrivateNetwork = *conf.PrivateNetwork
39-
}
4035
if conf.OptionsPassthrough != nil {
4136
opts.OptionsPassthrough = *conf.OptionsPassthrough
4237
}
43-
if conf.OptionsSuccessStatus != nil {
44-
opts.OptionsSuccessStatus = *conf.OptionsSuccessStatus
45-
}
4638
return cors.New(opts)
4739
}

0 commit comments

Comments
 (0)