go util
2023-02-16 本文已影响0人
hehehehe
https://github.com/sourcegraph/conc
lo.TryCatchWithErrorValue(func() error {
result = valid("abc")
return nil
}, func(val any) {
fmt.Println(val)
result = "cde"
})
fmt.Println(result)
fmt.Println(fmt.Sprintf("%s",result))
https://github.com/thoas/go-funk
go get -u github.com/tidwall/gjson
import (
"fmt"
"github.com/duke-git/lancet/v2/convertor"
"github.com/duke-git/lancet/v2/netutil"
"github.com/tidwall/gjson"
"io"
"log"
"net/http"
"net/url"
)
header := http.Header{}
//header.Add("Content-Type", "application/json")
header.Add("Content-Type", "text/plain")
//data:= map[string]bool{"track_total_hits": true}
//dataString, _ := json.Marshal(data)
values := url.Values{}
values.Add("appId","once_time_")
values.Add("apiName","gv3_place_detail")
values.Add("mapType","gaode")
values.Add("sign","1111")
request := &netutil.HttpRequest{
RawURL: "http://map.cn/map/api",
Method: "POST",
Headers: header,
QueryParams: values,
Body: []byte("id=B0H141YCBL"),
}
httpClient := netutil.NewHttpClient()
resp, err := httpClient.SendRequest(request)
if err != nil || resp.StatusCode != 200 {
fmt.Println("aa",err)
return
}
fmt.Println("aaa",resp.StatusCode)
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
result := gjson.Get(convertor.ToString(responseBody), "data.pois.0.type").String()
fmt.Println(result)