Skip to content

Commit d99543a

Browse files
committed
Reduce number of exported functions
1 parent 50e30ab commit d99543a

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

decode.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type Domain struct {
6969

7070
// Convert rawbody to XML and subtract the 'body' from the
7171
// SOAP-envelope into the struct given with out
72-
func Decode(rawbody []byte, out interface{}) error {
72+
func decode(rawbody []byte, out interface{}) error {
7373
dec := xml.NewDecoder(bytes.NewReader(rawbody))
7474

7575
for {

domainservice.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ type DomainService struct {
1414
}
1515

1616
func (c *DomainService) DomainNames() ([]string, error) {
17-
rawbody, e := Lookup(c.Creds, Request{Service: domainService, Method: "getDomainNames", Body: `<ns1:getDomainNames/>`})
17+
rawbody, e := lookup(c.Creds, request{Service: domainService, Method: "getDomainNames", Body: `<ns1:getDomainNames/>`})
1818
if e != nil {
1919
return nil, e
2020
}
2121

2222
domains := &DomainNames{}
23-
e = Decode(rawbody, &domains)
23+
e = decode(rawbody, &domains)
2424
return domains.Item, e
2525
}
2626

2727
func (c *DomainService) Domain(name string) (*Domain, error) {
28-
rawbody, e := Lookup(c.Creds, Request{
28+
rawbody, e := lookup(c.Creds, request{
2929
Service: domainService,
30-
ExtraParams: []KV{
30+
ExtraParams: []kV{
3131
{Key: "0", Value: name},
3232
},
3333
Method: "getInfo",
@@ -38,23 +38,23 @@ func (c *DomainService) Domain(name string) (*Domain, error) {
3838
}
3939

4040
domain := &Domain{}
41-
e = Decode(rawbody, &domain)
41+
e = decode(rawbody, &domain)
4242
return domain, e
4343
}
4444

4545
func (c *DomainService) Domains(names []string) ([]Domain, error) {
4646
entryTemplate := `<item xsi:type="xsd:string">%s</item>`
47-
params := []KV{}
47+
params := []kV{}
4848
xml := ``
4949

5050
for idx, v := range names {
5151
xml = xml + fmt.Sprintf(entryTemplate, v)
52-
params = append(params, []KV{
52+
params = append(params, []kV{
5353
{Key: fmt.Sprintf("0[%d]", idx), Value: v},
5454
}...)
5555
}
5656

57-
rawbody, e := Lookup(c.Creds, Request{
57+
rawbody, e := lookup(c.Creds, request{
5858
Service: domainService,
5959
ExtraParams: params,
6060
Method: "batchGetInfo",
@@ -65,29 +65,29 @@ func (c *DomainService) Domains(names []string) ([]Domain, error) {
6565
}
6666

6767
domains := &Domains{}
68-
e = Decode(rawbody, &domains)
68+
e = decode(rawbody, &domains)
6969
return domains.Domains, e
7070
}
7171

7272
func (c *DomainService) SetDNSEntries(domain string, entries []DomainDNSentry) error {
7373
entryTemplate := `<item xsi:type="ns1:DnsEntry"><name xsi:type="xsd:string">%s</name><expire xsi:type="xsd:int">%d</expire><type xsi:type="xsd:string">%s</type><content xsi:type="xsd:string">%s</content></item>`
7474

75-
params := []KV{
75+
params := []kV{
7676
{Key: "0", Value: domain},
7777
}
7878
xml := ``
7979

8080
for idx, entry := range entries {
8181
xml = xml + fmt.Sprintf(entryTemplate, entry.Name, entry.Expire, entry.Type, entry.Content)
82-
params = append(params, []KV{
82+
params = append(params, []kV{
8383
{fmt.Sprintf("1[%d][name]", idx), entry.Name},
8484
{fmt.Sprintf("1[%d][expire]", idx), strconv.Itoa(entry.Expire)},
8585
{fmt.Sprintf("1[%d][type]", idx), entry.Type},
8686
{fmt.Sprintf("1[%d][content]", idx), entry.Content},
8787
}...)
8888
}
8989

90-
rawbody, e := Lookup(c.Creds, Request{
90+
rawbody, e := lookup(c.Creds, request{
9191
Service: domainService,
9292
ExtraParams: params,
9393
Method: "setDnsEntries",

signature.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func sha512ASN1(data []byte) []byte {
2828
return append(asn1, h.Sum(nil)...)
2929
}
3030

31-
func Sign(privKey *rsa.PrivateKey, params []KV) (string, error) {
31+
func sign(privKey *rsa.PrivateKey, params []kV) (string, error) {
3232
asn1 := sha512ASN1(urlencode(params))
3333

3434
sig, e := rsa.SignPKCS1v15(nil, privKey, crypto.Hash(0), asn1)

signature_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
)
1111

1212
func TestParamEncode(t *testing.T) {
13-
in := []KV{
14-
KV{"__method", "getDomainNames"},
15-
KV{"__service", "DomainService"},
16-
KV{"__hostname", "api.transip.nl"},
17-
KV{"__timestamp", "1492760973"},
18-
KV{"__nonce", "58f9b98ddd3999.86051758"},
13+
in := []kV{
14+
kV{"__method", "getDomainNames"},
15+
kV{"__service", "DomainService"},
16+
kV{"__hostname", "api.transip.nl"},
17+
kV{"__timestamp", "1492760973"},
18+
kV{"__nonce", "58f9b98ddd3999.86051758"},
1919
}
2020
expect := []byte(`__method=getDomainNames&__service=DomainService&__hostname=api.transip.nl&__timestamp=1492760973&__nonce=58f9b98ddd3999.86051758`)
2121

soap.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ func uniqid() string {
2828
)
2929
}
3030

31-
type Request struct {
31+
type request struct {
3232
Service string // Service to call on TransIP side
33-
ExtraParams []KV // Additional params for the signature-code
33+
ExtraParams []kV // Additional params for the signature-code
3434
Body string // XML body to send in envelope
3535
Method string // Method to call on service
3636
}
3737

38-
func Lookup(c Client, in Request) ([]byte, error) {
38+
func lookup(c Client, in request) ([]byte, error) {
3939
raw := fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>
4040
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
4141
xmlns:ns1="%s" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
@@ -83,14 +83,14 @@ func Lookup(c Client, in Request) ([]byte, error) {
8383
})
8484

8585
kv := in.ExtraParams
86-
kv = append(kv, []KV{
86+
kv = append(kv, []kV{
8787
{"__method", in.Method},
8888
{"__service", in.Service},
8989
{"__hostname", API_URL},
9090
{"__timestamp", now},
9191
{"__nonce", nonce}}...,
9292
)
93-
sig, e := Sign(c.PrivateKey, kv)
93+
sig, e := sign(c.PrivateKey, kv)
9494
if e != nil {
9595
return []byte{}, e
9696
}

urlencode.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import (
66
"strings"
77
)
88

9-
type KV struct {
9+
type kV struct {
1010
Key string
1111
Value string
1212
}
1313

1414
// Encode encodes the values into ``URL encoded'' form
1515
// ("bar=baz&foo=quux") NOT sorted.
1616
// https://golang.org/src/net/url/url.go?s=24497:24528#L850
17-
func urlencode(v []KV) []byte {
17+
func urlencode(v []kV) []byte {
1818
if v == nil {
1919
return []byte{}
2020
}

0 commit comments

Comments
 (0)