[{"data":1,"prerenderedAt":102},["Reactive",2],{"/samples/go":3},[4,62],{"_path":5,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":10,"language":11,"library":12,"link":13,"body":14,"_type":57,"_id":58,"_source":59,"_file":60,"_extension":61},"/samples/go/go-resty","go",false,"","Go Resty","Go-Resty is a third-party HTTP client library for GoLang. It provides an easy-to-use API for making HTTP requests and handling responses, similar to libraries like net/http. Go-Resty simplifies tasks such as setting headers, handling cookies, and managing request parameters.","Go","go-resty","https://github.com/go-resty/resty",{"type":15,"children":16,"toc":54},"root",[17,33,45],{"type":18,"tag":19,"props":20,"children":21},"element","p",{},[22,31],{"type":18,"tag":23,"props":24,"children":27},"a",{"href":13,"rel":25},[26],"nofollow",[28],{"type":29,"value":30},"text","Go-Resty",{"type":29,"value":32}," is a third-party HTTP client library for GoLang. It provides an easy-to-use API for making HTTP requests and handling responses, similar to libraries like net/http. Go-Resty simplifies tasks such as setting headers, handling cookies, and managing request parameters.",{"type":18,"tag":34,"props":35,"children":39},"pre",{"className":36,"code":38,"language":6,"meta":8},[37],"language-go","package main\n\nimport (\n    \"encoding/json\"\n    \"fmt\"\n    \"github.com/go-resty/resty/v2\"\n    \"io/ioutil\"\n)\n\n// Convert function makes a POST request to the provided endpoint with the supplied parameters\nfunc convert(apiKey string, params map[string]string, endpoint string) ([]byte, error) {\n    client := resty.New()\n\n    // Perform the request\n    resp, err := client.R().\n        SetHeader(\"X-API-Key\", apiKey).\n        SetHeader(\"Content-Type\", \"application/json\").\n        SetBody(params).\n        Post(fmt.Sprintf(\"https://api.pdfshift.io/v3/convert/%s\", endpoint))\n\n    if err != nil {\n        return nil, err\n    }\n\n    if _, ok := params[\"filename\"]; ok || params[\"webhook\"]; ok {\n        var response map[string]interface{}\n        err := json.Unmarshal(resp.Body(), &response)\n        if err != nil {\n            return nil, err\n        }\n        return json.Marshal(response)\n    }\n\n    return resp.Body(), nil\n}\n",[40],{"type":18,"tag":41,"props":42,"children":43},"code",{"__ignoreMap":8},[44],{"type":29,"value":38},{"type":18,"tag":34,"props":46,"children":49},{"className":47,"code":48,"language":6,"meta":8},[37],"func main() {\n    params := map[string]string{\"source\": \"https://en.wikipedia.org/wiki/REST\"}\n    apiKey := \"sk_XXXXXXXXXXXXXX\"\n\n    resp, err := convert(apiKey, params, \"pdf\")\n    if err != nil {\n        panic(err)\n    }\n\n    error := ioutil.WriteFile(\"result.pdf\", resp, 0644)\n    if error != nil {\n        panic(err)\n    }\n}\n",[50],{"type":18,"tag":41,"props":51,"children":52},{"__ignoreMap":8},[53],{"type":29,"value":48},{"title":8,"searchDepth":55,"depth":55,"links":56},2,[],"markdown","content:samples:go:go-resty.md","content","samples/go/go-resty.md","md",{"_path":63,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":64,"description":65,"language":11,"library":66,"link":67,"body":68,"_type":57,"_id":100,"_source":59,"_file":101,"_extension":61},"/samples/go/nethttp","Nethttp","Net/HTTP is a core package that provides functionality for building HTTP servers and clients, handling HTTP requests and responses, and managing web communication. It offers a straightforward API for creating web applications, APIs, and microservices, making it a fundamental component of web development in Go.","Net/HTTP","https://golang.org/pkg/net/http/",{"type":15,"children":69,"toc":98},[70,80,89],{"type":18,"tag":19,"props":71,"children":72},{},[73,78],{"type":18,"tag":23,"props":74,"children":76},{"href":67,"rel":75},[26],[77],{"type":29,"value":66},{"type":29,"value":79}," is a core package that provides functionality for building HTTP servers and clients, handling HTTP requests and responses, and managing web communication. It offers a straightforward API for creating web applications, APIs, and microservices, making it a fundamental component of web development in Go.",{"type":18,"tag":34,"props":81,"children":84},{"className":82,"code":83,"language":6,"meta":8},[37],"package main\n\nimport (\n    \"bytes\"\n    \"encoding/json\"\n    \"io/ioutil\"\n    \"net/http\"\n)\n\ntype Response struct {\n    Filename string `json:\"filename\"`\n    Webhook  string `json:\"webhook\"`\n    Status   string `json:\"status\"`\n}\n\nfunc convert(apiKey string, params map[string]interface{}, endpoint string) ([]byte, error) {\n    allowedEndpoints := map[string]bool{\n        \"pdf\":  true,\n        \"png\":  true,\n        \"jpg\":  true,\n        \"webp\": true,\n    }\n    \n    if _, ok := allowedEndpoints[endpoint]; !ok {\n        panic(\"Invalid endpoint! Allowed endpoints are 'pdf', 'png', 'jpg', 'webp'\")\n    }\n    \n    url := \"https://api.pdfshift.io/v3/convert/\" + endpoint\n    jsonParams, err := json.Marshal(params)\n    if err != nil {\n        return nil, err\n    }\n\n    req, err := http.NewRequest(\"POST\", url, bytes.NewBuffer(jsonParams))\n    if err != nil {\n        return nil, err\n    }\n    req.Header.Set(\"Content-Type\", \"application/json\")\n    req.Header.Set(\"X-API-Key\", apiKey)\n\n    client := &http.Client{}\n    resp, err := client.Do(req)\n    if err != nil {\n        return nil, err\n    }\n    defer resp.Body.Close()\n\n    if _, ok := params[\"filename\"]; ok || params[\"webhook\"]; ok {\n        responseData := &Response{}\n        decoder := json.NewDecoder(resp.Body)\n        err := decoder.Decode(&responseData)\n        if err != nil {\n            return nil, err\n        }\n        jsonResponse, err := json.Marshal(responseData)\n        if err != nil {\n            return nil, err\n        }\n        return jsonResponse, nil\n    }\n\n    body, err := ioutil.ReadAll(resp.Body)\n    if err != nil {\n        return nil, err\n    }\n    return body, nil\n}\n",[85],{"type":18,"tag":41,"props":86,"children":87},{"__ignoreMap":8},[88],{"type":29,"value":83},{"type":18,"tag":34,"props":90,"children":93},{"className":91,"code":92,"language":6,"meta":8},[37],"func main() {\n    params := map[string]interface{}{\n        \"source\": \"https://en.wikipedia.org/wiki/REST\",\n    }\n    data, err := convert(\"sk_XXXXXXXXXXXXXX\", params, \"pdf\")\n    if err != nil {\n        panic(err)\n    }\n    err = ioutil.WriteFile(\"result.pdf\", data, 0644)\n    if err != nil {\n        panic(err)\n    }\n}\n",[94],{"type":18,"tag":41,"props":95,"children":96},{"__ignoreMap":8},[97],{"type":29,"value":92},{"title":8,"searchDepth":55,"depth":55,"links":99},[],"content:samples:go:nethttp.md","samples/go/nethttp.md",1785426821567]