-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhelpers.go
More file actions
49 lines (40 loc) · 1.28 KB
/
helpers.go
File metadata and controls
49 lines (40 loc) · 1.28 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
package timeweb
import (
"fmt"
"strings"
"github.com/libdns/libdns"
)
func isRecordExists(records []libdns.Record, libRecord libdns.Record) bool {
targetRR := libRecord.RR()
for _, record := range records {
rr := record.RR()
if targetRR.Name == rr.Name && targetRR.Type == rr.Type {
return true
}
}
return false
}
func normalizeZone(zone string) string {
return strings.TrimSuffix(strings.Replace(zone, "*.", "", 1), ".")
}
func getFQDN(record libdns.Record, zone string) string {
name := libdns.AbsoluteName(record.RR().Name, zone)
if record.RR().Type == "SRV" {
// For SRV records, the name is actually service.protocol.subdomain
parts := strings.SplitN(name, ".", 3)
name = parts[2]
}
return name
}
// buildURL builds a full API URL for the given API version and formatted path.
func (p *Provider) buildURL(version, pathFmt string, args ...interface{}) string {
base := strings.TrimRight(p.ApiURL, "/")
path := fmt.Sprintf(pathFmt, args...)
return fmt.Sprintf("%s/%s/%s", base, strings.Trim(version, "/"), strings.TrimLeft(path, "/"))
}
func (p *Provider) v1(pathFmt string, args ...interface{}) string {
return p.buildURL("api/v1", pathFmt, args...)
}
func (p *Provider) v2(pathFmt string, args ...interface{}) string {
return p.buildURL("api/v2", pathFmt, args...)
}