Debian Codegraph @

goinwx.go

raw symbols SCIP
1 package goinwxscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/
2
3 import (
4 "net/urlscip-go gomod github.com/golang/go/src go1.22 `net/url`/"
5
6 "github.com/kolo/xmlrpcscip-go gomod github.com/kolo/xmlrpc a4b6fa1dd06b `github.com/kolo/xmlrpc`/"
7 )
8
9 // API information.
10 const (
11 APIBaseURLscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/APIBaseURL. = "https://api.domrobot.com/xmlrpc/"
12 APISandboxBaseURLscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/APISandboxBaseURL. = "https://api.ote.domrobot.com/xmlrpc/"
13 APILanguagescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/APILanguage. = "en"
14 )
15
16 // Client manages communication with INWX API.
17 type Clientscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client# struct {
18 // HTTP client used to communicate with the INWX API.
19 RPCClientscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#RPCClient. *xmlrpcscip-go gomod github.com/kolo/xmlrpc a4b6fa1dd06b `github.com/kolo/xmlrpc`/.Clientscip-go gomod github.com/kolo/xmlrpc a4b6fa1dd06b `github.com/kolo/xmlrpc`/Client#
20
21 // API username and password
22 usernamescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#username. string
23 passwordscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#password. string
24
25 langscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#lang. string
26
27 commonscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#common. servicescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/service# // Reuse a single struct instead of allocating one for each service on the heap.
28
29 // Services used for communicating with the API
30 Accountscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#Account. *AccountServicescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/AccountService#
31 Contactsscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#Contacts. *ContactServicescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ContactService#
32 Dnssecscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#Dnssec. *DNSSecServicescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/DNSSecService#
33 Domainsscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#Domains. *DomainServicescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/DomainService#
34 Nameserversscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#Nameservers. *NameserverServicescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/NameserverService#
35 }
36
37 type servicescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/service# struct {
38 clientscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/service#client. *Clientscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#
39 }
40
41 // ClientOptions Options of the API client.
42 type ClientOptionsscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ClientOptions# struct {
43 Sandboxscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ClientOptions#Sandbox. bool
44
45 // Language of the return message. (en/de/es)
46 Langscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ClientOptions#Lang. string
47
48 // Base URL for API requests (only for client testing purpose).
49 BaseURLscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ClientOptions#BaseURL. *urlscip-go gomod github.com/golang/go/src go1.22 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.22 `net/url`/URL#
50 }
51
52 // Request The representation of an API request.
53 type Requestscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Request# struct {
54 ServiceMethodscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Request#ServiceMethod. string
55 Argsscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Request#Args. map[string]any
56 }
57
58 // NewClient returns a new INWX API client.
59 func NewClientscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/NewClient().(username, password string, opts *ClientOptionsscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ClientOptions#) *Clientscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client# {
60 baseURL := getBaseURLscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/getBaseURL().(opts).Stringscip-go gomod github.com/golang/go/src go1.22 `net/url`/URL#String().()
61
62 rpcClient, _ := xmlrpcscip-go gomod github.com/kolo/xmlrpc a4b6fa1dd06b `github.com/kolo/xmlrpc`/.NewClientscip-go gomod github.com/kolo/xmlrpc a4b6fa1dd06b `github.com/kolo/xmlrpc`/NewClient().(baseURL, nil)
63
64 client := &Clientscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#{
65 RPCClientscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#RPCClient.: rpcClient,
66 usernamescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#username.: username,
67 passwordscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#password.: password,
68 langscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#lang.: APILanguagescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/APILanguage.,
69 }
70
71 if opts != nil && opts.Langscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ClientOptions#Lang. != "" {
72 client.langscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#lang. = opts.Langscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ClientOptions#Lang.
73 }
74
75 client.commonscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#common..clientscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/service#client. = client
76 client.Accountscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#Account. = (*AccountServicescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/AccountService#)(&client.commonscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#common.)
77 client.Contactsscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#Contacts. = (*ContactServicescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ContactService#)(&client.commonscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#common.)
78 client.Dnssecscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#Dnssec. = (*DNSSecServicescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/DNSSecService#)(&client.commonscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#common.)
79 client.Domainsscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#Domains. = (*DomainServicescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/DomainService#)(&client.commonscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#common.)
80 client.Nameserversscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#Nameservers. = (*NameserverServicescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/NameserverService#)(&client.commonscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#common.)
81
82 return client
83 }
84
85 // NewRequest creates an API request.
86 func (c *Clientscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#) NewRequestscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#NewRequest().(serviceMethod string, args map[string]any) *Requestscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Request# {
87 if args != nil {
88 args["lang"] = APILanguagescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/APILanguage.
89 }
90
91 return &Requestscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Request#{ServiceMethodscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Request#ServiceMethod.: serviceMethod, Argsscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Request#Args.: args}
92 }
93
94 // Do sends an API request and returns the API response.
95 func (c *Clientscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#) Doscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#Do().(req *Requestscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Request#) (map[string]any, error) {
96 var resp Responsescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Response#
97
98 err := c.RPCClientscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Client#RPCClient..Callscip-go gomod github.com/golang/go/src go1.22 `net/rpc`/Client#Call().(req.ServiceMethodscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Request#ServiceMethod., req.Argsscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Request#Args., &resp)
99 if err != nil {
100 return nil, err
101 }
102
103 return resp.ResponseDatascip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Response#ResponseData., checkResponsescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/checkResponse().(&resp)
104 }
105
106 // checkResponse checks the API response for errors, and returns them if present.
107 func checkResponsescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/checkResponse().(r *Responsescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Response#) error {
108 if c := r.Codescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Response#Code.; c >= 1000 && c <= 1500 {
109 return nil
110 }
111
112 return &ErrorResponsescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ErrorResponse#{Codescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ErrorResponse#Code.: r.Codescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Response#Code., Messagescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ErrorResponse#Message.: r.Messagescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Response#Message., Reasonscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ErrorResponse#Reason.: r.Reasonscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Response#Reason., ReasonCodescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ErrorResponse#ReasonCode.: r.ReasonCodescip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/Response#ReasonCode.}
113 }
114
115 func getBaseURLscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/getBaseURL().(opts *ClientOptionsscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ClientOptions#) *urlscip-go gomod github.com/golang/go/src go1.22 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.22 `net/url`/URL# {
116 var useSandbox bool
117 if opts != nil {
118 useSandbox = opts.Sandboxscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ClientOptions#Sandbox.
119 }
120
121 var baseURL *urlscip-go gomod github.com/golang/go/src go1.22 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.22 `net/url`/URL#
122
123 if useSandbox {
124 baseURL, _ = urlscip-go gomod github.com/golang/go/src go1.22 `net/url`/.Parsescip-go gomod github.com/golang/go/src go1.22 `net/url`/Parse().(APISandboxBaseURLscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/APISandboxBaseURL.)
125 } else {
126 baseURL, _ = urlscip-go gomod github.com/golang/go/src go1.22 `net/url`/.Parsescip-go gomod github.com/golang/go/src go1.22 `net/url`/Parse().(APIBaseURLscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/APIBaseURL.)
127 }
128
129 if opts != nil && opts.BaseURLscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ClientOptions#BaseURL. != nil {
130 baseURL = opts.BaseURLscip-go gomod github.com/nrdcg/goinwx . `github.com/nrdcg/goinwx`/ClientOptions#BaseURL.
131 }
132
133 return baseURL
134 }