Found 26504 Articles for Server Side Programming

Golang program to search an item in the hash collection

Akhil Sharma
Updated on 03-Apr-2023 13:31:07

280 Views

In this article, we will write Golang programs to search an item in the hash collection. A hashmap is part of hash collections. Here we are building a hashmap as set of key-alue pairs using Golang’s map which is constructed using map literal. We will execute this program using two examples. Syntax func range(variable) The range function is used to iterate over any data type. To use this we first have to write the range keyword followed by the data type to which we want to iterate and as a result the loop will iterate till the last element ... Read More

Golang program to iterate hash collection and print only values

Akhil Sharma
Updated on 03-Apr-2023 13:23:09

370 Views

In golang we can use hashmap and key functions to iterate hash collection. Hashmap is said to be one of the hash collections. In the hashmap the data is stored in key value pairs as we did below. In this program we will use three methods to iterate the hashmap and print its values. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments func append(slice, element_1, element_2…, element_N) []T The append function is ... Read More

Golang program to get the current weekday

Akhil Sharma
Updated on 03-Apr-2023 13:22:12

491 Views

In this Go language article, we will write proCurrent weekday implies the current day in the week which can be obtained using numerous methods. In this program we will use three examples to get the current weekday for which time package will be imported in the program, it helps in viewing the time. Syntax func Now() Time The Now() function is defined in time package. this function generates the current local time. To use this function, we have to first import the time package in our program. time.Format() This function belongs to the time package. It is used ... Read More

Golang program to get current time zone

Akhil Sharma
Updated on 03-Apr-2023 13:19:11

6K+ Views

Golang has internal functions like Now() Time, and other Time functions that can be used for getting the current time zone. Current time zone in Go is a time zone where people reside in and see the same standard time. In a country like India IST is observed throughout the nation. In this program we will discuss how to obtain current time zone using two examples. Syntax func Now() Time The Now() function is defined in time package. this function generates the current local time. To use this function, we have to first import the time package in ... Read More

Golang program to create a hash collection

Akhil Sharma
Updated on 03-Apr-2023 13:18:29

235 Views

In this article, we will write a Golang programs to create hash collections with the help of make function and map function. Hashmap stores key value pairs that can be accessed via index. In this program we will create a hash collection with the help of two examples. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments. Using Make Function In this method, we will create a hashmap with the help of a make ... Read More

Golang program to demonstrate a simple module

Akhil Sharma
Updated on 03-Apr-2023 13:17:34

211 Views

In this Go language article, we will write programs to demonstrate a simple module. A module in Go is called as the collection of packages namely we can call it packages and sub-packages where the root file will be called as go.mod. In this program we will demonstrate a module using three different examples. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments Example1: Golang program to demonstrate a simple module using basic printing ... Read More

Golang program to create a module with variables

Akhil Sharma
Updated on 04-Apr-2023 08:24:15

422 Views

In golang we can create a module with variable using const or var keywords, orelse we can even import the module . A module in Go is a group of packages. It helps in managing the distribution of the package. Algorithm Step 1 − Create a package main and declare fmt(format package) package in the program where main produces executable codes and fmt helps in formatting input and Output. Step 2 − In the first step, create three variables name, age and address using var keyword and assign these variables the desired values. Step 3 − Then, create a ... Read More

Golang program to perform binary search on a slice of custom structs

Akhil Sharma
Updated on 03-Apr-2023 13:14:13

965 Views

In this Golang article, we are going to perform binary search on a slice of custom structs using iterative and recursive method. Binary search is a search algorithm used to find the position of a specific value within a sorted sequence of elements. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Create a custom Person structure with string type name and integer type age. Step 3 − Now, create a bSearch() function that is used to perform binary search on a slice of Person struct. Step 4 − It initializes the low ... Read More

Golang program to check if a stack is empty

Akhil Sharma
Updated on 03-Apr-2023 13:13:45

290 Views

In this Golang article, we are going to check if a stack is empty using iterative and recursive method. A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. Algorithm Step 1 − First, we need to import the fmt and strconv package. Step 2 − Create a stack structure with an item slice to store the stack elements. Step 3 − Now, define the functions, push(), pop() and peek() to perform the basic operations with the stack. Step 4 − push() adds the item to the end of the stack while pop() removes the last ... Read More

Golang program to reverse a stack

Akhil Sharma
Updated on 03-Apr-2023 13:13:14

244 Views

In this Golang article, we are going to reverse a stack using recursive and iterative method. A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. Algorithm Step 1 − First, we need to import the fmt and strconv package. Step 2 − Create a stack structure with an item slice to store the stack elements. Step 3 − Now, define the functions, push(), pop(), peek(), isEmpty() and print() to perform the basic operations with the stack. Step 4 − push() adds the item to the end of the stack while pop() removes ... Read More

Advertisements