-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
106 lines (93 loc) · 2.12 KB
/
Copy pathconfig.go
File metadata and controls
106 lines (93 loc) · 2.12 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
package gosparkclient
import (
"errors"
"time"
)
const (
defaultTimeout = 30 * time.Second
defaultUID = "12345"
defaultAuditing = "default"
)
// Config holds all configuration options for SparkClient
type Config struct {
AppID string
ApiSecret string
ApiKey string
HostURL string
EMBURL string
Domain string
Timeout time.Duration
UID string
Auditing string
}
// ConfigOption defines a function type for setting config options
type ConfigOption func(*Config)
// DefaultConfig returns a Config with default values
func DefaultConfig() *Config {
return &Config{
Timeout: defaultTimeout,
UID: defaultUID,
Auditing: defaultAuditing,
}
}
// validateConfig checks if the configuration is valid
func validateConfig(c *Config) error {
if c.AppID == "" {
return errors.New("AppID is required")
}
if c.ApiSecret == "" {
return errors.New("ApiSecret is required")
}
if c.ApiKey == "" {
return errors.New("ApiKey is required")
}
if c.HostURL == "" {
return errors.New("HostURL is required")
}
return nil
}
// WithTimeout sets the timeout for the client
func WithTimeout(timeout time.Duration) ConfigOption {
return func(c *Config) {
c.Timeout = timeout
}
}
// WithUID sets the UID for the client
func WithUID(uid string) ConfigOption {
return func(c *Config) {
c.UID = uid
}
}
// WithAuditing sets the auditing mode
func WithAuditing(auditing string) ConfigOption {
return func(c *Config) {
c.Auditing = auditing
}
}
// WithCredentials sets the credentials for the client
func WithCredentials(appID, apiKey, apiSecret string) ConfigOption {
return func(c *Config) {
c.AppID = appID
c.ApiKey = apiKey
c.ApiSecret = apiSecret
}
}
// WithURLs sets the URLs for the client
func WithURLs(hostURL, embURL string) ConfigOption {
return func(c *Config) {
c.HostURL = hostURL
c.EMBURL = embURL
}
}
// WithDomain sets the domain for the client
func WithDomain(domain string) ConfigOption {
return func(c *Config) {
c.Domain = domain
}
}
// WithConfig sets the entire configuration
func WithConfig(config *Config) ConfigOption {
return func(c *Config) {
*c = *config
}
}