├── .gitignore
├── .idea
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── dictionaries
│ ├── vishrana.xml
│ └── vr.xml
├── labstack-go.iml
├── misc.xml
├── modules.xml
├── vcs.xml
└── workspace.xml
├── .travis.yml
├── LICENSE
├── Makefile
├── README.md
├── client.go
├── client_test.go
├── currency.go
├── currency
└── currency.go
├── currency_test.go
├── domain.go
├── domain
└── domain.go
├── domain_test.go
├── email.go
├── email
└── email.go
├── email_test.go
├── go.mod
├── go.sum
├── ip.go
├── ip
└── ip.go
├── ip_test.go
├── webpage.go
├── webpage
└── webpage.go
└── webpage_test.go
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | vendor
3 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
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 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/dictionaries/vishrana.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | resty
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/dictionaries/vr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | aaaa
5 | resty
6 | twilio
7 | twillio
8 | whois
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/labstack-go.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
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 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 | 1563934802046
157 |
158 |
159 | 1563934802046
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
188 |
189 |
190 |
191 | true
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 | file://$PROJECT_DIR$/domain.go
236 | 87
237 |
238 |
239 |
240 |
241 |
242 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 | go:
3 | - 1.8.x
4 | - 1.9.x
5 | - tip
6 | install:
7 | - make dependency
8 | # script:
9 | # - make test
10 | after_success:
11 | - bash <(curl -s https://codecov.io/bash)
12 | matrix:
13 | allow_failures:
14 | - go: tip
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2017 LabStack
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | dependency:
2 | go get -u github.com/golang/dep/cmd/dep
3 | dep ensure
4 |
5 | test:
6 | echo "" > coverage.txt
7 | for d in $(shell go list ./... | grep -v vendor); do \
8 | go test -race -coverprofile=profile.out -covermode=atomic $$d || exit 1; \
9 | [ -f profile.out ] && cat profile.out >> coverage.txt && rm profile.out; \
10 | done
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## Go Client
4 |
5 | ## Installation
6 |
7 | `go get github.com/labstack/labstack-go`
8 |
9 | ## Quick Start
10 |
11 | [Sign up](https://labstack.com/signup) to get an API key
12 |
13 | Create a file `app.go` with the following content:
14 |
15 | ```go
16 | package main
17 |
18 | import (
19 | "fmt"
20 |
21 | "github.com/labstack/labstack-go"
22 | )
23 |
24 | func main() {
25 | client := labstack.NewClient("")
26 | geocode := client.Geocode()
27 | res, err := geocode.Address("eiffel tower")
28 | if err != nil {
29 | fmt.Println(err)
30 | } else {
31 | fmt.Printf("%+v", res)
32 | }
33 | }
34 | ```
35 |
36 | From terminal run your app:
37 |
38 | ```sh
39 | go run app.go
40 | ```
41 |
42 | ## [Docs](https://labstack.com/docs) | [Forum](https://forum.labstack.com)
43 |
--------------------------------------------------------------------------------
/client.go:
--------------------------------------------------------------------------------
1 | package labstack
2 |
3 | import (
4 | "github.com/go-resty/resty/v2"
5 | )
6 |
7 | type (
8 | Client struct {
9 | key string
10 | resty *resty.Client
11 | }
12 |
13 | Error struct {
14 | StatusCode int `json:"status_code"`
15 | Code int `json:"code"`
16 | Message string `json:"message"`
17 | }
18 | )
19 |
20 | const (
21 | url = "https://api.labstack.com"
22 | )
23 |
24 | func NewClient(key string) *Client {
25 | return &Client{
26 | key: key,
27 | resty: resty.New().SetHostURL(url).SetAuthToken(key),
28 | }
29 | }
30 |
31 | func (c *Client) Currency() *CurrencyService {
32 | return &CurrencyService{
33 | resty: resty.New().SetHostURL("https://currency.labstack.com/api/v1").SetAuthToken(c.key),
34 | }
35 | }
36 |
37 | func (c *Client) Domain() *DomainService {
38 | return &DomainService{
39 | resty: resty.New().SetHostURL("https://domain.labstack.com/api/v1").SetAuthToken(c.key),
40 | }
41 | }
42 |
43 | func (c *Client) Email() *EmailService {
44 | return &EmailService{
45 | resty: resty.New().SetHostURL("https://email.labstack.com/api/v1").SetAuthToken(c.key),
46 | }
47 | }
48 |
49 | func (c *Client) IP() *IPService {
50 | return &IPService{
51 | resty: resty.New().SetHostURL("https://ip.labstack.com/api/v1").SetAuthToken(c.key),
52 | }
53 | }
54 |
55 | func (c *Client) Webpage() *WebpageService {
56 | return &WebpageService{
57 | resty: resty.New().SetHostURL("https://webpage.labstack.com/api/v1").SetAuthToken(c.key),
58 | }
59 | }
60 |
61 | func isError(status int) bool {
62 | return status < 200 || status >= 300
63 | }
64 |
65 | func (e *Error) Error() string {
66 | return e.Message
67 | }
68 |
--------------------------------------------------------------------------------
/client_test.go:
--------------------------------------------------------------------------------
1 | package labstack
2 |
3 | import "os"
4 |
5 | var (
6 | client = NewClient(os.Getenv("KEY"))
7 | cs = client.Currency()
8 | ds = client.Domain()
9 | es = client.Email()
10 | is = client.IP()
11 | ws = client.Webpage()
12 | )
13 |
--------------------------------------------------------------------------------
/currency.go:
--------------------------------------------------------------------------------
1 | package labstack
2 |
3 | import (
4 | "github.com/go-resty/resty/v2"
5 | "github.com/labstack/labstack-go/currency"
6 | "strconv"
7 | )
8 |
9 | type (
10 | CurrencyService struct {
11 | resty *resty.Client
12 | }
13 | )
14 |
15 | func (c *CurrencyService) Convert(req *currency.ConvertRequest) (*currency.ConvertResponse, error) {
16 | res := new(currency.ConvertResponse)
17 | err := new(Error)
18 | r, e := c.resty.R().
19 | SetPathParams(map[string]string{
20 | "amount": strconv.FormatFloat(req.Amount, 'f', -1, 64),
21 | "from": req.From,
22 | "to": req.To,
23 | }).
24 | SetResult(res).
25 | SetError(err).
26 | Get("/convert/{amount}/{from}/{to}")
27 | if e != nil {
28 | return nil, &Error{
29 | Message: e.Error(),
30 | }
31 | }
32 | if isError(r.StatusCode()) {
33 | return nil, err
34 | }
35 | return res, nil
36 | }
37 |
38 | func (c *CurrencyService) List(req *currency.ListRequest) (*currency.ListResponse, error) {
39 | res := new(currency.ListResponse)
40 | err := new(Error)
41 | r, e := c.resty.R().
42 | SetResult(res).
43 | SetError(err).
44 | Get("/list")
45 | if e != nil {
46 | return nil, &Error{
47 | Message: e.Error(),
48 | }
49 | }
50 | if isError(r.StatusCode()) {
51 | return nil, err
52 | }
53 | return res, nil
54 | }
55 |
56 | func (c *CurrencyService) Rates(req *currency.RatesRequest) (*currency.RatesResponse, error) {
57 | res := new(currency.RatesResponse)
58 | err := new(Error)
59 | r, e := c.resty.R().
60 | SetResult(res).
61 | SetError(err).
62 | Get("/rates")
63 | if e != nil {
64 | return nil, &Error{
65 | Message: e.Error(),
66 | }
67 | }
68 | if isError(r.StatusCode()) {
69 | return nil, err
70 | }
71 | return res, nil
72 | }
73 |
--------------------------------------------------------------------------------
/currency/currency.go:
--------------------------------------------------------------------------------
1 | package currency
2 |
3 | import (
4 | "time"
5 | )
6 |
7 | type (
8 | Currency struct {
9 | Name string `json:"name"`
10 | Code string `json:"code"`
11 | Symbol string `json:"symbol"`
12 | }
13 |
14 | ConvertRequest struct {
15 | Amount float64
16 | From string
17 | To string
18 | }
19 |
20 | ConvertResponse struct {
21 | Time time.Time `json:"time"`
22 | Amount float64 `json:"amount"`
23 | }
24 |
25 | ListRequest struct {
26 | }
27 |
28 | ListResponse struct {
29 | Currencies []*Currency `json:"currencies"`
30 | }
31 |
32 | RatesRequest struct {
33 | }
34 |
35 | RatesResponse struct {
36 | Time time.Time `json:"time"`
37 | Base string `json:"base"`
38 | Rates map[string]float64 `json:"rates"`
39 | }
40 | )
41 |
--------------------------------------------------------------------------------
/currency_test.go:
--------------------------------------------------------------------------------
1 | package labstack
2 |
3 | import (
4 | "github.com/labstack/labstack-go/currency"
5 | "github.com/stretchr/testify/assert"
6 | "testing"
7 | )
8 |
9 | func TestClient_Convert(t *testing.T) {
10 | res, err := cs.Convert(¤cy.ConvertRequest{
11 | Amount: 10,
12 | From: "USD",
13 | To: "INR",
14 | })
15 | if assert.Nil(t, err) {
16 | assert.NotZero(t, res.Amount)
17 | }
18 | }
19 |
20 | func TestClient_List(t *testing.T) {
21 | res, err := cs.List(¤cy.ListRequest{})
22 | if assert.Nil(t, err) {
23 | assert.NotZero(t, len(res.Currencies))
24 | }
25 | }
26 |
27 | func TestClient_Rates(t *testing.T) {
28 | res, err := cs.Rates(¤cy.RatesRequest{})
29 | if assert.Nil(t, err) {
30 | assert.NotZero(t, len(res.Rates))
31 | }
32 | }
--------------------------------------------------------------------------------
/domain.go:
--------------------------------------------------------------------------------
1 | package labstack
2 |
3 | import (
4 | "github.com/go-resty/resty/v2"
5 | "github.com/labstack/labstack-go/domain"
6 | )
7 |
8 | type (
9 | DomainService struct {
10 | resty *resty.Client
11 | }
12 | )
13 |
14 | func (d *DomainService) DNS(req *domain.DNSRequest) (*domain.DNSResponse, error) {
15 | res := new(domain.DNSResponse)
16 | err := new(Error)
17 | r, e := d.resty.R().
18 | SetPathParams(map[string]string{
19 | "type": req.Type,
20 | "domain": req.Domain,
21 | }).
22 | SetResult(res).
23 | SetError(err).
24 | Get("/{type}/{domain}")
25 | if e != nil {
26 | return nil, &Error{
27 | Message: err.Error(),
28 | }
29 | }
30 | if isError(r.StatusCode()) {
31 | return nil, err
32 | }
33 | return res, nil
34 | }
35 |
36 | func (d *DomainService) Search(req *domain.SearchRequest) (*domain.SearchResponse, error) {
37 | res := new(domain.SearchResponse)
38 | err := new(Error)
39 | r, e := d.resty.R().
40 | SetQueryParam("q", req.Q).
41 | SetResult(res).
42 | SetError(err).
43 | Get("/search")
44 | if e != nil {
45 | return nil, &Error{
46 | Message: err.Error(),
47 | }
48 | }
49 | if isError(r.StatusCode()) {
50 | return nil, err
51 | }
52 | return res, nil
53 | }
54 |
55 | func (d *DomainService) Status(req *domain.StatusRequest) (*domain.StatusResponse, error) {
56 | res := new(domain.StatusResponse)
57 | err := new(Error)
58 | r, e := d.resty.R().
59 | SetPathParams(map[string]string{
60 | "domain": req.Domain,
61 | }).
62 | SetResult(res).
63 | SetError(err).
64 | Get("/status/{domain}")
65 | if e != nil {
66 | return nil, &Error{
67 | Message: err.Error(),
68 | }
69 | }
70 | if isError(r.StatusCode()) {
71 | return nil, err
72 | }
73 | return res, nil
74 | }
75 |
76 | func (d *DomainService) Whois(req *domain.WhoisRequest) (*domain.WhoisResponse, error) {
77 | res := new(domain.WhoisResponse)
78 | err := new(Error)
79 | r, e := d.resty.R().
80 | SetPathParams(map[string]string{
81 | "domain": req.Domain,
82 | }).
83 | SetResult(res).
84 | SetError(err).
85 | Get("/whois/{domain}")
86 | if e != nil {
87 | return nil, &Error{
88 | Message: err.Error(),
89 | }
90 | }
91 | if isError(r.StatusCode()) {
92 | return nil, err
93 | }
94 | return res, nil
95 | }
96 |
--------------------------------------------------------------------------------
/domain/domain.go:
--------------------------------------------------------------------------------
1 | package domain
2 |
3 | type (
4 | Record struct {
5 | Domain string `json:"domain"`
6 | Type string `json:"type"`
7 | Server string `json:"server"`
8 | A string
9 | AAAA string
10 | CNAME string
11 | MX string
12 | NS string
13 | PTR string
14 | Serial int `json:"serial"`
15 | Refresh int `json:"refresh"`
16 | Retry int `json:"retry"`
17 | Expire int `json:"expire"`
18 | Priority int `json:"priority"`
19 | Weight int `json:"weight"`
20 | Port int `json:"port"`
21 | Target string `json:"target"`
22 | TXT []string
23 | TTL int `json:"ttl"`
24 | Class string `json:"class"`
25 | SPF []string
26 | }
27 |
28 | Result struct {
29 | Domain string `json:"domain"`
30 | Zone string `json:"zone"`
31 | }
32 |
33 | Registrar struct {
34 | Id string `json:"id"`
35 | Name string `json:"name"`
36 | Url string `json:"url"`
37 | WhoisServer string `json:"whois_server"`
38 | }
39 |
40 | Registrant struct {
41 | Id string `json:"id"`
42 | Name string `json:"name"`
43 | Organization string `json:"organization"`
44 | Street string `json:"street"`
45 | City string `json:"city"`
46 | State string `json:"state"`
47 | Zip string `json:"zip"`
48 | Country string `json:"country"`
49 | Phone string `json:"phone"`
50 | Fax string `json:"fax"`
51 | Email string `json:"email"`
52 | }
53 |
54 | DNSRequest struct {
55 | Type string
56 | Domain string
57 | }
58 |
59 | DNSResponse struct {
60 | Records []*Record
61 | }
62 |
63 | SearchRequest struct {
64 | Q string
65 | }
66 |
67 | SearchResponse struct {
68 | Results []*Result
69 | }
70 |
71 | StatusRequest struct {
72 | Domain string
73 | }
74 |
75 | StatusResponse struct {
76 | Domain string `json:"domain"`
77 | Zone string `json:"zone"`
78 | Result string `json:"result"`
79 | Flags []string `json:"flags"`
80 | }
81 |
82 | WhoisRequest struct {
83 | Domain string
84 | }
85 |
86 | WhoisResponse struct {
87 | Domain string `json:"domain"`
88 | Id string `json:"id"`
89 | Status string `json:"status"`
90 | CreatedDate string `json:"created_date"`
91 | UpdatedDate string `json:"updated_date"`
92 | ExpiryDate string `json:"expiry_date"`
93 | NameServers []string `json:"name_servers"`
94 | Dnssec string `json:"dnssec"`
95 | Registrar *Registrar `json:"registrar"`
96 | Registrant *Registrant `json:"registrant"`
97 | Admin *Registrant `json:"admin"`
98 | Technical *Registrant `json:"technical"`
99 | Billing *Registrant `json:"billing"`
100 | Raw string `json:"raw"`
101 | }
102 | )
103 |
--------------------------------------------------------------------------------
/domain_test.go:
--------------------------------------------------------------------------------
1 | package labstack
2 |
3 | import (
4 | "testing"
5 |
6 | "github.com/labstack/labstack-go/domain"
7 | "github.com/stretchr/testify/assert"
8 | )
9 |
10 | func TestClient_DNS(t *testing.T) {
11 | res, err := ds.DNS(&domain.DNSRequest{
12 | Type: "A",
13 | Domain: "twilio.com",
14 | })
15 | if assert.Nil(t, err) {
16 | assert.NotZero(t, len(res.Records))
17 | }
18 | }
19 |
20 | func TestClient_Search(t *testing.T) {
21 | res, err := ds.Search(&domain.SearchRequest{
22 | Q: "twilio",
23 | })
24 | if assert.Nil(t, err) {
25 | assert.NotZero(t, len(res.Results))
26 | }
27 | }
28 |
29 | func TestClient_Status(t *testing.T) {
30 | res, err := ds.Status(&domain.StatusRequest{
31 | Domain: "twilio.com",
32 | })
33 | if assert.Nil(t, err) {
34 | assert.Equal(t, "unavailable", res.Result)
35 | }
36 | }
37 |
38 | func TestClient_Whois(t *testing.T) {
39 | res, err := ds.Whois(&domain.WhoisRequest{
40 | Domain: "twilio.com",
41 | })
42 | if assert.Nil(t, err) {
43 | assert.NotEmpty(t, res.Raw)
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/email.go:
--------------------------------------------------------------------------------
1 | package labstack
2 |
3 | import (
4 | "github.com/go-resty/resty/v2"
5 | "github.com/labstack/labstack-go/email"
6 | )
7 |
8 | type (
9 | EmailService struct {
10 | resty *resty.Client
11 | }
12 | )
13 |
14 | func (es *EmailService) Verify(req *email.VerifyRequest) (*email.VerifyResponse, error) {
15 | res := new(email.VerifyResponse)
16 | err := new(Error)
17 | r, e := es.resty.R().
18 | SetPathParams(map[string]string{
19 | "email": req.Email,
20 | }).
21 | SetResult(res).
22 | SetError(err).
23 | Get("/verify/{email}")
24 | if e != nil {
25 | return nil, &Error{
26 | Message: err.Error(),
27 | }
28 | }
29 | if isError(r.StatusCode()) {
30 | return nil, err
31 | }
32 | return res, nil
33 | }
34 |
--------------------------------------------------------------------------------
/email/email.go:
--------------------------------------------------------------------------------
1 | package email
2 |
3 | type (
4 | VerifyRequest struct {
5 | Email string
6 | }
7 |
8 | VerifyResponse struct {
9 | Email string `json:"email"`
10 | Username string `json:"username"`
11 | Domain string `json:"domain"`
12 | Result string `json:"result"`
13 | Flags []string `json:"flags"`
14 | }
15 | )
16 |
17 |
--------------------------------------------------------------------------------
/email_test.go:
--------------------------------------------------------------------------------
1 | package labstack
2 |
3 | import (
4 | "github.com/labstack/labstack-go/email"
5 | "github.com/stretchr/testify/assert"
6 | "testing"
7 | )
8 |
9 | func TestClient_Verify(t *testing.T) {
10 | res, err := es.Verify(&email.VerifyRequest{
11 | Email: "jon@labstack.com",
12 | })
13 | if assert.Nil(t, err) {
14 | assert.Equal(t, "deliverable", res.Result)
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/labstack/labstack-go
2 |
3 | go 1.12
4 |
5 | require (
6 | github.com/go-resty/resty/v2 v2.0.0
7 | github.com/labstack/gommon v0.2.9
8 | github.com/stretchr/testify v1.3.0
9 | )
10 |
--------------------------------------------------------------------------------
/go.sum:
--------------------------------------------------------------------------------
1 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4 | github.com/go-resty/resty/v2 v2.0.0 h1:9Nq/U+V4xsoDnDa/iTrABDWUCuk3Ne92XFHPe6dKWUc=
5 | github.com/go-resty/resty/v2 v2.0.0/go.mod h1:dZGr0i9PLlaaTD4H/hoZIDjQ+r6xq8mgbRzHZf7f2J8=
6 | github.com/labstack/gommon v0.2.9 h1:heVeuAYtevIQVYkGj6A41dtfT91LrvFG220lavpWhrU=
7 | github.com/labstack/gommon v0.2.9/go.mod h1:E8ZTmW9vw5az5/ZyHWCp0Lw4OH2ecsaBP1C/NKavGG4=
8 | github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
9 | github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
10 | github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
11 | github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
12 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
13 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
14 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
15 | github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
16 | github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
17 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
18 | github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
19 | github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
20 | github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
21 | github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
22 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
23 | golang.org/x/net v0.0.0-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU=
24 | golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
25 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
26 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
27 | golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed h1:uPxWBzB3+mlnjy9W58qY1j/cjyFjutgw/Vhan2zLy/A=
28 | golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
29 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
30 |
--------------------------------------------------------------------------------
/ip.go:
--------------------------------------------------------------------------------
1 | package labstack
2 |
3 | import (
4 | "github.com/go-resty/resty/v2"
5 | "github.com/labstack/labstack-go/ip"
6 | )
7 |
8 | type (
9 | IPService struct {
10 | resty *resty.Client
11 | }
12 | )
13 |
14 | func (i *IPService) Lookup(req *ip.LookupRequest) (*ip.LookupResponse, error) {
15 | res := new(ip.LookupResponse)
16 | err := new(Error)
17 | r, e := i.resty.R().
18 | SetPathParams(map[string]string{
19 | "ip": req.IP,
20 | }).
21 | SetResult(res).
22 | SetError(err).
23 | Get("/{ip}")
24 | if e != nil {
25 | return nil, &Error{
26 | Message: e.Error(),
27 | }
28 | }
29 | if isError(r.StatusCode()) {
30 | return nil, err
31 | }
32 | return res, nil
33 | }
34 |
--------------------------------------------------------------------------------
/ip/ip.go:
--------------------------------------------------------------------------------
1 | package ip
2 |
3 | import (
4 | "time"
5 | )
6 |
7 | type (
8 | Organization struct {
9 | Name string `json:"name"`
10 | }
11 |
12 | Flag struct {
13 | SVG string `json:"svg"`
14 | PNG string `json:"png"`
15 | Emoji string `json:"emoji"`
16 | }
17 |
18 | TimeZone struct {
19 | ID string `json:"id"`
20 | Name string `json:"name"`
21 | Abbreviation string `json:"abbreviation"`
22 | Offset int `json:"offset"`
23 | Time time.Time `json:"time"`
24 | }
25 |
26 | AS struct {
27 | Number int `json:"number"`
28 | Name string `json:"name"`
29 | Organization string `json:"organization"`
30 | }
31 |
32 | LookupRequest struct {
33 | IP string
34 | }
35 |
36 | LookupResponse struct {
37 | IP string `json:"ip"`
38 | Hostname string `json:"hostname"`
39 | Version string `json:"version"`
40 | City string `json:"city"`
41 | Region string `json:"region"`
42 | RegionCode string `json:"region_code"`
43 | Postal string `json:"postal"`
44 | Country string `json:"country"`
45 | CountryCode string `json:"country_code"`
46 | Latitude float64 `json:"latitude"`
47 | Longitude float64 `json:"longitude"`
48 | Organization *Organization `json:"organization"`
49 | Flag *Flag `json:"flag"`
50 | Currencies []string `json:"currencies"`
51 | TimeZone *TimeZone `json:"time_zone"`
52 | Language []string `json:"languages"`
53 | AS *AS `json:"as"`
54 | Flags []string `json:"flags"`
55 | }
56 | )
57 |
58 |
--------------------------------------------------------------------------------
/ip_test.go:
--------------------------------------------------------------------------------
1 | package labstack
2 |
3 | import (
4 | "github.com/labstack/labstack-go/ip"
5 | "github.com/stretchr/testify/assert"
6 | "testing"
7 | )
8 |
9 | func TestClient_Lookup(t *testing.T) {
10 | res, err := is.Lookup(&ip.LookupRequest{
11 | IP: "96.45.83.67",
12 | })
13 | if assert.Nil(t, err) {
14 | assert.NotEmpty(t, res.Country)
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/webpage.go:
--------------------------------------------------------------------------------
1 | package labstack
2 |
3 | import (
4 | "github.com/go-resty/resty/v2"
5 | "github.com/labstack/labstack-go/webpage"
6 | "strconv"
7 | )
8 |
9 | type (
10 | WebpageService struct {
11 | resty *resty.Client
12 | }
13 | )
14 |
15 | func (w *WebpageService) Image(req *webpage.ImageRequest) (*webpage.ImageResponse, error) {
16 | res := new(webpage.ImageResponse)
17 | err := new(Error)
18 | r, e := w.resty.R().
19 | SetQueryParams(map[string]string{
20 | "url": req.URL,
21 | "language": req.Language,
22 | "ttl": strconv.Itoa(req.TTL),
23 | "full_page": strconv.FormatBool(req.FullPage),
24 | "retina": strconv.FormatBool(req.Retina),
25 | "width": strconv.Itoa(req.Width),
26 | "height": strconv.Itoa(req.Height),
27 | "delay": strconv.Itoa(req.Delay),
28 | }).
29 | SetResult(res).
30 | SetError(err).
31 | Get("/image")
32 | if e != nil {
33 | return nil, &Error{
34 | Message: err.Error(),
35 | }
36 | }
37 | if isError(r.StatusCode()) {
38 | return nil, err
39 | }
40 | return res, nil
41 | }
42 |
43 | func (w *WebpageService) PDF(req *webpage.PDFRequest) (*webpage.PDFResponse, error) {
44 | res := new(webpage.PDFResponse)
45 | err := new(Error)
46 | r, e := w.resty.R().
47 | SetQueryParams(map[string]string{
48 | "url": req.URL,
49 | "language": req.Language,
50 | "ttl": strconv.Itoa(req.TTL),
51 | "size": req.Size,
52 | "width": strconv.Itoa(req.Width),
53 | "height": strconv.Itoa(req.Height),
54 | "orientation": req.Orientation,
55 | "delay": strconv.Itoa(req.Delay),
56 | }).
57 | SetResult(res).
58 | SetError(err).
59 | Get("/pdf")
60 | if e != nil {
61 | return nil, &Error{
62 | Message: err.Error(),
63 | }
64 | }
65 | if isError(r.StatusCode()) {
66 | return nil, err
67 | }
68 | return res, nil
69 | }
70 |
--------------------------------------------------------------------------------
/webpage/webpage.go:
--------------------------------------------------------------------------------
1 | package webpage
2 |
3 | type (
4 | ImageRequest struct {
5 | URL string
6 | Language string
7 | TTL int
8 | FullPage bool
9 | Retina bool
10 | Width int
11 | Height int
12 | Delay int
13 | }
14 |
15 | ImageResponse struct {
16 | Image string `json:"image"`
17 | Cached bool `json:"cached"`
18 | Took int `json:"took"`
19 | GeneratedAt string `json:"generated_at"`
20 | }
21 |
22 | PDFRequest struct {
23 | URL string
24 | Language string
25 | TTL int
26 | Size string
27 | Width int
28 | Height int
29 | Orientation string
30 | Delay int
31 | }
32 |
33 | PDFResponse struct {
34 | PDF string `json:"pdf"`
35 | Cached bool `json:"cached"`
36 | Took int `json:"took"`
37 | GeneratedAt string `json:"generated_at"`
38 | }
39 | )
40 |
41 |
--------------------------------------------------------------------------------
/webpage_test.go:
--------------------------------------------------------------------------------
1 | package labstack
2 |
3 | import (
4 | "github.com/labstack/labstack-go/webpage"
5 | "github.com/stretchr/testify/assert"
6 | "testing"
7 | )
8 |
9 | func TestClient_Image(t *testing.T) {
10 | res, err := ws.Image(&webpage.ImageRequest{
11 | URL: "amazon.com",
12 | })
13 | if assert.Nil(t, err) {
14 | assert.NotEmpty(t, res.Image)
15 | }
16 | }
17 |
18 | func TestClient_PDF(t *testing.T) {
19 | res, err := ws.PDF(&webpage.PDFRequest{
20 | URL: "amazon.com",
21 | })
22 | if assert.Nil(t, err) {
23 | assert.NotEmpty(t, res.PDF)
24 | }
25 | }
26 |
--------------------------------------------------------------------------------