12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package task
- import (
- "be-vpn/internal/dto"
- "bytes"
- "encoding/json"
- "github.com/tidwall/gjson"
- "io"
- "log"
- "net/http"
- )
- func Register() {
- resp, err := http.Get("https://ipinfo.ipidea.io")
- if err != nil {
- log.Fatalf("can not get resp, err: %+v", err)
- }
- bs, err := io.ReadAll(resp.Body)
- if err != nil {
- log.Printf("can not read resp, err: %+v", err)
- return
- }
- countryCode := gjson.Get(string(bs), "country_code").String()
- ip := gjson.Get(string(bs), "ip").String()
- city := gjson.Get(string(bs), "city").String()
- log.Printf("ipinfo: %s", string(bs))
- request := dto.RegisterRequest{Ip: ip, CountryCode: countryCode, CountryName: city, City: city}
- body, err := json.Marshal(request)
- if err != nil {
- log.Printf("err: %+v", err)
- return
- }
- // send request
- reader := bytes.NewBuffer(body)
- resp, err = http.Post("http://v.starttransfernow.com/register", "application/json", reader)
- if err != nil {
- log.Printf("err: %+v", err)
- return
- }
- respBody, err := io.ReadAll(resp.Body)
- if err != nil {
- log.Printf("err: %+v", err)
- return
- }
- log.Printf("resp: %s", string(respBody))
- }
|