-
Notifications
You must be signed in to change notification settings - Fork 10
/
client-loadOption.go
36 lines (30 loc) · 1013 Bytes
/
client-loadOption.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
package ascontextmaker
// LoadConfig contains optional settings for the Load() method
type LoadConfig struct {
history []string // history tracks URI's that have already been loaded
}
// LoadOption is a function that modifies the default behavior of the LoadConfig
type LoadOption func(*LoadConfig)
// NewLoadConfig creates a new LoadConfig object with corresponding options
func NewLoadConfig(options ...any) LoadConfig {
result := LoadConfig{
history: make([]string, 0),
}
result.With(options...)
return result
}
// With applies options to the LoadConfig IF they are ascontextmaker.LoadOption
func (config *LoadConfig) With(options ...any) {
for _, option := range options {
if typed, ok := option.(LoadOption); ok {
typed(config)
}
}
}
// WithHistory adds a URI into the load history. This is used to prevent
// infinite loops when loading documents.
func WithHistory(uris ...string) LoadOption {
return func(config *LoadConfig) {
config.history = append(config.history, uris...)
}
}