Skip to content

Commit dd6678a

Browse files
committed
Create API
1 parent 2a24937 commit dd6678a

13 files changed

+700
-0
lines changed

.gitignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories (remove the comment below to include it)
15+
# vendor/
16+
17+
*.csv
18+
*.tsv
19+
bin/*

Makefile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.PHONY: init lint
2+
3+
GO111MODULE=on
4+
LINT_OPT := -E gofmt \
5+
-E golint \
6+
-E govet \
7+
-E gosec \
8+
-E unused \
9+
-E gosimple \
10+
-E structcheck \
11+
-E varcheck \
12+
-E ineffassign \
13+
-E deadcode \
14+
-E typecheck \
15+
-E misspell \
16+
-E whitespace \
17+
-E errcheck \
18+
--exclude '(comment on exported (method|function|type|const|var)|should have( a package)? comment|comment should be of the form)' \
19+
--timeout 5m
20+
21+
init:
22+
go mod download
23+
24+
lint:
25+
@type golangci-lint > /dev/null || go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
26+
golangci-lint $(LINT_OPT) run ./...

README.md

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
bigdatacloud-go
2+
----
3+
4+
[![License: MIT][401]][402] [![GoDoc][101]][102] [![Release][103]][104] [![Build Status][201]][202] [![Coveralls Coverage][203]][204] [![Codecov Coverage][205]][206]
5+
[![Go Report Card][301]][302] [![Code Climate][303]][304] [![BCH compliance][305]][306] [![CodeFactor][307]][308] [![codebeat][309]][310] [![Scrutinizer Code Quality][311]][312] [![FOSSA Status][403]][404]
6+
7+
8+
<!-- Basic -->
9+
10+
[101]: https://godoc.org/github.com/evalphobia/bigdatacloud-go?status.svg
11+
[102]: https://godoc.org/github.com/evalphobia/bigdatacloud-go
12+
[103]: https://img.shields.io/github/release/evalphobia/bigdatacloud-go.svg
13+
[104]: https://github.com/evalphobia/bigdatacloud-go/releases/latest
14+
[105]: https://img.shields.io/github/downloads/evalphobia/bigdatacloud-go/total.svg?maxAge=1800
15+
[106]: https://github.com/evalphobia/bigdatacloud-go/releases
16+
[107]: https://img.shields.io/github/stars/evalphobia/bigdatacloud-go.svg
17+
[108]: https://github.com/evalphobia/bigdatacloud-go/stargazers
18+
19+
20+
<!-- Testing -->
21+
22+
[201]: https://github.com/evalphobia/bigdatacloud-go/workflows/test/badge.svg
23+
[202]: https://github.com/evalphobia/bigdatacloud-go/actions?query=workflow%3Atest
24+
[203]: https://coveralls.io/repos/evalphobia/bigdatacloud-go/badge.svg?branch=master&service=github
25+
[204]: https://coveralls.io/github/evalphobia/bigdatacloud-go?branch=master
26+
[205]: https://codecov.io/gh/evalphobia/bigdatacloud-go/branch/master/graph/badge.svg
27+
[206]: https://codecov.io/gh/evalphobia/bigdatacloud-go
28+
29+
30+
<!-- Code Quality -->
31+
32+
[301]: https://goreportcard.com/badge/github.com/evalphobia/bigdatacloud-go
33+
[302]: https://goreportcard.com/report/github.com/evalphobia/bigdatacloud-go
34+
[303]: https://codeclimate.com/github/evalphobia/bigdatacloud-go/badges/gpa.svg
35+
[304]: https://codeclimate.com/github/evalphobia/bigdatacloud-go
36+
[305]: https://bettercodehub.com/edge/badge/evalphobia/bigdatacloud-go?branch=master
37+
[306]: https://bettercodehub.com/
38+
[307]: https://www.codefactor.io/repository/github/evalphobia/bigdatacloud-go/badge
39+
[308]: https://www.codefactor.io/repository/github/evalphobia/bigdatacloud-go
40+
[309]: https://codebeat.co/badges/142f5ca7-da37-474f-9264-f708ade08b5c
41+
[310]: https://codebeat.co/projects/github-com-evalphobia-bigdatacloud-go-master
42+
[311]: https://scrutinizer-ci.com/g/evalphobia/bigdatacloud-go/badges/quality-score.png?b=master
43+
[312]: https://scrutinizer-ci.com/g/evalphobia/bigdatacloud-go/?branch=master
44+
45+
<!-- License -->
46+
[401]: https://img.shields.io/badge/License-MIT-blue.svg
47+
[402]: LICENSE.md
48+
[403]: https://app.fossa.com/api/projects/git%2Bgithub.com%2Fevalphobia%2Fbigdatacloud-go.svg?type=shield
49+
[404]: https://app.fossa.com/projects/git%2Bgithub.com%2Fevalphobia%2Fbigdatacloud-go?ref=badge_shield
50+
51+
52+
Unofficial golang library for [Big Data Cloud](https://www.bigdatacloud.com/).
53+
54+
55+
# Quick Usage for API
56+
57+
```go
58+
package main
59+
60+
import (
61+
"fmt"
62+
63+
"github.com/evalphobia/bigdatacloud-go/config"
64+
"github.com/evalphobia/bigdatacloud-go/bigdatacloud"
65+
)
66+
67+
func main() {
68+
conf := config.Config{
69+
// you can set auth values to config directly, otherwise used from environment variables.
70+
APIKey: "<your API Key>",
71+
Language: "en", // default=en
72+
Debug: false,
73+
}
74+
75+
svc, err := bigdatacloud.New(conf)
76+
if err != nil {
77+
panic(err)
78+
}
79+
80+
// execute score API
81+
resp, err := svc.IPGeolocationFull("8.8.8.8")
82+
if err != nil {
83+
panic(err)
84+
}
85+
if resp.HasError() {
86+
panic(fmt.Errorf("code=[%s] description=[%s]", resp.ErrData.Code, resp.ErrData.Description))
87+
}
88+
89+
// just print response in json format
90+
b, _ := json.Marshal(resp)
91+
fmt.Printf("%s", string(b))
92+
}
93+
```
94+
95+
see example dir for more examples, and see [official API document](https://www.bigdatacloud.com/ip-geolocation-apis/ip-address-geolocation-with-confidence-area-and-hazard-report-api) for more details (especially request/response).
96+
97+
98+
# Environment variables
99+
100+
| Name | Description |
101+
|:--|:--|
102+
| `BIGDATACLOUD_APIKEY` | [Big Data Cloud API Key](https://www.bigdatacloud.com/sdk). |
103+
| `BIGDATACLOUD_LANGUAGE` | [Big Data Cloud localityLanguage](https://www.bigdatacloud.com/ip-geolocation-apis/ip-address-geolocation-with-confidence-area-and-hazard-report-api). |

bigdatacloud/base_response.go

+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
package bigdatacloud
2+
3+
type ErrData struct {
4+
StatusCode int `json:"status_code"`
5+
Status int64 `json:"status"`
6+
Description string `json:"description"`
7+
}
8+
9+
func (r *ErrData) SetStatusCode(code int) {
10+
r.StatusCode = code
11+
}
12+
13+
func (r ErrData) HasError() bool {
14+
return r.StatusCode >= 400
15+
}
16+
17+
// IPResponse is a response data of IP Geolocation APIs.
18+
// ref: https://www.bigdatacloud.com/ip-geolocation-apis
19+
type IPResponse struct {
20+
ErrData
21+
22+
IP string `json:"ip"`
23+
LocalityLanguageRequested string `json:"localityLanguageRequested"`
24+
IsReachableGlobally bool `json:"isReachableGlobally"`
25+
Country Country `json:"country"`
26+
Location Location `json:"location"`
27+
LastUpdated string `json:"lastUpdated"`
28+
Network Network `json:"network"`
29+
Confidence string `json:"confidence"`
30+
ConfidenceArea []Area `json:"confidenceArea"`
31+
SecurityThreat string `json:"securityThreat"`
32+
HazardReport HazardReport `json:"hazardReport"`
33+
}
34+
35+
type Country struct {
36+
ISOAlpha2 string `json:"isoAlpha2"`
37+
ISOAlpha3 string `json:"isoAlpha3"`
38+
M49Code int64 `json:"m49Code"`
39+
Name string `json:"name"`
40+
ISOName string `json:"isoName"`
41+
ISONameFull string `json:"isoNameFull"`
42+
ISOAdminLanguages []ISOAdminLanguage `json:"isoAdminLanguages"`
43+
UNRegion string `json:"unRegion"`
44+
Currency Currency `json:"currency"`
45+
WBRegion WBRegion `json:"wbRegion"`
46+
WBIncomeLevel WBIncomeLevel `json:"wbIncomeLevel"`
47+
CallingCode string `json:"callingCode"`
48+
CountryFlagEmoji string `json:"countryFlagEmoji"`
49+
WikidataID string `json:"wikidataId"`
50+
GeonameID int64 `json:"geonameId"`
51+
Continents []Continent `json:"continents"`
52+
}
53+
54+
type ISOAdminLanguage struct {
55+
ISOAlpha3 string `json:"isoAlpha3"`
56+
ISOAlpha2 string `json:"isoAlpha2"`
57+
ISOName string `json:"isoName"`
58+
NativeName string `json:"nativeName"`
59+
}
60+
61+
type Currency struct {
62+
NumericCode int64 `json:"numericCode"`
63+
Code string `json:"code"`
64+
Name string `json:"name"`
65+
MinorUnits int64 `json:"minorUnits"`
66+
}
67+
68+
type WBRegion struct {
69+
ID string `json:"id"`
70+
ISO2code string `json:"iso2code"`
71+
Value string `json:"value"`
72+
}
73+
74+
type WBIncomeLevel struct {
75+
ID string `json:"id"`
76+
ISO2code string `json:"iso2code"`
77+
Value string `json:"value"`
78+
}
79+
80+
type Continent struct {
81+
Continent string `json:"continent"`
82+
ContinentCode string `json:"continentCode"`
83+
}
84+
85+
type Location struct {
86+
Continent string `json:"continent"`
87+
ContinentCode string `json:"continentCode"`
88+
ISOPrincipalSubdivision string `json:"isoPrincipalSubdivision"`
89+
ISOPrincipalSubdivisionCode string `json:"isoPrincipalSubdivisionCode"`
90+
City string `json:"city"`
91+
LocalityName string `json:"localityName"`
92+
PostCode string `json:"postcode"`
93+
Latitude float64 `json:"latitude"`
94+
Longitude float64 `json:"longitude"`
95+
PlusCode string `json:"plusCode"`
96+
TimeZone TimeZone `json:"timeZone"`
97+
LocalityInfo LocalityInfo `json:"localityInfo"`
98+
}
99+
100+
type TimeZone struct {
101+
IANATimeID string `json:"ianaTimeId"`
102+
DisplayName string `json:"displayName"`
103+
EffectiveTimeZoneFull string `json:"effectiveTimeZoneFull"`
104+
EffectiveTimeZoneShort string `json:"effectiveTimeZoneShort"`
105+
UTCOffsetSeconds int64 `json:"utcOffsetSeconds"`
106+
UTCOffset string `json:"utcOffset"`
107+
IsDaylightSavingTime bool `json:"isDaylightSavingTime"`
108+
LocalTime string `json:"localTime"`
109+
}
110+
111+
type LocalityInfo struct {
112+
Administrative []LocalityInfoData `json:"administrative"`
113+
Informative []LocalityInfoData `json:"informative"`
114+
}
115+
116+
type LocalityInfoData struct {
117+
Order int64 `json:"order"`
118+
AdminLevel int64 `json:"adminLevel"`
119+
Name string `json:"name"`
120+
Description string `json:"description"`
121+
ISOName string `json:"isoName"`
122+
ISOCode string `json:"isoCode"`
123+
WikidataID string `json:"wikidataId"`
124+
GeonameID int64 `json:"geonameId"`
125+
}
126+
127+
type Network struct {
128+
Registry string `json:"registry"`
129+
RegistryStatus string `json:"registryStatus"`
130+
RegisteredCountry string `json:"registeredCountry"`
131+
RegisteredCountryName string `json:"registeredCountryName"`
132+
Organisation string `json:"organisation"`
133+
IsReachableGlobally bool `json:"isReachableGlobally"`
134+
IsBogon bool `json:"isBogon"`
135+
BGPPrefix string `json:"bgpPrefix"`
136+
BGPPrefixNetworkAddress string `json:"bgpPrefixNetworkAddress"`
137+
BGPPrefixLastAddress string `json:"bgpPrefixLastAddress"`
138+
TotalAddresses int64 `json:"totalAddresses"`
139+
Carriers []Carrier `json:"carriers"`
140+
ViaCarriers []Carrier `json:"viaCarriers"`
141+
}
142+
143+
type Carrier struct {
144+
ASN string `json:"asn"`
145+
ASNNumeric int64 `json:"asnNumeric"`
146+
Organisation string `json:"organisation"`
147+
Name string `json:"name"`
148+
TotalIpv4Addresses int64 `json:"totalIpv4Addresses"`
149+
TotalIpv4Prefixes int64 `json:"totalIpv4Prefixes"`
150+
TotalIpv4BogonPrefixes int64 `json:"totalIpv4BogonPrefixes"`
151+
Rank int64 `json:"rank"`
152+
RankText string `json:"rankText"`
153+
}
154+
155+
type Area struct {
156+
Latitude float64 `json:"latitude"`
157+
Longitude float64 `json:"longitude"`
158+
}
159+
160+
type HazardReport struct {
161+
IsKnownAsTorServer bool `json:"isKnownAsTorServer"`
162+
IsKnownAsVPN bool `json:"isKnownAsVpn"`
163+
IsKnownAsProxy bool `json:"isKnownAsProxy"`
164+
IsSpamhausDrop bool `json:"isSpamhausDrop"`
165+
IsSpamhausEdrop bool `json:"isSpamhausEdrop"`
166+
IsSpamhausAsnDrop bool `json:"isSpamhausAsnDrop"`
167+
IsBlacklistedUceprotect bool `json:"isBlacklistedUceprotect"`
168+
IsBlacklistedBlocklistDe bool `json:"isBlacklistedBlocklistDe"`
169+
IsKnownAsMailServer bool `json:"isKnownAsMailServer"`
170+
IsKnownAsPublicRouter bool `json:"isKnownAsPublicRouter"`
171+
IsBogon bool `json:"isBogon"`
172+
IsUnreachable bool `json:"isUnreachable"`
173+
HostingLikelihood int64 `json:"hostingLikelihood"` // [0 - 10]
174+
IsHostingASN bool `json:"isHostingAsn"`
175+
IsCellular bool `json:"isCellular"`
176+
}

0 commit comments

Comments
 (0)