Programming

99 Artikel tersedia

02 How to Used HTTP Test in Golang

02 How to Used HTTP Test in Golang

Introduction to HTTP Testing

HTTP Test in Golang has been provided with a special package for creating unit tests for Web features. All of this is in the net/http/httptest package https://golang.org/pkg/net/http/httptest/. By using this package, we can unit test the web handler that we have created without having to run the web application so that we can immediately focus on the handler function that we want to test.

01 Introduction Golang Web Server

01 Introduction Golang Web Server

Web Introduction

The web is a collection of information available on a computer that is connected directly via the internet. This website contains information in any form such as text, audio, video and others. The web runs on an application called a web server, which is an application used to store and convey the contents of web information.

Introduction and Implementation of Golang Embed

Introduction and Implementation of Golang Embed

Introduction to Embed Packages

Since Golang released version 1.16 there is a new feature called Embed. This embed package is a feature that makes it easier to open the contents of a file at compile time, automatically inserting the contents of the file into the variables that we have defined. For more details, you can see here.

Get to know the Repository Pattern in Golang

Get to know the Repository Pattern in Golang

In the book Domain-Driven Design, Eric Evans explains that

Repository is a mechanism for encapsulating storage, retrieval and search behaviour, which emulates a collection of objects

How To Integrate Golang with MySQL Database

How To Integrate Golang with MySQL Database

Introduction to Package Database

In Golang programming, by default it has a package called database. This package has a set of standard interfaces which provide standards for communication into the database so that we can immediately create the program that we will create using this package to access any type of database with the same code. But what will differ is that only the SQL query code is used according to the database used.

Recognizing Package Context With Timeout In Golang

Recognizing Package Context With Timeout In Golang

Package introduction context.WithTimeout

In the previous article we learned context.WithCancel where we manually send the cancel signal from context. But we can also add cancel signal to context automatically by using timeout timings. By using timeout, we no longer need to manually call cancel execution, but with timeout cancel will be automatically executed if the timeout time has passed.

Getting to Know Package Context With Cancel On Golang

Getting to Know Package Context With Cancel On Golang

Package introduction context.WithCancel

Context which can add values, we can also add cancel signals to the context. Usually context cancel is used when we need to run another process, and we want to cancel the process. This context cancel is usually run using a different goroutine so that we easily want to cancel the execution of the goroutine, so we just send a cancel signal to the context then the goroutine we want to stop can be done.

Get to know Package Context With Value in Golang

Get to know Package Context With Value in Golang

Introduction to the context.WithValue package

At the beginning of the context explanation, we know that the context will be created for the first time during initialization using context.Background() or context.TODO(), where the context does not have a value, aka it is still empty. We can add values from a context with a concept like a map, namely [key - value].

Getting to Know Package Context in Golang

Getting to Know Package Context in Golang

Introduction to package context

Context is a package that can store and carry data values, timeout signals and deadline signals. This context runs and is created per request. The context usually carries the value from initialization until the end of the process. This context is sometimes a necessity when we code a program so that from the beginning of the function to the next function the previous value can be used if the process in the next function requires data from the initial process.

Get to know the Package Ticker in Golang

Get to know the Package Ticker in Golang

Introduction to the time.Ticker package

This Golang package is a package that is used to repeat certain events which will continue to be repeated for a certain time. When this ticker has expired it will send a trigger or signal to the channel.

Get to know the Package Timer in Golang

Get to know the Package Timer in Golang

Introduction to the time.Timer package

time.Timer is a package that deals with times or events that will occur when the process is executed. For example, we will provide a ‘delay’ for a few seconds to go to the next process or there is another scheme.

Knowing and Implementing Atomic Sync in Golang

Knowing and Implementing Atomic Sync in Golang

Introduction to sync.Atomic

For atomic operations on variables in golang, the sync/atomic package offers certain low-level methods. In Go, these methods allow multiple goroutines to safely modify shared variables without using locks or other explicit synchronization. Functions like AddInt64, AddUint32, CompareAndSwapInt32, etc. used to perform basic arithmetic on different types of variables can be found in the atom package. The AddInt64 method for example, guarantees that modifications made by other goroutines will be seen when adding a certain value to an int64 variable in atomic style.