4 Commits

5 changed files with 61 additions and 61 deletions

View File

@@ -1,25 +1,25 @@
name: Go name: Go
on: on:
push: push:
branches: [ master ] branches: [ master ]
pull_request: pull_request:
branches: [ master ] branches: [ master ]
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: 1.17 go-version: 1.17
- name: Build - name: Build
run: go build -v ./... run: go build -v ./...
- name: Test - name: Test
run: go test -v ./... run: go test -v ./...

2
.gitignore vendored
View File

@@ -1,2 +1,2 @@
bin/ bin/*
lookupip lookupip

50
.vscode/tasks.json vendored
View File

@@ -1,26 +1,26 @@
{ {
// See https://go.microsoft.com/fwlink/?LinkId=733558 // See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format // for the documentation about the tasks.json format
"version": "2.0.0", "version": "2.0.0",
"tasks": [ "tasks": [
{ {
"label": "Go Build", "label": "Go Build",
"type": "shell", "type": "shell",
"command": "go build -o bin/", "command": "go build -o bin/",
"group": { "group": {
"kind": "build", "kind": "build",
"isDefault": true "isDefault": true
}, },
"presentation": { "presentation": {
"reveal": "silent", "reveal": "silent",
"clear": true "clear": true
} }
}, },
{ {
"label": "Go Test All", "label": "Go Test All",
"type": "shell", "type": "shell",
"command": "go test ./...", "command": "go test ./...",
"problemMatcher": [] "problemMatcher": []
} }
] ]
} }

View File

@@ -1,11 +1,11 @@
# lookupip # lookupip
Simple go executable to task an ip and get the results from ip-api Simple Go executable to query an IP and get the results from ip-api:
https://ip-api.com/ https://ip-api.com/
This is a fantastic site and I hope the continue to provide this This is a fantastic site, and I hope they continue to provide this service.
Allows flag -p to replace the properties output Allows flag -p to replace the properties output.
## Build ## Build

View File

@@ -63,21 +63,21 @@ func buildURL(ip string) (string, error) {
// https://ip-api.com/docs/api:json // https://ip-api.com/docs/api:json
func Lookup(ip string) (data IPAPI, err error) { func Lookup(ip string) (data IPAPI, err error) {
url, error := buildURL(ip) url, err := buildURL(ip)
if error != nil { if err != nil {
return data, error return data, err
} }
resp, err := http.Get(url) resp, err := http.Get(url)
if error != nil { if err != nil {
return data, error return data, err
} }
defer resp.Body.Close() defer resp.Body.Close()
err = json.NewDecoder(resp.Body).Decode(&data) err = json.NewDecoder(resp.Body).Decode(&data)
if error != nil { if err != nil {
return data, error return data, err
} }
if data.Status == "fail" { if data.Status == "fail" {