From 07c723310f6ffbf97d69ebb7f46cbda0ccc7ba92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Mon, 19 Sep 2022 16:06:57 +0800 Subject: [PATCH] - update ip --- .gitignore | 3 ++- const.go | 2 +- go.mod | 2 +- go.sum | 4 +-- ip.go | 26 ++++++++++++------- .../go-playground/validator/v10/README.md | 2 +- .../go-playground/validator/v10/baked_in.go | 11 +++++--- vendor/modules.txt | 2 +- 8 files changed, 33 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 557a87e..4a8d465 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ *_test.go gomod.sh *.zip -*.tar.gz \ No newline at end of file +*.tar.gz +/vendor/ diff --git a/const.go b/const.go index 8f0b4f8..f70ec7b 100644 --- a/const.go +++ b/const.go @@ -1,3 +1,3 @@ package goip -const Version = "1.0.34" +const Version = "1.0.35" diff --git a/go.mod b/go.mod index 1301b94..61239f0 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/gin-gonic/gin v1.8.1 // indirect github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect - github.com/go-playground/validator/v10 v10.11.0 // indirect + github.com/go-playground/validator/v10 v10.11.1 // indirect github.com/goccy/go-json v0.9.11 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/leodido/go-urn v1.2.1 // indirect diff --git a/go.sum b/go.sum index ae9cf27..b32bf4a 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,8 @@ github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= -github.com/go-playground/validator/v10 v10.11.0 h1:0W+xRM511GY47Yy3bZUbJVitCNg2BOGlCyvTqsp/xIw= -github.com/go-playground/validator/v10 v10.11.0/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= +github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ= +github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk= github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= diff --git a/ip.go b/ip.go index 158c4bb..d2c1cd5 100644 --- a/ip.go +++ b/ip.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "go.dtapp.net/gorequest" + "log" "net" ) @@ -48,28 +49,35 @@ func Ips(ctx context.Context) (map[string]string, error) { return ips, nil } -var respGetOutsideIp struct { - Data struct { - Ip string `json:"ip,omitempty"` - } `json:"data"` -} - // GetOutsideIp 外网ip func GetOutsideIp(ctx context.Context) string { + + // 返回结果 + type respGetOutsideIp struct { + Data struct { + Ip string `json:"ip,omitempty"` + } `json:"data"` + } + // 请求 getHttp := gorequest.NewHttp() getHttp.SetUri("https://api.dtapp.net/ip") response, err := getHttp.Get(ctx) if err != nil { + log.Printf("[GetOutsideIp]getHttp.Get:%s\n", err) return "0.0.0.0" } // 解析 - err = json.Unmarshal(response.ResponseBody, &respGetOutsideIp) + var responseJson respGetOutsideIp + err = json.Unmarshal(response.ResponseBody, &responseJson) if err != nil { + log.Printf("[GetOutsideIp]json.Unmarshal:%s\n", err) return "0.0.0.0" } - respGetOutsideIp.Data.Ip = "0.0.0.0" - return respGetOutsideIp.Data.Ip + if responseJson.Data.Ip == "" { + responseJson.Data.Ip = "0.0.0.0" + } + return responseJson.Data.Ip } // GetMacAddr 获取Mac地址 diff --git a/vendor/github.com/go-playground/validator/v10/README.md b/vendor/github.com/go-playground/validator/v10/README.md index 8b730b6..9d0a79e 100644 --- a/vendor/github.com/go-playground/validator/v10/README.md +++ b/vendor/github.com/go-playground/validator/v10/README.md @@ -1,7 +1,7 @@ Package validator ================= [![Join the chat at https://gitter.im/go-playground/validator](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-playground/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -![Project status](https://img.shields.io/badge/version-10.11.0-green.svg) +![Project status](https://img.shields.io/badge/version-10.11.1-green.svg) [![Build Status](https://travis-ci.org/go-playground/validator.svg?branch=master)](https://travis-ci.org/go-playground/validator) [![Coverage Status](https://coveralls.io/repos/go-playground/validator/badge.svg?branch=master&service=github)](https://coveralls.io/github/go-playground/validator?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/validator)](https://goreportcard.com/report/github.com/go-playground/validator) diff --git a/vendor/github.com/go-playground/validator/v10/baked_in.go b/vendor/github.com/go-playground/validator/v10/baked_in.go index f2f0939..c9b1db4 100644 --- a/vendor/github.com/go-playground/validator/v10/baked_in.go +++ b/vendor/github.com/go-playground/validator/v10/baked_in.go @@ -1484,10 +1484,15 @@ func isAlphaUnicode(fl FieldLevel) bool { return alphaUnicodeRegex.MatchString(fl.Field().String()) } -// isBoolean is the validation function for validating if the current field's value can be safely converted to a boolean. +// isBoolean is the validation function for validating if the current field's value is a valid boolean value or can be safely converted to a boolean value. func isBoolean(fl FieldLevel) bool { - _, err := strconv.ParseBool(fl.Field().String()) - return err == nil + switch fl.Field().Kind() { + case reflect.Bool: + return true + default: + _, err := strconv.ParseBool(fl.Field().String()) + return err == nil + } } // isDefault is the opposite of required aka hasValue diff --git a/vendor/modules.txt b/vendor/modules.txt index 188a9f2..a651db8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -15,7 +15,7 @@ github.com/go-playground/locales/currency # github.com/go-playground/universal-translator v0.18.0 ## explicit; go 1.13 github.com/go-playground/universal-translator -# github.com/go-playground/validator/v10 v10.11.0 +# github.com/go-playground/validator/v10 v10.11.1 ## explicit; go 1.13 github.com/go-playground/validator/v10 # github.com/goccy/go-json v0.9.11