-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathparser_options.go
47 lines (36 loc) · 1.28 KB
/
parser_options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
Copyright © 2024 Acronis International GmbH.
Released under MIT license.
*/
package cti
// ParserOption is an interface for functional options that can be passed to the NewParser constructor.
type ParserOption interface {
apply(*parserOptions)
}
type parserOptions struct {
allowAnonymousEntity bool
allowedDynamicParameterNames []string
}
type allowAnonymousEntityParserOption bool
func (o allowAnonymousEntityParserOption) apply(opts *parserOptions) {
opts.allowAnonymousEntity = bool(o)
}
// WithAllowAnonymousEntity allows specifying whether the anonymous entity is allowed to be used in the CTI.
func WithAllowAnonymousEntity(b bool) ParserOption {
return allowAnonymousEntityParserOption(b)
}
type allowedDynamicParameterNamesParserOption []string
func (o allowedDynamicParameterNamesParserOption) apply(opts *parserOptions) {
opts.allowedDynamicParameterNames = o
}
// WithAllowedDynamicParameterNames allows specifying dynamic parameter names that are allowed to be used in the CTI.
func WithAllowedDynamicParameterNames(names ...string) ParserOption {
return allowedDynamicParameterNamesParserOption(names)
}
func makeParserOptions(opts ...ParserOption) parserOptions {
var options parserOptions
for _, opt := range opts {
opt.apply(&options)
}
return options
}