• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H19-May-2021-

dnsimple/H19-May-2021-

fixtures.http/H19-May-2021-

.gitignoreH A D19-May-202113

.tool-versionsH A D19-May-202114

.travis.ymlH A D19-May-2021424

CHANGELOG.mdH A D19-May-20215.5 KiB

CONTRIBUTING.mdH A D19-May-20212.1 KiB

README.mdH A D19-May-20214.8 KiB

go.modH A D19-May-2021158

go.sumH A D19-May-20211.8 KiB

README.md

1# DNSimple Go Client
2
3A Go client for the [DNSimple API v2](https://developer.dnsimple.com/v2/).
4
5[![Build Status](https://travis-ci.com/dnsimple/dnsimple-go.svg?branch=master)](https://travis-ci.com/dnsimple/dnsimple-go)
6[![GoDoc](https://godoc.org/github.com/dnsimple/dnsimple-go/dnsimple?status.svg)](https://godoc.org/github.com/dnsimple/dnsimple-go/dnsimple)
7
8
9## Installation
10
11```
12go get github.com/dnsimple/dnsimple-go/dnsimple
13```
14
15
16## Usage
17
18This library is a Go client you can use to interact with the [DNSimple API v2](https://developer.dnsimple.com/v2/). Here are some examples.
19
20```go
21package main
22
23import (
24    "context"
25    "fmt"
26    "os"
27    "strconv"
28
29    "github.com/dnsimple/dnsimple-go/dnsimple"
30)
31
32func main() {
33    tc := dnsimple.StaticTokenHTTPClient(context.Background(), "your-token")
34
35    // new client
36    client := dnsimple.NewClient(tc)
37
38    // get the current authenticated account (if you don't know who you are)
39    whoamiResponse, err := client.Identity.Whoami(context.Background())
40    if err != nil {
41        fmt.Printf("Whoami() returned error: %v\n", err)
42        os.Exit(1)
43    }
44
45    fmt.Println(whoamiResponse.Data.Account)
46    fmt.Println(whoamiResponse.Data.User)
47
48    // either assign the account ID or fetch it from the response
49    // if you are authenticated with an account token
50    accountID := strconv.FormatInt(whoamiResponse.Data.Account.ID, 10)
51
52    // get the list of domains
53    domainsResponse, err := client.Domains.ListDomains(context.Background(), accountID, nil)
54    if err != nil {
55        fmt.Printf("Domains.ListDomains() returned error: %v\n", err)
56        os.Exit(1)
57    }
58
59    // iterate over all the domains in the
60    // paginated response.
61    for _, domain := range domainsResponse.Data {
62        fmt.Println(domain)
63    }
64
65    // List methods support a variety of options to paginate, sort and filter records.
66    // Here's a few example:
67
68    // get the list of domains filtered by name and sorted by expiration
69    client.Domains.ListDomains(context.Background(), accountID, &dnsimple.DomainListOptions{NameLike: dnsimple.String("com"), ListOptions: {Sort: dnsimple.String("expiration:DESC")}})
70}
71```
72
73For more complete documentation, see [godoc](https://godoc.org/github.com/dnsimple/dnsimple-go/dnsimple).
74
75
76## Authentication
77
78When creating a new client you are required to provide an `http.Client` to use for authenticating the requests.
79Supported authentication mechanisms are OAuth and HTTP Digest. We provide convenient helpers to generate a preconfigured HTTP client.
80
81**Authenticating with OAuth**
82
83```go
84tc := dnsimple.StaticTokenHTTPClient(context.Background(), "your-token")
85
86// new client
87client := dnsimple.NewClient(tc)
88```
89
90**Authenticating with HTTP Basic Auth**
91
92```go
93hc := dnsimple.BasicAuthHTTPClient(context.Background(), "your-user", "your-password")
94client := dnsimple.NewClient(hc)
95```
96
97For requests made to authorize OAuth access, and to exchange the short lived authorization token for the OAuth token, use an HTTP client with a timeout:
98
99```go
100client := dnsimple.NewClient(&http.Client{Timeout: time.Second * 10})
101```
102
103For any other custom need you can define your own `http.RoundTripper` implementation and
104pass a client that authenticated with the custom round tripper.
105
106
107## Sandbox Environment
108
109We highly recommend testing against our [sandbox environment](https://developer.dnsimple.com/sandbox/) before using our production environment. This will allow you to avoid real purchases, live charges on your credit card, and reduce the chance of your running up against rate limits.
110
111The client supports both the production and sandbox environment. To switch to sandbox pass the sandbox API host using the `base_url` option when you construct the client:
112
113```go
114client := dnsimple.NewClient(tc)
115client.BaseURL = "https://api.sandbox.dnsimple.com"
116```
117
118You will need to ensure that you are using an access token created in the sandbox environment. Production tokens will *not* work in the sandbox environment.
119
120
121## Setting a custom `User-Agent` header
122
123You can customize the `User-Agent` header for the calls made to the DNSimple API:
124
125```go
126client := dnsimple.NewClient(tc)
127client.SetUserAgent("my-app/1.0")
128```
129
130The value you provide will be prepended to the default `User-Agent` the client uses. For example, if you use `my-app/1.0`, the final header value will be `my-app/1.0 dnsimple-go/0.14.0` (note that it will vary depending on the client version).
131
132We recommend to customize the user agent. If you are building a library or integration on top of the official client, customizing the client will help us to understand what is this client used for, and allow to contribute back or get in touch.
133
134
135## Contributing
136
137For instructions about contributing and testing, visit the [CONTRIBUTING](CONTRIBUTING.md) file.
138
139
140## License
141
142Copyright (c) 2014-2020 DNSimple Corporation. This is Free Software distributed under the MIT license.
143