Programming
99 Artikel tersedia
Usage Channel Select Range Timeout
The existence of channels really helps us to manage the goroutines that are running in our program. There are times when we also need to manage many goroutines and many channels are needed. So, this is where select
comes in handy. select
allows us to control data communication through channels. It is used in the same way as the switch
selection condition.
Channel Introduction to Golang
A channel is a link from one goroutine to another and this channel is synchronous
because of blocking data processes. Channels can be defined as variables with the keyword chan
. This variable has the task of sending and receiving data.
Introduction of Go Routine on Golang
Use go-routine when the process to be executed as a goroutine must be wrapped in a function. When calling the function, the go
command is added in front of it. Thus the process will be detected as a new goroutine.
Techniques for Creating Mocking Unit Tests in Golang
When we create a function or code, sometimes we have difficulty carrying out unit tests at several points that we cannot cover with unit tests. So here are several technical ways to carry out unit tests using the mocking technique. But actually we can also use third-party which is already available in several libraries so we just need to use it straight away.
How to Create Integration Tests in Golang
Carrying out integration tests for APIs means that we must at least be able to run the application first so that integrated testing can be carried out.
We need to prepare several cases, test cases that cover the needs of the integration test. For example, the API Endpoint' that we have worked on has a
database,
cache` or other external resource that is related to the continuity of the API Endpoint.
How to Create Unit Tests Using the moq Library in Golang
Carrying out unit tests using this mocking method is usually used if several functions have been carried out in interface
format so that we can assume that if we call the interface
function we believe that it should produce the correct program.
How to Create Benchmark Units in Golang
The testing
package in Golang Programming, apart from containing tools for testing, also contains tools for benchmarking. The way to create a benchmark itself is quite easy, namely by creating a function whose name begins with Benchmark
and whose parameters are of type *testing.B
.
How to Create Unit Tests in Golang
Unit Testing Using the Go Library
programming is not easy, even the best programmers cannot write programs that work exactly as desired every time. Therefore, an important part of the software development process is testing. Writing tests
for our code is a good way to ensure quality and increase reliability.
Getting to Know Hashes Cryptography in Golang
Hashes & Cryptography
The hash
function takes a set of data and reduces it to a smaller fixed size. Hash is often used in programming for everything from searching data to easily detecting changes. The hash
functions in Go are divided into two categories namely cryptographic
and non-cryptographic
. Non-cryptographic
hash
functions can be found under the hash
package and include adler32
, crc32
, crc64
and fnv
.
Get to know Container List and Sort in Golang
In addition to arrays
and maps
, Go has several more collections available under the container package. We’ll look at the container/list
package as an example.
Get to know the Standard String Library in Golang
As programmers who are learning Go Lang, we also need to know Go’s default library packages so that we understand better and have an easier time interacting with the core packages. There are lots of built-in libraries from Golang that can make it easier for us when coding. For example, if we need string conversion, the Go library is provided by default.
Get to know the Input Output Library in Golang
Before studying the Golang IO library, there are lots of functions in the IO library but the most important ones are 2 function interfaces, namely Reader
and Writer
. Reader
is usually used to read data from a file or some provided input/output. Meanwhile Writer
is a function that will later write data to a file or input/output provided by our system.