feat: add myip-go
This commit is contained in:
3
myip-go/go.mod
Normal file
3
myip-go/go.mod
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module myip
|
||||||
|
|
||||||
|
go 1.23.0
|
||||||
39
myip-go/main.go
Executable file
39
myip-go/main.go
Executable file
@@ -0,0 +1,39 @@
|
|||||||
|
/// 2>/dev/null ; gorun "$0" "$@" ; exit $?
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
const GetIpUrl = "https://hatter.ink/ip/ip.jsonp"
|
||||||
|
|
||||||
|
type IpResponse struct {
|
||||||
|
Status int16 `json:"status"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
IP string `json:"ip"`
|
||||||
|
UserAgent string `json:"userAgent"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
response, err := http.Get(GetIpUrl)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("[ERROR] Get IP failed: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
body, err := io.ReadAll(response.Body)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("[ERROR] Get IP failed: %s\n", err)
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
|
var ipReponse IpResponse
|
||||||
|
if err := json.Unmarshal(body, &ipReponse); err != nil {
|
||||||
|
fmt.Printf("[ERROR] Get IP failed: %s\n", err)
|
||||||
|
os.Exit(3)
|
||||||
|
}
|
||||||
|
fmt.Printf("[INFO] Your IP address: %s\n", ipReponse.IP)
|
||||||
|
}
|
||||||
@@ -3,5 +3,10 @@
|
|||||||
"script_name": "helloworld-go",
|
"script_name": "helloworld-go",
|
||||||
"script_length": 128,
|
"script_length": 128,
|
||||||
"script_sha256": "b807f5d29dd2dbd4dc8c665616c836b1e1c0274d377672109a3e2397bb1139bf"
|
"script_sha256": "b807f5d29dd2dbd4dc8c665616c836b1e1c0274d377672109a3e2397bb1139bf"
|
||||||
|
},
|
||||||
|
"myip-go": {
|
||||||
|
"script_name": "myip-go",
|
||||||
|
"script_length": 798,
|
||||||
|
"script_sha256": "2abb41d64288774c01c465508070bec5ba7350228ab0dc79a2fe679b5afb07b6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user