1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package main
- import (
- "bytes"
- "encoding/json"
- "fmt"
- "io"
- "net/http"
- "testing"
- "time"
- )
- func TestA(t *testing.T) {
- data := map[string]interface{}{
- "detail": "中共潮州市委办公室",
- }
- res := getAreaInfo(data)
- fmt.Println(res)
- }
- func getAreaInfo(data map[string]interface{}) map[string]interface{} {
- info := map[string]interface{}{}
- client := &http.Client{Timeout: 2 * time.Second}
- jsonStr, _ := json.Marshal(data)
- resp, err := client.Post("http://127.0.0.1:9996/service/region", "application/json", bytes.NewBuffer(jsonStr))
- if err != nil {
- return info
- }
- res, err := io.ReadAll(resp.Body)
- if err != nil {
- return info
- }
- err = json.Unmarshal(res, &info)
- if err != nil {
- return info
- }
- return info
- }
|