Golang: How to Trim Whitespace and Newlines
If you want to simply remove the leading and trailing white spaces from a string then forget about the regex and only use TrimSpace simple… Read More »Golang: How to Trim Whitespace and Newlines
If you want to simply remove the leading and trailing white spaces from a string then forget about the regex and only use TrimSpace simple… Read More »Golang: How to Trim Whitespace and Newlines
You have a JSON in string and you want to map its values into a struct, take a look at this simple example:
Lovely Golang! I like this feature in Go which you can return multiple values from your functions 🙂 Look at the below function definition and… Read More »Golang Return Multiple Values: Different Types + Error
This is the easiest thing I want to mention! Just use the equal (==) operator in golang: Code example:
Just call the HasPrefix function from the lovely strings package: Simple example code to check if a list of strings has a prefix:
Checking if a character or a substring exists in a string is so simple: And a simple example:
In Golang convert an object to JSON string (or a slice of bytes) is so simple by using the json package: In this example you… Read More »Golang: Simple Marshal Struct to JSON
If you came from the PHP or JS world then you want to know how you can write a foreach loop in the Golang 🙂… Read More »Is There a Foreach Loop in Go? [YES]
In Golang, you don’t have a special function that extracts the map keys for you. But it is as simple as this loop:
There are two ways to add an item to a map and one way to remove it from a map: Simple code example: