resolver: make decoders return string instead of byte slice
This commit is contained in:
parent
ae79cd131e
commit
c36a83c9b8
3 changed files with 16 additions and 20 deletions
|
|
@ -5,16 +5,12 @@ import (
|
|||
"io"
|
||||
)
|
||||
|
||||
func Jsonip(r io.Reader) ([]byte, error) {
|
||||
func Jsonip(r io.Reader) (string, error) {
|
||||
var v struct {
|
||||
Ip string `json:"ip"`
|
||||
Location string `json:"geo-ip"`
|
||||
Help string `json:"API Help"`
|
||||
}
|
||||
var val []byte
|
||||
err := json.NewDecoder(r).Decode(&v)
|
||||
if err == nil {
|
||||
val = []byte(v.Ip)
|
||||
}
|
||||
return val, err
|
||||
return v.Ip, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,16 +5,12 @@ import (
|
|||
"io"
|
||||
)
|
||||
|
||||
func MyIP(r io.Reader) ([]byte, error) {
|
||||
func MyIP(r io.Reader) (string, error) {
|
||||
var v struct {
|
||||
Ip string `json:"ip"`
|
||||
Country string `json:"country"`
|
||||
Cc string `json:"cc"`
|
||||
}
|
||||
var val []byte
|
||||
err := json.NewDecoder(r).Decode(&v)
|
||||
if err == nil {
|
||||
val = []byte(v.Ip)
|
||||
}
|
||||
return val, err
|
||||
return v.Ip, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue