43 lines
667 B
Go
43 lines
667 B
Go
package rest
|
|
|
|
type CORSConfig struct {
|
|
Enabled bool
|
|
AllowedOrigins []string
|
|
AllowedMethods []string
|
|
AllowCredentials bool
|
|
MaxAge int
|
|
}
|
|
|
|
type SwaggerConfig struct {
|
|
Enabled bool
|
|
Host string
|
|
Schemes []string
|
|
}
|
|
|
|
type Option func(cfg *config)
|
|
|
|
func WithCORSConfig(cors CORSConfig) Option {
|
|
return func(cfg *config) {
|
|
cfg.cors = cors
|
|
}
|
|
}
|
|
|
|
func WithSwaggerConfig(swagger SwaggerConfig) Option {
|
|
return func(cfg *config) {
|
|
cfg.swagger = swagger
|
|
}
|
|
}
|
|
|
|
type config struct {
|
|
cors CORSConfig
|
|
swagger SwaggerConfig
|
|
}
|
|
|
|
func newConfig(opts ...Option) *config {
|
|
cfg := &config{}
|
|
for _, opt := range opts {
|
|
opt(cfg)
|
|
}
|
|
return cfg
|
|
}
|