parser.go 779 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package optionsparser
  2. // Presets is a map of preset names to their corresponding urlOptions
  3. type Presets = map[string]urlOptions
  4. // Parser creates Options instances
  5. type Parser struct {
  6. config *Config // Parser configuration
  7. presets Presets // Parsed presets
  8. }
  9. // New creates new Parser instance
  10. func New(config *Config) (*Parser, error) {
  11. if err := config.Validate(); err != nil {
  12. return nil, err
  13. }
  14. p := &Parser{
  15. config: config,
  16. presets: make(map[string]urlOptions),
  17. }
  18. if err := p.parsePresets(); err != nil {
  19. return nil, err
  20. }
  21. if err := p.validatePresets(); err != nil {
  22. return nil, err
  23. }
  24. return p, nil
  25. }
  26. func (p *Parser) IsSecurityOptionsAllowed() error {
  27. if p.config.AllowSecurityOptions {
  28. return nil
  29. }
  30. return newSecurityOptionsError()
  31. }