-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
139 lines (118 loc) · 4.18 KB
/
options.go
File metadata and controls
139 lines (118 loc) · 4.18 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package starmap
import (
"time"
"github.com/agentstation/starmap/internal/utils/ptr"
"github.com/agentstation/starmap/pkg/catalogs"
"github.com/agentstation/starmap/pkg/constants"
"github.com/agentstation/starmap/pkg/sources"
)
// ============================================================================
// Starmap Options
// ============================================================================
// options holds the configuration for a Starmap instance.
type options struct {
// Remote server configuration
remoteServerURL *string
remoteServerAPIKey *string
remoteServerOnly bool // If true (enabled), don't use any other sources for catalog updates including provider APIs
// Update configuration
autoUpdatesEnabled bool
autoUpdateInterval time.Duration
autoUpdateFunc AutoUpdateFunc
// local catalog path
localPath string
// embedded catalog
embeddedCatalogEnabled bool
sources []sources.ID // Configured sources for syncing
}
func defaults() *options {
return &options{
autoUpdatesEnabled: true, // Default to auto-updates enabled
autoUpdateInterval: constants.DefaultUpdateInterval, // Default to hourly updates
autoUpdateFunc: nil, // Default to no auto-update function
localPath: "", // Default to no local path
embeddedCatalogEnabled: false, // Default to no embedded catalog
sources: []sources.ID{}, // Default to no sources
remoteServerURL: nil, // Default to no remote server
remoteServerAPIKey: nil, // Default to no remote server API key
remoteServerOnly: false, // Default to not only use remote server
}
}
// Option is a function that configures a Starmap instance.
type Option func(*options) error
// apply applies the given options to the options.
func (o *options) apply(opts ...Option) (*options, error) {
for _, opt := range opts {
if err := opt(o); err != nil {
return nil, err
}
}
return o, nil
}
// WithRemoteServerURL configures the remote server URL.
func WithRemoteServerURL(url string) Option {
return func(o *options) error {
o.remoteServerURL = ptr.String(url)
return nil
}
}
// WithRemoteServerAPIKey configures the remote server API key.
func WithRemoteServerAPIKey(apiKey string) Option {
return func(o *options) error {
o.remoteServerAPIKey = ptr.String(apiKey)
return nil
}
}
// WithRemoteServerOnly configures whether to only use the remote server and not hit provider APIs.
func WithRemoteServerOnly(url string) Option {
return func(o *options) error {
o.remoteServerOnly = true
o.remoteServerURL = ptr.String(url)
return nil
}
}
// WithAutoUpdatesDisabled configures whether automatic updates are disabled.
func WithAutoUpdatesDisabled() Option {
return func(o *options) error {
o.autoUpdatesEnabled = false
return nil
}
}
// WithAutoUpdateInterval configures how often to automatically update the catalog.
func WithAutoUpdateInterval(interval time.Duration) Option {
return func(o *options) error {
o.autoUpdateInterval = interval
return nil
}
}
// AutoUpdateFunc is a function that updates the catalog.
type AutoUpdateFunc func(catalogs.Catalog) (catalogs.Catalog, error)
// WithAutoUpdateFunc configures a custom function for updating the catalog.
func WithAutoUpdateFunc(fn AutoUpdateFunc) Option {
return func(o *options) error {
o.autoUpdateFunc = fn
return nil
}
}
// // WithInitialCatalog configures the initial catalog to use.
// func WithInitialCatalog(catalog catalogs.Catalog) Option {
// return func(o *options) error {
// o.initialCatalog = &catalog
// return nil
// }
// }
// WithLocalPath configures the local source to use a specific catalog path.
func WithLocalPath(path string) Option {
return func(o *options) error {
o.localPath = path
return nil
}
}
// WithEmbeddedCatalog configures whether to use an embedded catalog.
// It defaults to false, but takes precedence over WithLocalPath if set.
func WithEmbeddedCatalog() Option {
return func(o *options) error {
o.embeddedCatalogEnabled = true
return nil
}
}