Skip to content

Commit

Permalink
golang-snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
jolav committed Oct 4, 2024
1 parent 8525704 commit 5ce0b71
Show file tree
Hide file tree
Showing 24 changed files with 66 additions and 66 deletions.
24 changes: 12 additions & 12 deletions docs/golang-snippets.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,43 +183,43 @@ func FetchPOST(url string, d interface{}) error {

```

### fetchPOST with url params
### fetchPOST with params

```go
import (
url2 "net/url"
url "net/url"
)

// FetchPOSTparams ...
func FetchPOSTparams(url string, d map[string]string) error {
func FetchPOSTparams(path string, d map[string]string) error {
client := &http.Client{
Timeout: 10 * time.Second,
}

params := url2.Values{}
params := url.Values{}
for key, value := range d {
params.Add(key, value)
}
/*params = url2.Values{
"test": "myTest",
"data": "myData",
/*params := url.Values{
"test": {myTest},
"data": {myData},
}*/

query := bytes.NewBufferString(params.Encode())
body := bytes.NewBufferString(params.Encode())

req, err := http.NewRequest("POST", url, query)
req, err := http.NewRequest("POST", path, body)
if err != nil {
log.Printf("ERROR: Failed to create request for %s => %v", url, err)
log.Printf("ERROR: Failed to create request for %s => %v", path, err)
return err
}

req.Header.Set("Authorization", "Bearer YOUR_ACCESS_TOKEN")
req.Header.Set("Accept-Charset", "utf-8")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Content-Type", "application/x-www-form-pathencoded")

resp, err := client.Do(req)
if err != nil {
log.Printf("ERROR: Request %s => %v", url, err)
log.Printf("ERROR: Request %s => %v", path, err)
return err
}
defer resp.Body.Close()
Expand Down
2 changes: 1 addition & 1 deletion www/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.553849+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.134713+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/css/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.588605+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.176982+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/debian/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2488,7 +2488,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.603152+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.195883+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/expressjs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.620962+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.219100+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.640648+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.230371+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/golang-bases-de-datos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.644316+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.236388+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/golang-para-web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.646800+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.240116+00:00
-->
</body>

Expand Down
30 changes: 15 additions & 15 deletions www/golang-snippets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,41 +213,41 @@ <h3 id="fetchpost">fetchPOST</h3>
}

</code></pre>
<h3 id="fetchpost-with-url-params">fetchPOST with url params</h3>
<h3 id="fetchpost-with-params">fetchPOST with params</h3>
<pre><code class="language-go">import (
url2 &quot;net/url&quot;
url &quot;net/url&quot;
)

// FetchPOSTparams ...
func FetchPOSTparams(url string, d map[string]string) error {
func FetchPOSTparams(path string, d map[string]string) error {
client := &amp;http.Client{
Timeout: 10 * time.Second,
}

params := url2.Values{}
params := url.Values{}
for key, value := range d {
params.Add(key, value)
}
/*params = url2.Values{
&quot;test&quot;: &quot;myTest&quot;,
&quot;data&quot;: &quot;myData&quot;,
/*params := url.Values{
&quot;test&quot;: {myTest},
&quot;data&quot;: {myData},
}*/

query := bytes.NewBufferString(params.Encode())
body := bytes.NewBufferString(params.Encode())

req, err := http.NewRequest(&quot;POST&quot;, url, query)
req, err := http.NewRequest(&quot;POST&quot;, path, body)
if err != nil {
log.Printf(&quot;ERROR: Failed to create request for %s =&gt; %v&quot;, url, err)
log.Printf(&quot;ERROR: Failed to create request for %s =&gt; %v&quot;, path, err)
return err
}

req.Header.Set(&quot;Authorization&quot;, &quot;Bearer YOUR_ACCESS_TOKEN&quot;)
req.Header.Set(&quot;Accept-Charset&quot;, &quot;utf-8&quot;)
req.Header.Set(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;)
req.Header.Set(&quot;Content-Type&quot;, &quot;application/x-www-form-pathencoded&quot;)

resp, err := client.Do(req)
if err != nil {
log.Printf(&quot;ERROR: Request %s =&gt; %v&quot;, url, err)
log.Printf(&quot;ERROR: Request %s =&gt; %v&quot;, path, err)
return err
}
defer resp.Body.Close()
Expand Down Expand Up @@ -1650,7 +1650,7 @@ <h3>Contenidos</h3>
</ul>
<li><a href="#fetchpost-with-url-params">fetchPOST with url params</a></li>
<li><a href="#fetchpost-with-params">fetchPOST with params</a></li>
<ul>
</ul>
Expand Down Expand Up @@ -2093,7 +2093,7 @@ <h3>Contenidos</h3>

</ul>

<li><a href="#fetchpost-with-url-params">fetchPOST with url params</a></li>
<li><a href="#fetchpost-with-params">fetchPOST with params</a></li>
<ul>

</ul>
Expand Down Expand Up @@ -2372,7 +2372,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.654148+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.251456+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/golang/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3125,7 +3125,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.659927+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.265657+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.686305+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.292052+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ <h3>Quick search</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.587181+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.175601+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/javascript-apis/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.693858+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.300788+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/javascript-para-web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.710658+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.310242+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/javascript-snippets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.722477+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.332687+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/javascript/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2287,7 +2287,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.727546+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.337295+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/nodejs-bases-de-datos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.744130+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.363798+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/nodejs-snippets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.746317+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.369831+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/nodejs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.748778+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.375052+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/reactjs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-02 16:18:53.750673+00:00
Docs Build Date UTC : 2024-10-04 13:57:34.377002+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/search/search_index.json

Large diffs are not rendered by default.

Loading

0 comments on commit 5ce0b71

Please sign in to comment.