1
0
Fork 0

resolver: make decoders return string instead of byte slice

This commit is contained in:
Henrik Hautakoski 2026-02-19 10:23:11 +01:00
parent ae79cd131e
commit c36a83c9b8
3 changed files with 16 additions and 20 deletions

View file

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

View file

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