Articles by Tuan Nguyen
How to Properly Uninstall Golang (Go Compiler) on Linux, Windows, and macOS
Learn how to properly uninstall Golang (Go compiler) on Linux, Windows, and macOS. Step-by-step removal methods with cleanup tips.
How to Remove or Uninstall a Go Package (go get, Modules, GOPATH)
Learn how to remove or uninstall a Go package installed with go get. Covers Go Modules, tools, GOPATH, and common mistakes.
go.mod file not found in current directory or any parent directory — Why It
There are 2 different ways to solve go.mod file not found. By creating go.mod file using go mod init command or by setting go env -w GO111MODULE
How to PROPERLY upgrade GO version in Ubuntu? [SOLVED]
Step by step instructions to upgrade go in Linux, Windows and MacOS.
GO Import struct from another file [SOLVED]
You can use import to import the package and then reference the struct using package.StructName wherein the name of Struct must start with Capital letters to …
Golang Ticker Explained in Detail [With Examples]
golang ticker is used to perform any task at frequent intervals. golang time.Ticker is similar to time.Timer, but its channel delivers more elements at regular …
Golang memdb Tutorial [With Examples]
golang memdb is a simple key value pair based in memory database. We learned how to create a database, insert records, query and then delete the records. …
How to PROPERLY stop goroutine? [SOLVED]
In today's article, I will guide you on how to stop a goroutine in Golang. A goroutine is a very lightweight thread that is managed by the Go runtime. Every
When does the init() function run in GO? [SOLVED]
Understanding the basics of golang init function and when it is called in the overall flow of the golang code?
30+ Golang Interview Questions and Answers
30+ golang interview questions and answers for Junior (Beginner), Middle and Advanced (Experienced) professionals
Golang JWT (Json Web Token) Examples
In this tutorial we learned how to create HTTP Server and Client using golang JWT (JSON Web Token)
Golang MongoDB Tutorial with Examples
Using mongo-driver and mgo package to use golang mongodb with examples to perform CRUD operations
Golang AWS Lambda Example [In-depth Tutorial]
In this series, we will learn how to set up a serverless framework example for Golang and AWS Lambda. First of all, we are going to walk through how to create
Top 6 Golang Web Frameworks with Examples in
In today's article, I will introduce some web development frameworks in Go. The Google Go language (also known as Golang) has become one of the top choices
Golang vs Rust | Which language to choose in
Comparing different aspects of golang with rust programming language
Learn Golang Chi to Master the Craft of Web Services
Discover the transformative power of Golang Chi in web development. Our comprehensive guide provides insights and practical knowledge, equipping you to create …
Golang remove backslash from string [SOLVED]
We can use strings.replace() and strings.replaceall() function to remove backslash from string in golang by replacing backslash with empty character
PROPERLY delete an element from Slice in GO [SOLVED]
2 different methods to remove elements from slice in golang. We can either maintain the order or remove elements without maintaining the order
Golang Timing - RIGHT way to measure execution time in GO
We explained two methods to achieve golang timing to measure execution time of go code using time function
How to write logs to file in Golang? [SOLVED]
In this tutorial, we will learn how to write logs to file in Golang. We have several ways to save the application log to specific files: we can use the
GO capture ctrl+c signal & run cleanup function? [SOLVED]
In this tutorial, we will answer the question "Is it possible to capture a Ctrl+C signal (SIGINT) and run a cleanup function, in a "defer" fashion" in Golang.
Golang Performance Comparison | Why is GO Fast?
How to perform Golang Performance Benchmarking and Testing
Golang Websocket Examples [Server and Client]
Examples to setup golang websokcet server and client for testing purpose.
How to handle defer calls with os.Exit in GO? [SOLVED]
In this tutorial, we will guide you on how to handle defer calls with the os.Exit(). The defer keyword in Go is a statement used to defer the execution of a
Golang Ticker loop to iterate over time.Tick channel
Execute a ticker in for loop and then stop the loop using stop() function. We can also break the ticker loop channel conditionally.
How to use goroutine return value? [SOLVED]
In this example we will use golang channel to fetch the goroutine return value:
Golang SQLite3 Tutorial [With Examples]
Golang sqlite tutorial with CRUD Operation. Executing commands on SQLITE database, Select statement, Insert, Read and Delete Operation with examples
Golang http - Create HTTPS Server and Client
Use golang http to setup a basic and advanced web server and client. The client go code will establish communication with HTTPS server over TLS, MTLS or …
Golang prompt - Create interactive CLI prompt in GO
Create a simple and interactive golang prompt with examples
Import local packages without GOPATH [SOLVED]
In today's post, we are going to answer the question "Can we import the local packages without the GOPATH". We already have an article about how to organize
How to import private Github Repos in GO? [SOLVED]
Creating libs and sharing them among applications is one strategy to shorten the time needed to develop a new project and make your team's work easier. Each
Golang Viper: The Unsung Hero of Configuration Wizards
golang viper tutorial to source YAML, JSON or ENV files and get variables. Set default values for empty or missing variables using viper.SetDefault
Cannot find package even if GOPATH is set [SOLVED]
Sometimes you will encounter the "Cannot find package" error (even though GOPATH is set) when building a Golang module. In this article, we will explain why
Golang Compare String PROPERLY [3 Methods]
golang compare strings using comparision operators, compare() method or equalof() method
How to do repetitive tasks at intervals GO? [SOLVED]
In today's post, I will introduce to you some ways to do some repetitive tasks at intervals in Golang. We can use the time.Ticker() function or use a channel
How to import local package in GO? [SOLVED]
Step by step instructions to setup golang workspace and import local package with examples
Managing golang connection pool [Practical Examples]
In the previous article, I introduced to you the ways to work with SQL in Golang. You don't need to change the defaults for the sql.DB connection pool for the
How to get current directory in Golang? [SOLVED]
There are 4 different methods to get current directory in golang. Method-1: The os package and Executable() function Method-2: file/filepath and the Abs() …
Golang generate random string Examples [SOLVED]
Multiple examples covering golang generate random string using rand function. Generate alphanumeric, special characters, uppercase, lowercase strings
Setting HTTP Cookie in Golang [SOLVED]
Examples to set HTTP cookie in golang web server. Fetch HTTP cookies.
How to check if struct is empty in GO? [SOLVED]
This article describes a few methods for determining whether a struct in Go is empty. It includes structs having fields that are comparable and
Master Golang JSON Omitempty: No More Rookie Errors
Explore the dynamic capabilities of Golang JSON Omitempty to revolutionize your data structuring and serialization. Dive deep into expert techniques, unlocking …
Golang Parse JSON (With or Without Struct)? [SOLVED]
golang parse json file, golang parse json array, golang parse json response without struct, golang parse json to struct, golang parse json to map, golang json …
Golang slice append return value? [SOLVED]
In the previous chapter, we discuss how to use append function in Golang. append is a built-in function which appends elements to the end of a slice. If it
Top 8 Golang Development IDEs [With Features]
Although Golang may not be the most popular programming language, it is employed by many major companies, like Google, Uber, DropBox, DailyMotion, and many
Golang Hello World Example for Beginners
Step by step instructions to create your first golang hello world program with examples
Golang search for an element in slice [SOLVED]
In this tutorial, we will try to implement some algorithms to search for an element in a slice. Go before version 1.18 does not provide any built-in methods
Print Function, File Name, Line Number in GO [SOLVED]
In this tutorial we will share different methods to print or get logrus line number, file name, function name of the go code.
How to pass array to function in Golang? [SOLVED]
Learn how to pass array to function in golang using different examples
How to pass slice to function in Golang? [SOLVED]
There are multiple ways we can pass slice to function in golang. We will explore through some of the examples
Is golang tuple possible? [SOLVED]
By design golang tuple is not possible but we can work around this by using interfaces and generics.
How to do https request with bad certificate? [SOLVED]
We can use InsecureSkipVerify to do HTTPS request with bad certificate.
Golang read and update same file [SOLVED]
Update file using os.OpenFile with os.O_APPEND flag and Write() function, Using WriteString() function to append string to a file, Using WriteAt() function to …
Learn to Clone or Copy Map in GO Like a PRO [5 Methods]
Learn to clone map or copy map in GO using 5 different methods. Perform either deep copy or shallow copy of maps
What the Hell is Golang Anonymous Structs? How to Use it?
Explore the dynamic world of Golang Anonymous Structs! Dive into this insightful guide to uncover powerful strategies, avoid common pitfalls, and harness the …
Golang Variable Naming Convention Guideline and TIPs
Explore the indispensable Golang Variable Naming Convention to elevate your coding practices. Dive deep into strategies that will enhance readability, improve …
Convert Golang Interface to String [7 Methods]
golang interface to string conversion is not supported directly but we can use type assertion or fmt.Sprintf to do the type casting
Check if Key Exists in GO Map [6 Proven Methods]
We will explore following methods to check if key exists in map in golang. terate over map elements and look out for the key, Using index expression, Perform a …
Golang Time Format Examples [With Explanation]
golang time format yyyy mm dd, milliseconds, hmmss, timezone, rfc3339, utc, golang time parse format
Golang UDP Server and Client Example [Tutorial]
Step by Step instructions to set up golang UDP Server and Client with Examples
Golang Parse YAML file [With or Without Struct]
We can use YAML package in golang to parse YAML file and store the content inside struct or map using yaml.Unmarshal.
How to change int to int64 in Golang? [SOLVED]
In Golang, it is very simple to convert an int to int64. In today's post, we will show you some simple examples of converting an int to int64. Depending on
Golang iterate over slice in reverse? [SOLVED]
In Golang, iterating over a slice is surprisingly straightforward; In this article, we will learn how to iterate over a slice in reverse in Go.
How to get current time in milliseconds in GO? [SOLVED]
In this tutorial, we will try to get Unix time in milliseconds from a time.Time in Golang. The built-in time package provides some functions to help us to
Golang Padding String, Int or Float [SOLVED]
In this tutorial we have covered different examples for golang padding or formatting of string and integer values. We can perform formatting using whitespace or …
How to use go get specific version in GO? [SOLVED]
In this tutorial, we will show you how to import a package on a specific version. Your code may occasionally require extra functions not available in your
How to pass multiple values into URL in GO? [SOLVED]
When building an HTTP server and client, we might need to pass multiple strings as parameters to an HTTP URL. In this tutorial, we will introduce some methods
How to set golang HTTP client timeout? [SOLVED]
In this tutorial, we will explain some methods to set timeout for HTTP requests. A Request Timeout header is defined for Hypertext Transfer Protocol (HTTP).
Subtract time.Duration from time in GO [SOLVED]
In Golang, we usually have to deal with time management, we do need to do some operations such as adding, and subtracting a duration from time. We will walk
Split a string and assign it to variables GO? [SOLVED]
In this tutorial we will explore different methods to split a string and store into variables using golang.
How to convert io.Reader to string Golang? [SOLVED]
In this article, we will walk through some examples of converting from an io.Reader to a string in Go.
What is & and * in Golang? [Solved]
In this tutorial we will explore what is & and * icon or operator in golang and what is it used for?
How to convert float64 to int Golang? [SOLVED]
In this tutorial, we will walk through some ways to convert a float64 to int in Golang. As introduced before, we can convert float64 to a string using the
How to Compare Struct, Slice or Map in GO? [SOLVED]
In Golang, the DeepEqual function is used to compare struct, slice, and map equality. It is used to determine whether or not two items are "deeply equal".
How to trim leading and trailing spaces GO? [SOLVED]
In this tutorial, we are going to examine some examples of trim leading and trailing white spaces of a string in Golang. Golang provides the built-in package
GO nil detection [interface, slice, pointer, struct, map]
How to detect nil in golang pointers, structs, interface, map, slice with examples
Can functions be passed as parameters GO? [SOLVED]
In this tutorial, we will learn how to pass functions as a parameter to another function in Golang. Since Golang functions are first-order variables so it has
SOLVED: How to reverse sort slice of integer in GO
There are two methods to sort slice of integer in reverse or descending order. To sort in descending order, you have to implement the sort.Interface interface …
[SOLVED] Define GO function with multiple types
We can either use an empty interface using interface{} or use generics to define golang function accept two types or multiple types as an input.
Golang print type of an object [SOLVED]
In this tutorial we covered golang print type of an object using string formatting, go reflect package and type assertions
Golang array contains specific element or not? [SOLVED]
In this tutorial we have covered different examples to cover golang array contains elements. Use for loop to check for string, int or float64 element in array …
PROPERLY delete an element from map in GO [SOLVED]
We can delete elements from map using 2 different methods. Check if the key exists and delete or delete the key without checking.
Golang concatenate or merge two or more slices [SOLVED]
We can use copy() and append() function to merge or concatenate two or more slices in Golang.
Golang read multiple lines from stdin [SOLVED]
We can use fmt.Scan(), bufio.Reader(), bufio.Scanner() function in golang to read multiple lines from STDIN input with examples.
Fix 'declared and not used' message in Golang [SOLVED]
How to fix declared and not used error in golang with examples
Golang Concat Slices - Remove Duplicates [SOLVED]
In this article we learn about different methods which can be used to golang concat slices and remove duplicates
Using golang constants in struct [SOLVED]
In general, golang does not allow declaring a constant struct and constant within a struct. But we can use a custom function to perform this purpose
How to sort array of ints in Golang [SOLVED]
Golang sort array of ints using 3 different examples. Example 1: Convert to int slice and then use the Ints() function. Example 2: Using Slice() function to …
Golang Print Struct Variables [SOLVED]
Golang print struct variables on console using 4 different methods. Method 1: Using fmt package. Method 2: Using json package. Method 2: Using go-spew package. …
Declare a constant array in Golang [SOLVED]
Slice or const array are not supported in Go. It is thus because Go computes constant values at compilation time. Slices or arrays are always assessed in- …
Declare new error in Golang [SOLVED]
There are various ways to declare new error in golang such as using errors.New() function or Using Errorf() with fmt package to return an error, Define a custom …
How to append to a slice in Golang [SOLVED]
Different ways in golang to append to slice. We can append one slice to another, strings, byte string, int, elements to a slice.
How to split string in Golang? [SOLVED]
Golang string Splitusing strings.Split(), SplitAfter(), Fields(), FieldsFunc() function. Perform Split string with regular expression
How to multiply duration by integer in GO? [SOLVED]
In this tutorial, we will walk through some examples of converting int to time.Duration and doing some operations (division, multiply) with it. The built- in
How to turn html body tag into string in GO? [SOLVED]
In order to make the string printable as plain text, we need to strip the string of its tags. In today's post, we will examine some methods to convert HTML to
How to make Golang POST JSON request? [SOLVED]
In the previous chapter, we have shown you some examples of working with the HTTP server and client in Golang. The built-in package net/http in Go provides
Remove fields from struct or hide them in JSON [SOLVED]
Learn how to remove fields from struct in golang or hide them.
How to set default values in GO structs? [SOLVED]
There are multiple ways to set default values in go struct. We have explored some of the possible ways such as using an init function, using a separate …
What is the zero value for time.Time in GO? [SOLVED]
The zero value of type Time is January 1, year 1, 00:00:00.000000000 UTC. The IsZero() method returns whether a time has a zero value or not.
Convert byte slice to io.Reader in Golang [SOLVED]
In this post, we'll examine how to translate a byte slice into an io.Reader in Golang. In Go, a byte slice is a dynamic array (slice) of bytes, which can
Golang Fuzz Tutorial With Examples
In this guide, we'll go over the fundamentals of fuzzing in Go. We will create some fuzz tests for functions using the go command, and troubleshoot and debug
What does underscore in front of import statement mean in GO?
The underscore in front of an import statement is solely for its side-effects.
Golang cobra Tutorial [With Examples]
Golang is a perfect programming language for creating CLI applications. In today's post, I will introduce you Cobra - a library for creating powerful modern
Install Golang on Windows [Step-by-Step]
Step by Step instructions to install golang on WIndows using official archive and choclatey
Golang Embedding Examples [Tutorial]
Using golang embedding with structs, interfaces, methods and files with examples
Golang SQL Tutorial [CRUD Operation]
Step by Step instructions to create and manage QL database using golang sql module. Perform CRUD Operation using GO.
Golang Packaging Structure & Best Practices [Tutorial]
Learn about golang packaging with how to create custom packages, install third- party packages, import packages, export package members, and organize Go code …
Golang Command Line Arguments Example [Tutorial]
Parse single or multiple command line arguments in golang. Use flag and other methods to read and implement command line arguments
Copy different data types in GO [shallow & deep copy]
Different methods to copy structs in golang using deep copy and shallow copy
Golang pass by value VS pass by reference [Explained]
In conclusion, pass-by-value copies the value, but pass-by-reference provides the memory location.
Golang TCP Server and Client Example [Tutorial]
Step by step instructions to setup golang TCP server and client with examples
Golang regexp Examples [In-Depth Tutorial]
In the Python section, we have introduced some examples of working with regex (regular expression). In Golang, the built-in package regexp implements regular
Golang os.Stat Usage and Examples
golang os state Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError.
Golang seek Examples [Tutorial]
Golang seek from has three constant values as follows: SeekStart = 0: the file's starting point is used. SeekCurrent = 1: the seek is made in relation to the …
Golang reflect Examples [Tutorial]
Golang reflect implements run-time reflection, allowing a program to manipulate objects with arbitrary types.
Getting started with Golang Gopher
Gopher stands for the Go project and Go programmers everywhere, and is one of the most popular things in the Go world
Golang sha512 Hashing Examples
Use golang sha512 package to generate sha512 encrypted hash for text, string and files.
Golang io.ReadCloser Examples
Golang io.ReadCloser interface is built out of an io.Reader and an io.Closer:
How to pass default parameter to golang function?
Golang does not support optional parameters (can not set default values for parameters). But there are different methods to add golang default parameter.
Golang Queue Implementation
We can use slices, lists, or channels for golang queue implementation
Golang []byte to int Conversion [SOLVED]
Convert ASCII []byte to int, Convert ASCII []byte to int with validation, Using math/big package to convert []byte to int, Using binary package to convert byte …
Golang GOPATH vs GOROOT Comparison
We perform a comparison and difference between GOPATH and GOROOT variable available in go env.
Golang os.file Usage and Examples
We explore different golang os modules while working with files.
Golang Encrypt Decrypt String, File, Binary, JSON, Struct
Golang encrypt decrypt String, File, Binary, JSON and Struct with Examples
Golang URL Encode & Decode Practical Examples
In this tutorial we will explore golang url encode and decode using url.QueryEscape, url.PathEscape, url.QueryUnescape and url.PathUnescape with examples
Golang Graphql Tutorial with Examples
Complete golang graphql tutorial with sample schema and resolving the content with schema. Integrate graphql with HTTP
Golang Sort Slice [Ascending & Descending Order]
Golang sort slices with strings, integers, float64 in ascending and descending order
Golang Type Assertion Explained with Examples
Golang type assertion is a mechanism for working with the underlying concrete value of an interface. Type switches use switch blocks for data types and allow …
Golang JSON Unmarshal Examples
Use golang json unmarshal to parse JSON data with simple and complex structured data and unstructured data with examples
Golang FlashDB Tutorial- In Memory Database
Golang flashdb is an in memory database written in golang. Read, Write, Store, Update and Delete key and value content inside the database with examples
Golang lint - Different methods with Best Practices
Golang linting is a way to verify the go code to identify any kind of compilation issues, or performance improvements which can be done. We can perform linting …
Golang Math Package Examples [Tutorial]
golang math package examples to perform calculations in go code using math sub packages
Go Prompt - Create Interactive CLI prompts with Examples
To read input from users in Go and create an interactive CLI based go prompt, we use the fmt, bufio, and os packages.
Golang generate random boolean [Simple Examples]
Use rand.Intn() function to generate random boolean in golang
Golang length of map [2 Easy Methods]
use two different methods to get golang length of map. Using len() function or iterate over the map elements and count each occurence to get the length.
Golang iterate over Array [2 Methods]
There are two possible methods in golang to iterate over an array using for loop with range function or with len(array) function
Golang sha256 Hashing Examples
golang sha256 hashing examples to hash a string of text or an entire file using sha256 function
Golang Bool to String Type Casting [2 Methods]
There are 2 methods to convert golang bool to string type. We can use FormatBool() function or Sprintf() function for the type casting
Golang Tabs vs Space for indentation - Formatting Tips
The official recommendation is to use golang TABs for indentation and formatting. We can format go code automatically using go fmt or goimports command
Golang power calculation using math.Pow() function
Calculate the power of integers and float number using math.pow() function and other possible methods.
Golang string interpolation Explained [With Examples]
The golang string interpolation can be done using different fmt packages such as Printf(), Sprintf(). Fprintf() and Errorf()
How to PROPERLY write multiline strings in GO?
How to declare golang multiline string. Declare a multiline string with and without special characters and escape characters used for new line or Tab delimiter. …
