go util

作者: hehehehe | 来源:发表于2023-02-16 17:44 被阅读0次

    https://github.com/sourcegraph/conc

    https://github.com/samber/lo

        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)
    

    相关文章

      网友评论

          本文标题:go util

          本文链接:https://www.haomeiwen.com/subject/dqskfdtx.html