-
Notifications
You must be signed in to change notification settings - Fork 69
/
request.go
42 lines (37 loc) · 956 Bytes
/
request.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
package whois
const (
// IANA is the default whois server for TLDs.
IANA = "whois.iana.org"
)
// Request represents a whois request.
type Request struct {
Query string
Host string
URL string
Body []byte
}
// NewRequest returns a prepared Request ready to fetch.
// On error, returns a nil Request and the error.
func NewRequest(query string) (*Request, error) {
req := &Request{Query: query}
if err := req.Prepare(); err != nil {
return nil, err
}
return req, nil
}
// Prepare prepares a Request with an appropriate Adapter.
// First resolves whois server in req.Host if not already set.
// Returns any errors.
func (req *Request) Prepare() error {
var err error
if req.Host == "" {
if req.Host, req.URL, err = Server(req.Query); err != nil {
return err
}
}
return req.Adapter().Prepare(req)
}
// Adapter returns an appropriate Adapter for the Request.
func (req *Request) Adapter() Adapter {
return adapterFor(req.Host)
}