cors_config.go 533 B

1234567891011121314151617181920212223242526272829303132333435
  1. package cors
  2. type Config struct {
  3. origin string
  4. methods string
  5. }
  6. type ConfigOption func(*Config)
  7. type ConfigOptions []ConfigOption
  8. func (s *ConfigOptions) Add(option ConfigOption) {
  9. *s = append(*s, option)
  10. }
  11. func NewConfig(opts ...ConfigOption) Config {
  12. c := &Config{}
  13. for _, opt := range opts {
  14. opt(c)
  15. }
  16. return *c
  17. }
  18. func WithOrigin(origin string) ConfigOption {
  19. return func(s *Config) {
  20. s.origin = origin
  21. }
  22. }
  23. func WithMethods(methods string) ConfigOption {
  24. return func(s *Config) {
  25. s.methods = methods
  26. }
  27. }