Go Programming Articles

Page 36 of 86

How to check equality of slices of bytes in Golang?

Siva Sai
Siva Sai
Updated on 19-Apr-2023 256 Views

In Golang, checking the equality of slices of bytes is a common task when working with binary data or network protocols. In this article, we will discuss how to check the equality of slices of bytes in Golang using different methods. Method 1: Compare Each Element of the Slices One way to check the equality of slices of bytes in Golang is to iterate over each element of the slices and compare them one by one. This can be achieved using a simple for loop, as shown in the following code example − Example package main import "fmt" ...

Read More

How to Assign Default Value for Struct Field in Golang?

Siva Sai
Siva Sai
Updated on 19-Apr-2023 23K+ Views

In Golang, it is common to have struct types that need to be initialized with default values. In this article, we will explore how to assign a default value for a struct field in Golang. Assigning Default Values for Struct Fields To assign a default value for a struct field in Golang, we can define a default value for the field during the struct type declaration. For example, consider the following struct type − type Person struct { Name string Age int Address string ...

Read More

How to append a slice in Golang?

Siva Sai
Siva Sai
Updated on 19-Apr-2023 7K+ Views

Appending a slice in Golang is a common operation when working with collections of data. In this article, we will explore how to append a slice in Golang. Syntax for Appending a Slice in Golang slice = append(slice, element) The append() function in Golang appends the given element(s) to the end of a slice and returns a new slice. If the original slice has enough capacity to hold the new elements, the underlying array is reused, else a new array is allocated. Example Here's an example of how to append a slice in Golang. package main import ( ...

Read More

How Many Logical Processors Used By Current Process in Golang

Siva Sai
Siva Sai
Updated on 19-Apr-2023 850 Views

In modern computing, multi-core processors are ubiquitous, which can execute multiple tasks simultaneously. In Golang, we can take advantage of this by using concurrency to perform tasks in parallel. However, how can we determine the number of logical processors used by the current process? In this article, we will discuss how to find out the number of logical processors used by the current process in Golang. Using the Runtime Package The Go programming language provides the runtime package, which includes functions that allow us to control and interact with the Go runtime environment. One of these functions is runtime.NumCPU(), which ...

Read More

Higher-Order Function in Golang

Siva Sai
Siva Sai
Updated on 19-Apr-2023 1K+ Views

Higher-order functions are a powerful feature of modern programming languages, including Golang. In this article, we will discuss what higher-order functions are and how they can be used in Golang. What is a Higher-Order Function? A higher-order function is a function that takes one or more functions as arguments and/or returns a function as its result. This means that higher-order functions can be used to create new functions that are tailored to specific needs, making code more efficient and reusable. Higher-Order Function Example in Golang Let's consider a simple example to understand how higher-order functions work in Golang. Suppose we ...

Read More

Golang Program to Check if the String is Alphanumeric

Siva Sai
Siva Sai
Updated on 19-Apr-2023 3K+ Views

In Go programming language, it is essential to check if a string contains alphanumeric characters or not. Alphanumeric characters are a combination of alphabets and numbers, and they are commonly used in passwords, usernames, and other important data. In this article, we will discuss how to write a Golang program to check if a string is alphanumeric. What is an Alphanumeric String? An alphanumeric string is a string that contains a combination of alphabets and numbers. It can also include special characters such as underscore (_) and dash (-), but not all special characters are considered alphanumeric. Alphanumeric strings are ...

Read More

Go vs Java

Sabid Ansari
Sabid Ansari
Updated on 18-Apr-2023 424 Views

Go and Java are two popular programming languages used for developing different types of applications. While both languages have their unique features and advantages, there are some key differences between them that developers should consider when deciding which language to use for their projects. In this article, we'll explore the differences between Go and Java in terms of syntax, performance, concurrency, and more. Go Java Syntax Go has a simpler and more concise syntax compared to Java. Go has fewer keywords and syntax rules, making it easier for developers to read, write and maintain code. ...

Read More

Golang program that removes duplicates, ignores order

Siva Sai
Siva Sai
Updated on 18-Apr-2023 231 Views

When working with slices in Golang, it's common to need to remove duplicate elements from the slice. While there are many ways to do this, one approach that can be particularly useful is to remove duplicates while ignoring the order of the elements. This can be useful, for example, when you want to compare two slices for equality without caring about the order of the elements. In this article, we'll explore a simple Golang program that removes duplicates from a slice while ignoring the order of the elements. We'll break down the program step by step to explain how it ...

Read More

Generate UUID in Golang

Sabid Ansari
Sabid Ansari
Updated on 18-Apr-2023 3K+ Views

Universally Unique Identifier (UUID) is a 128-bit value that is used to uniquely identify objects or entities. UUID is widely used in computer systems for generating unique IDs for objects, documents, and data records. In Golang, we can generate UUID using the "github.com/google/uuid" package. Installing the "github.com/google/uuid" Package Before we can generate UUID in Golang, we need to install the "github.com/google/uuid" package. To install this package, run the following command in the terminal − go get github.com/google/uuid Generating UUID in Golang Once we have installed the "github.com/google/uuid" package, we can use the "uuid" package to generate UUIDs. Here's an ...

Read More

Getting the current date and time with timestamp in local and other timezones in Golang

Sabid Ansari
Sabid Ansari
Updated on 18-Apr-2023 2K+ Views

In Go, it's easy to work with dates and times using the time package. This package provides a set of functions and types for working with dates and times, including the ability to get the current date and time with a timestamp in local and other timezones. In this article, we'll explore how to get the current date and time with a timestamp in local and other timezones using Go. Getting the current date and time with timestamp in local timezone To get the current date and time with a timestamp in the local timezone, we can use the time.Now() ...

Read More
Showing 351–360 of 852 articles
« Prev 1 34 35 36 37 38 86 Next »
Advertisements