1
0
Fork 0

ip/resolver: move decoders into sub package

This commit is contained in:
Henrik Hautakoski 2025-10-16 23:12:27 +02:00
parent 7c2ad9384b
commit a0fa688451
3 changed files with 7 additions and 6 deletions

View file

@ -0,0 +1,20 @@
package decoder
import (
"encoding/json"
"io"
)
func Jsonip(r io.Reader) ([]byte, 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
}

View file

@ -0,0 +1,20 @@
package decoder
import (
"encoding/json"
"io"
)
func MyIP(r io.Reader) ([]byte, 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
}