mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-22 19:07:48 +08:00
37 lines
631 B
Go
37 lines
631 B
Go
package options
|
|
|
|
type ApiSettings struct {
|
|
Offline bool
|
|
}
|
|
|
|
type ApiOption func(*ApiSettings) error
|
|
|
|
func ApiOptions(opts ...ApiOption) (*ApiSettings, error) {
|
|
options := &ApiSettings{
|
|
Offline: false,
|
|
}
|
|
|
|
return ApiOptionsTo(options, opts...)
|
|
}
|
|
|
|
func ApiOptionsTo(options *ApiSettings, opts ...ApiOption) (*ApiSettings, error) {
|
|
for _, opt := range opts {
|
|
err := opt(options)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return options, nil
|
|
}
|
|
|
|
type apiOpts struct{}
|
|
|
|
var Api apiOpts
|
|
|
|
func (apiOpts) Offline(offline bool) ApiOption {
|
|
return func(settings *ApiSettings) error {
|
|
settings.Offline = offline
|
|
return nil
|
|
}
|
|
}
|