-
Notifications
You must be signed in to change notification settings - Fork 15
/
namecheap.go
40 lines (30 loc) · 818 Bytes
/
namecheap.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
package source
import (
gonc "github.com/billputer/go-namecheap"
)
// NameCheapConfig holds the configuration for the namecheap.com source
type NameCheapConfig struct {
APIUser string
APIToken string
UserName string
Enabled bool
}
// NameCheap handles namecheap.com API requests
type NameCheap struct {
config *NameCheapConfig
}
// NewNameCheap returns a new NameCheap instance
func NewNameCheap(config *NameCheapConfig) Source {
nc := new(NameCheap)
nc.config = config
return nc
}
// IsAvailable checks if a domain is available
func (nc *NameCheap) IsAvailable(domain string) (bool, error) {
client := gonc.NewClient(nc.config.APIUser, nc.config.APIToken, nc.config.UserName)
result, err := client.DomainsCheck(domain)
if err == nil {
return result[0].Available, err
}
return false, err
}