initial commit

This commit is contained in:
Paul 2020-01-29 12:37:14 +01:00
commit 8b6cf61b7d
4 changed files with 127 additions and 0 deletions

15
.gitignore vendored Normal file
View File

@ -0,0 +1,15 @@
# ---> Go
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
/dipc

17
Makefile Normal file
View File

@ -0,0 +1,17 @@
# dipc Makefile
GOCMD=go
GOBUILDCMD=${GOCMD} build
RMCMD=rm
BINNAME=dipc
SRCFILES=cmd/dipc/*.go
all: build
build:
${GOBUILDCMD} ${SRCFILES}
clean:
${RMCMD} -f ${BINNAME}

52
README.md Normal file
View File

@ -0,0 +1,52 @@
# dipc
dipc is a client-side command-line utility that return public ip address, written in golang
## Howto
### Prerequisites
### Build
```bash
make
```
### Play
./dipc
## Todo
- Add tests
## License
```text
Copyright (c) 2020 PaulBSD
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the fuelprices project.
```

43
cmd/dipc/dipc.go Normal file
View File

@ -0,0 +1,43 @@
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
func main() {
var ip Dipc
var client = &http.Client{}
var url = "https://ip.paulbsd.com"
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Fatal(err)
}
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
err = json.Unmarshal(body, &ip)
if err != nil {
log.Println(err)
}
fmt.Println(ip.IP)
}
// Dipc is the main struct
type Dipc struct {
IP string `json:"ip"`
Hostname string `json:"hostname"`
}