Introduction # In Python you can assign default value to the functions, like so:
1 2 def my_func(posarg, named_arg=True, another_named_arg="Okay") # logic goes here... But in Go you can’t do this:
1 2 3 func myFunc(posarg, named_arg bool = true, another_named_arg string = "Okay") { // logic goes here... } This will throw a syntax error. Try that?
In this post, we’ll see how can we overcome this issue the go way, with something called Function Options. Not sure if go is the only language that uses this syntax, if there is another language you are using, please let me know. Also, connect with me on LinkedIn
Introduction # Send a POST request in golang is pretty daunting if you have a post body and you’re coming from a scripting language like JavaScript or Python. Here in Go, schema for JSON needs to be defined beforehand in order to marshal and unmarshal string back and forth to JSON.
Simple POST # This marshaling/unmarshalling could be an oneliner if your request body is not nested, or is one level deep, or there is not even a body. Consider this example:
Introduction # Have you ever ran into a situation where you wanted to version your application, but doing git tag and making a separate commit for updating version number was a two-step process? Isn’t that kinda frustrating? You can even miss to update the version number in your code, which happens to be with me a lot. In this post we’ll see how to convert this two-step process into one.
I will start this post with a quote from webassembly.org:
WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable target for compilation of high-level languages like C/C++/Rust, enabling deployment on the web for client and server applications.— webassembly.org That’s a lot of technical jargon. In very simple terms, Wasm provides a way to run code written in multiple languages on the web at near-native speed. Where multiple languages refers to all these languages.
Why use BoltDB # Bolt plays pretty well with Go’s concurrency model, we can do multiple reads concurrently.
For pro and cons, I will contrast it with similar database SQLite. I have done SQLite when I worked with Xentrix to develop GUI tools for the artists.
You may want to connect with me on LinkedIn.
Pro # It is native go. This means you don’t need any database server running, like SQLite. In oppose to Redis and memcached.
You can’t think of deploying your application to production without testing it.
Neither you can manage a large codebase with confidence without it.
Let us go through some basics of unit testing in golang.
This post is structured in the following manner:
unit testing basics in golang (jump) inbuilt code coverage command understanding subtests and helper function (jump) Travis CI integration (jump) running test against multiple version of go Please connect with me on LinkedIn and let’s get started.
Back in time when I used to see Photoshop’s layers section, there was a list of things named like Darken, Multiply, Screen and so on. They used to change the color when that particular layer was placed on some other layer.
Later in my college days I came to know these were the well known blending modes. There are mathematical in nature and does maths on pixel by pixel basis.