1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2026-04-12 02:35:42 +02:00
Files
imgproxy/options/parser/parser.go
2026-01-14 18:10:46 +01:00

43 lines
843 B
Go

package optionsparser
import "context"
// Presets is a map of preset names to their corresponding urlOptions
type Presets = map[string]urlOptions
// Parser creates Options instances
type Parser struct {
config *Config // Parser configuration
presets Presets // Parsed presets
}
// New creates new Parser instance
func New(ctx context.Context, config *Config) (*Parser, error) {
if err := config.Validate(); err != nil {
return nil, err
}
p := &Parser{
config: config,
presets: make(map[string]urlOptions),
}
if err := p.parsePresets(); err != nil {
return nil, err
}
if err := p.validatePresets(ctx); err != nil {
return nil, err
}
return p, nil
}
func (p *Parser) IsSecurityOptionsAllowed(ctx context.Context) error {
if p.config.AllowSecurityOptions {
return nil
}
return newSecurityOptionsError(ctx)
}