-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
48 lines (44 loc) · 891 Bytes
/
config.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
48
package lago
import (
"errors"
"fmt"
"net/url"
)
// Config is a struct that holds the configuration for the client.
type Config struct {
BaseURL string
APIKey string
Debug bool
Client HTTPClient
}
func (c *Config) Validate() error {
if err := validateBaseURL(c.BaseURL); err != nil {
return fmt.Errorf("BaseURL validation error: %v", err)
}
if c.Client == nil {
return errors.New("Client is nil")
}
if c.APIKey == "" {
return errors.New("APIKey is empty")
}
return nil
}
func validateBaseURL(s string) error {
u, err := url.Parse(s)
if err != nil {
return err
}
if u.Scheme != "http" && u.Scheme != "https" {
return errors.New("invalid scheme")
}
if u.Host == "" {
return errors.New("missing host")
}
if u.Path != "" {
return errors.New("path must be empty")
}
if len(u.Query()) > 0 {
return errors.New("query must be empty")
}
return nil
}