-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a24937
commit dd6678a
Showing
13 changed files
with
700 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
*.csv | ||
*.tsv | ||
bin/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.PHONY: init lint | ||
|
||
GO111MODULE=on | ||
LINT_OPT := -E gofmt \ | ||
-E golint \ | ||
-E govet \ | ||
-E gosec \ | ||
-E unused \ | ||
-E gosimple \ | ||
-E structcheck \ | ||
-E varcheck \ | ||
-E ineffassign \ | ||
-E deadcode \ | ||
-E typecheck \ | ||
-E misspell \ | ||
-E whitespace \ | ||
-E errcheck \ | ||
--exclude '(comment on exported (method|function|type|const|var)|should have( a package)? comment|comment should be of the form)' \ | ||
--timeout 5m | ||
|
||
init: | ||
go mod download | ||
|
||
lint: | ||
@type golangci-lint > /dev/null || go get -u github.com/golangci/golangci-lint/cmd/golangci-lint | ||
golangci-lint $(LINT_OPT) run ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
bigdatacloud-go | ||
---- | ||
|
||
[![License: MIT][401]][402] [![GoDoc][101]][102] [![Release][103]][104] [![Build Status][201]][202] [![Coveralls Coverage][203]][204] [![Codecov Coverage][205]][206] | ||
[![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] | ||
|
||
|
||
<!-- Basic --> | ||
|
||
[101]: https://godoc.org/github.com/evalphobia/bigdatacloud-go?status.svg | ||
[102]: https://godoc.org/github.com/evalphobia/bigdatacloud-go | ||
[103]: https://img.shields.io/github/release/evalphobia/bigdatacloud-go.svg | ||
[104]: https://github.com/evalphobia/bigdatacloud-go/releases/latest | ||
[105]: https://img.shields.io/github/downloads/evalphobia/bigdatacloud-go/total.svg?maxAge=1800 | ||
[106]: https://github.com/evalphobia/bigdatacloud-go/releases | ||
[107]: https://img.shields.io/github/stars/evalphobia/bigdatacloud-go.svg | ||
[108]: https://github.com/evalphobia/bigdatacloud-go/stargazers | ||
|
||
|
||
<!-- Testing --> | ||
|
||
[201]: https://github.com/evalphobia/bigdatacloud-go/workflows/test/badge.svg | ||
[202]: https://github.com/evalphobia/bigdatacloud-go/actions?query=workflow%3Atest | ||
[203]: https://coveralls.io/repos/evalphobia/bigdatacloud-go/badge.svg?branch=master&service=github | ||
[204]: https://coveralls.io/github/evalphobia/bigdatacloud-go?branch=master | ||
[205]: https://codecov.io/gh/evalphobia/bigdatacloud-go/branch/master/graph/badge.svg | ||
[206]: https://codecov.io/gh/evalphobia/bigdatacloud-go | ||
|
||
|
||
<!-- Code Quality --> | ||
|
||
[301]: https://goreportcard.com/badge/github.com/evalphobia/bigdatacloud-go | ||
[302]: https://goreportcard.com/report/github.com/evalphobia/bigdatacloud-go | ||
[303]: https://codeclimate.com/github/evalphobia/bigdatacloud-go/badges/gpa.svg | ||
[304]: https://codeclimate.com/github/evalphobia/bigdatacloud-go | ||
[305]: https://bettercodehub.com/edge/badge/evalphobia/bigdatacloud-go?branch=master | ||
[306]: https://bettercodehub.com/ | ||
[307]: https://www.codefactor.io/repository/github/evalphobia/bigdatacloud-go/badge | ||
[308]: https://www.codefactor.io/repository/github/evalphobia/bigdatacloud-go | ||
[309]: https://codebeat.co/badges/142f5ca7-da37-474f-9264-f708ade08b5c | ||
[310]: https://codebeat.co/projects/github-com-evalphobia-bigdatacloud-go-master | ||
[311]: https://scrutinizer-ci.com/g/evalphobia/bigdatacloud-go/badges/quality-score.png?b=master | ||
[312]: https://scrutinizer-ci.com/g/evalphobia/bigdatacloud-go/?branch=master | ||
|
||
<!-- License --> | ||
[401]: https://img.shields.io/badge/License-MIT-blue.svg | ||
[402]: LICENSE.md | ||
[403]: https://app.fossa.com/api/projects/git%2Bgithub.com%2Fevalphobia%2Fbigdatacloud-go.svg?type=shield | ||
[404]: https://app.fossa.com/projects/git%2Bgithub.com%2Fevalphobia%2Fbigdatacloud-go?ref=badge_shield | ||
|
||
|
||
Unofficial golang library for [Big Data Cloud](https://www.bigdatacloud.com/). | ||
|
||
|
||
# Quick Usage for API | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/evalphobia/bigdatacloud-go/config" | ||
"github.com/evalphobia/bigdatacloud-go/bigdatacloud" | ||
) | ||
|
||
func main() { | ||
conf := config.Config{ | ||
// you can set auth values to config directly, otherwise used from environment variables. | ||
APIKey: "<your API Key>", | ||
Language: "en", // default=en | ||
Debug: false, | ||
} | ||
|
||
svc, err := bigdatacloud.New(conf) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// execute score API | ||
resp, err := svc.IPGeolocationFull("8.8.8.8") | ||
if err != nil { | ||
panic(err) | ||
} | ||
if resp.HasError() { | ||
panic(fmt.Errorf("code=[%s] description=[%s]", resp.ErrData.Code, resp.ErrData.Description)) | ||
} | ||
|
||
// just print response in json format | ||
b, _ := json.Marshal(resp) | ||
fmt.Printf("%s", string(b)) | ||
} | ||
``` | ||
|
||
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). | ||
|
||
|
||
# Environment variables | ||
|
||
| Name | Description | | ||
|:--|:--| | ||
| `BIGDATACLOUD_APIKEY` | [Big Data Cloud API Key](https://www.bigdatacloud.com/sdk). | | ||
| `BIGDATACLOUD_LANGUAGE` | [Big Data Cloud localityLanguage](https://www.bigdatacloud.com/ip-geolocation-apis/ip-address-geolocation-with-confidence-area-and-hazard-report-api). | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
package bigdatacloud | ||
|
||
type ErrData struct { | ||
StatusCode int `json:"status_code"` | ||
Status int64 `json:"status"` | ||
Description string `json:"description"` | ||
} | ||
|
||
func (r *ErrData) SetStatusCode(code int) { | ||
r.StatusCode = code | ||
} | ||
|
||
func (r ErrData) HasError() bool { | ||
return r.StatusCode >= 400 | ||
} | ||
|
||
// IPResponse is a response data of IP Geolocation APIs. | ||
// ref: https://www.bigdatacloud.com/ip-geolocation-apis | ||
type IPResponse struct { | ||
ErrData | ||
|
||
IP string `json:"ip"` | ||
LocalityLanguageRequested string `json:"localityLanguageRequested"` | ||
IsReachableGlobally bool `json:"isReachableGlobally"` | ||
Country Country `json:"country"` | ||
Location Location `json:"location"` | ||
LastUpdated string `json:"lastUpdated"` | ||
Network Network `json:"network"` | ||
Confidence string `json:"confidence"` | ||
ConfidenceArea []Area `json:"confidenceArea"` | ||
SecurityThreat string `json:"securityThreat"` | ||
HazardReport HazardReport `json:"hazardReport"` | ||
} | ||
|
||
type Country struct { | ||
ISOAlpha2 string `json:"isoAlpha2"` | ||
ISOAlpha3 string `json:"isoAlpha3"` | ||
M49Code int64 `json:"m49Code"` | ||
Name string `json:"name"` | ||
ISOName string `json:"isoName"` | ||
ISONameFull string `json:"isoNameFull"` | ||
ISOAdminLanguages []ISOAdminLanguage `json:"isoAdminLanguages"` | ||
UNRegion string `json:"unRegion"` | ||
Currency Currency `json:"currency"` | ||
WBRegion WBRegion `json:"wbRegion"` | ||
WBIncomeLevel WBIncomeLevel `json:"wbIncomeLevel"` | ||
CallingCode string `json:"callingCode"` | ||
CountryFlagEmoji string `json:"countryFlagEmoji"` | ||
WikidataID string `json:"wikidataId"` | ||
GeonameID int64 `json:"geonameId"` | ||
Continents []Continent `json:"continents"` | ||
} | ||
|
||
type ISOAdminLanguage struct { | ||
ISOAlpha3 string `json:"isoAlpha3"` | ||
ISOAlpha2 string `json:"isoAlpha2"` | ||
ISOName string `json:"isoName"` | ||
NativeName string `json:"nativeName"` | ||
} | ||
|
||
type Currency struct { | ||
NumericCode int64 `json:"numericCode"` | ||
Code string `json:"code"` | ||
Name string `json:"name"` | ||
MinorUnits int64 `json:"minorUnits"` | ||
} | ||
|
||
type WBRegion struct { | ||
ID string `json:"id"` | ||
ISO2code string `json:"iso2code"` | ||
Value string `json:"value"` | ||
} | ||
|
||
type WBIncomeLevel struct { | ||
ID string `json:"id"` | ||
ISO2code string `json:"iso2code"` | ||
Value string `json:"value"` | ||
} | ||
|
||
type Continent struct { | ||
Continent string `json:"continent"` | ||
ContinentCode string `json:"continentCode"` | ||
} | ||
|
||
type Location struct { | ||
Continent string `json:"continent"` | ||
ContinentCode string `json:"continentCode"` | ||
ISOPrincipalSubdivision string `json:"isoPrincipalSubdivision"` | ||
ISOPrincipalSubdivisionCode string `json:"isoPrincipalSubdivisionCode"` | ||
City string `json:"city"` | ||
LocalityName string `json:"localityName"` | ||
PostCode string `json:"postcode"` | ||
Latitude float64 `json:"latitude"` | ||
Longitude float64 `json:"longitude"` | ||
PlusCode string `json:"plusCode"` | ||
TimeZone TimeZone `json:"timeZone"` | ||
LocalityInfo LocalityInfo `json:"localityInfo"` | ||
} | ||
|
||
type TimeZone struct { | ||
IANATimeID string `json:"ianaTimeId"` | ||
DisplayName string `json:"displayName"` | ||
EffectiveTimeZoneFull string `json:"effectiveTimeZoneFull"` | ||
EffectiveTimeZoneShort string `json:"effectiveTimeZoneShort"` | ||
UTCOffsetSeconds int64 `json:"utcOffsetSeconds"` | ||
UTCOffset string `json:"utcOffset"` | ||
IsDaylightSavingTime bool `json:"isDaylightSavingTime"` | ||
LocalTime string `json:"localTime"` | ||
} | ||
|
||
type LocalityInfo struct { | ||
Administrative []LocalityInfoData `json:"administrative"` | ||
Informative []LocalityInfoData `json:"informative"` | ||
} | ||
|
||
type LocalityInfoData struct { | ||
Order int64 `json:"order"` | ||
AdminLevel int64 `json:"adminLevel"` | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
ISOName string `json:"isoName"` | ||
ISOCode string `json:"isoCode"` | ||
WikidataID string `json:"wikidataId"` | ||
GeonameID int64 `json:"geonameId"` | ||
} | ||
|
||
type Network struct { | ||
Registry string `json:"registry"` | ||
RegistryStatus string `json:"registryStatus"` | ||
RegisteredCountry string `json:"registeredCountry"` | ||
RegisteredCountryName string `json:"registeredCountryName"` | ||
Organisation string `json:"organisation"` | ||
IsReachableGlobally bool `json:"isReachableGlobally"` | ||
IsBogon bool `json:"isBogon"` | ||
BGPPrefix string `json:"bgpPrefix"` | ||
BGPPrefixNetworkAddress string `json:"bgpPrefixNetworkAddress"` | ||
BGPPrefixLastAddress string `json:"bgpPrefixLastAddress"` | ||
TotalAddresses int64 `json:"totalAddresses"` | ||
Carriers []Carrier `json:"carriers"` | ||
ViaCarriers []Carrier `json:"viaCarriers"` | ||
} | ||
|
||
type Carrier struct { | ||
ASN string `json:"asn"` | ||
ASNNumeric int64 `json:"asnNumeric"` | ||
Organisation string `json:"organisation"` | ||
Name string `json:"name"` | ||
TotalIpv4Addresses int64 `json:"totalIpv4Addresses"` | ||
TotalIpv4Prefixes int64 `json:"totalIpv4Prefixes"` | ||
TotalIpv4BogonPrefixes int64 `json:"totalIpv4BogonPrefixes"` | ||
Rank int64 `json:"rank"` | ||
RankText string `json:"rankText"` | ||
} | ||
|
||
type Area struct { | ||
Latitude float64 `json:"latitude"` | ||
Longitude float64 `json:"longitude"` | ||
} | ||
|
||
type HazardReport struct { | ||
IsKnownAsTorServer bool `json:"isKnownAsTorServer"` | ||
IsKnownAsVPN bool `json:"isKnownAsVpn"` | ||
IsKnownAsProxy bool `json:"isKnownAsProxy"` | ||
IsSpamhausDrop bool `json:"isSpamhausDrop"` | ||
IsSpamhausEdrop bool `json:"isSpamhausEdrop"` | ||
IsSpamhausAsnDrop bool `json:"isSpamhausAsnDrop"` | ||
IsBlacklistedUceprotect bool `json:"isBlacklistedUceprotect"` | ||
IsBlacklistedBlocklistDe bool `json:"isBlacklistedBlocklistDe"` | ||
IsKnownAsMailServer bool `json:"isKnownAsMailServer"` | ||
IsKnownAsPublicRouter bool `json:"isKnownAsPublicRouter"` | ||
IsBogon bool `json:"isBogon"` | ||
IsUnreachable bool `json:"isUnreachable"` | ||
HostingLikelihood int64 `json:"hostingLikelihood"` // [0 - 10] | ||
IsHostingASN bool `json:"isHostingAsn"` | ||
IsCellular bool `json:"isCellular"` | ||
} |
Oops, something went wrong.