Type Conversion and Type Assertion in Go

Type conversion The expression T(v) converts the value v to the type T. In Go, assignment between items of different type requires an explicit conversion. Here’s an example. 1 2 3 4 5 6 7 8 9 10 11 12 13 package main import ( "fmt" "math" ) func main() { var x, y int = 11, 12 f := math.Sqrt(float64(x*x + y*y)) var z uint = uint(f) fmt.Println(x, y, z) } Type assertion Type assertion provides access to an interface value’s underlying concrete value.

Why Do We Need Unit Tests?

What is unit testing? Unit testing is the process where you test the smallest functional unit of code. Software testing helps ensure code quality, and it’s an integral part of software development. It’s a software development best practice to write software as small, functional units then write a unit test for each code unit. You can first write unit tests as code. Then, run that test code automatically every time you make changes in the software code.

Go Does Not Have Reference Variables

To be clear, Go does not have reference variables, so Go does not have pass-by-reference function call semantics. Dave Cheney What is a reference variable? In languages like C++ you can declare an alias, or an alternate name to an existing variable. This is called a reference variable. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 #include <stdio.

How to Assume IAM Role in AWS and Use It

AWS IAM Assume Role is a mechanism that enables a user or service to assume a specific IAM role temporarily. This allows the user or service to acquire temporary security credentials, including access keys, session tokens, and permissions, to perform actions within AWS resources. The assumed role can have different permissions and policies than the original user or service, ensuring a granular level of access control and reducing the need for sharing long-term credentials.

How to Configure Remote SSH Connection to WSL 2

There may be a case where you want to use WSL(Windows Subsystem for Linux) via a remote SSH connection. Configuring a remote SSH connection to WSL is not necessarily straightforward because: You need to configure port forwarding from WSL to the host machine WSL does not have systemd, so you need to configure automatic booting of WSL and then SSH server inside it(because you will want to automate everything). Well, let’s take a look at the configuration process step by step.