- update ip

master v1.0.35
李光春 2 weeks ago
parent a24d5383fb
commit 07c723310f
  1. 3
      .gitignore
  2. 2
      const.go
  3. 2
      go.mod
  4. 4
      go.sum
  5. 26
      ip.go
  6. 2
      vendor/github.com/go-playground/validator/v10/README.md
  7. 11
      vendor/github.com/go-playground/validator/v10/baked_in.go
  8. 2
      vendor/modules.txt

3
.gitignore vendored

@ -7,4 +7,5 @@
*_test.go
gomod.sh
*.zip
*.tar.gz
*.tar.gz
/vendor/

@ -1,3 +1,3 @@
package goip
const Version = "1.0.34"
const Version = "1.0.35"

@ -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

@ -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=

26
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地址

@ -1,7 +1,7 @@
Package validator
=================
<img align="right" src="https://raw.githubusercontent.com/go-playground/validator/v9/logo.png">[![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)

@ -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

@ -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

Loading…
Cancel
Save