Overview In this tutorial, we will explore two libraries that can be used to validate the field of a struct in Golang. The two libraries are gopkg.in/go-playground/validator.v9 – https://pkg.go.dev/github.com/go-playground/validator github.com/asaskevich/govalidator – https://github.com/asaskevich/govalidator…
Tag: go
Set a timeout while making an HTTP request in Go (Golang)
Overview client struct of HTTP package can be used to specify the timeout. While creating the HTTP client we can specify the value of the Timeout. An important thing to note about…
ASCII digit to the character in Go (Golang)
Overview Below is the simple program to convert an ASCII digit to its corresponding character in go. We can simply typecast the number to the string. That will convert it into its…
Convert a JSON to map in Go (Golang)
Overview encoding/json package provides utilities that can be used to convert to and from JSON. The same utility can be used to convert a golang map to JSON string and vice versa….
Convert a map to JSON in Go (Golang)
Overview encoding/json package provides utilities that can be used to convert to and from JSON. The same utility can be used to convert a golang map to JSON string and vice versa….
Conversion between map and JSON in Go (Golang)
Overview encoding/json package provides utilities that can be used to convert to and from JSON. The same utility can be used to convert a golang map to JSON string and vice versa….
Why response body is closed in golang
The response body should be closed after the response is fully read. This is done to prevent resource leak of connections. If the response body is not closed then the connection will…
HTTP send/receive application octet-stream request body in Go (Golang)
Overview application/octet-stream content-type is used to transfer binary data in the HTTP request body. So application/octet-stream is used for sending files over HTTP request. Let’s see an example of both HTTP client and server…
HTTP client/server multipart form-data request body example in Go (Golang)
Overview In HTTP context, the multipart/form-data content-type is used for submitting HTML form. In the case of multipart/form-data, as the name suggests, the body consists of different parts separated by a delimiter…
HTTP send/receive png file in request body example in Go (Golang)
Overview multipart/form-data content-type can be used to send the png files in an HTTP POST call. The form-data will contain png filename- test.png in the example that we will see in this…