Found 1082 Articles for Go Programming

Golang Program to Create Filter for the Employees Based on their Salary

Akhil Sharma
Updated on 13-Jul-2023 23:03:25

56 Views

It is important to have the knowledge of filters while working on data sets in go language because there may be cases where you want to analyze data to get customized results. In this article we are going to create a filter on the employee list based on the salary using traditional looping method, functions approach as well as using goroutines. Example 1 In the code given below “FilterEmployeeBySallary()” filters the list of employee based on a salary range and returns the list of employee that falls in that salary range. package main import "fmt" type Employee struct ... Read More

Golang program to create filter for the Employees

Akhil Sharma
Updated on 14-Jul-2023 15:55:13

335 Views

Go Language allows you to apply a filter on particular data for analyzing specified data, work on a particular property of data, data integration and more.In this article we are going to write a program to create a filter for the employees, using iterative filtering, functional filtering, as well as using go language built in filtering function. Syntax filtered := funk.Filter(collection, func(item Type) bool {…}) collection = It is the original collection to filter. This function takes two arguments, a collection and a filtering function. Algorithm Make ... Read More

Golang Program to Create Two Goroutines

Akhil Sharma
Updated on 13-Jul-2023 22:39:39

117 Views

When working with go language there may be instances where you need to create two goroutines for parallel processing, asynchronous operations and more. In this go language article we will explore how to create two goroutines using anonymous functions, named functions as well as using function calls.In golanguage a goroutine is an independent concurrent function, it enables concurrent programming by allowing the functions to run concurrently. Syntax time.Sleep(duration) It is a built-in go language function used to pause the execution of a program. It ... Read More

Golang Program to Creates a Unidirectional Sending Channel and Passes it to a Function that Returns a Unidirectional Receiving Channel

Akhil Sharma
Updated on 13-Jul-2023 22:35:50

57 Views

A unidirectional sending channel is used to send the values to the channel, while the unidirectional receiving channel is used to receive the data from the channel. These channels are used in concurrent data processing, data sharing and more. In this golang article we are going to create a program to create a unidirectional sending and pass it to a function that returns a unidirectional receiving channel using function parameters, type conversion as well as channel composition. Algorithm Define the sender Function that accepts a send-only channel named “ch” of type integer. ... Read More

Golang program to creates a unidirectional sending channel and passes it to a function that takes a pointer to a slice of integers

Akhil Sharma
Updated on 13-Jul-2023 22:21:16

54 Views

There are many cases while working on go language channels where you need to write a program that creates a unidirectional sending channel and passes it to a function that takes a pointer to a slice of integers for data streaming, asynchronous data sharing and more, in this go language article we will write such a program using the make() function as well as using channel types. Syntax ch := make(chan

Golang Program to Find Average Paid Employee

Akhil Sharma
Updated on 13-Jul-2023 22:22:36

59 Views

It is very important to know about the average salary paid to an employee in an organization for analysis, research and rewards. In this article we are going to find out the average employee salary in go language using iteration, reduce function as well as goroutines and channels. Algorithm CalculateAverage is a function that accepts a slice of float64 values salaries as input and returns a float64 value. Set the total to 0 and count the length of the salary slice. Using a ... Read More

How to return an array to the function in Golang?

Aman Sharma
Updated on 10-Jul-2023 17:13:28

2K+ Views

In programming, to make the code more modular, usable, and readable we break the code into different functions. For example, we have to swap two numbers at different places so instead of swapping in place we create a different function and call it everywhere. In some use cases, we need a function that returns multiple values at once. For this, we have a data structure called arrays in programming that is nothing but a collection of multiple values of the same type. In this tutorial, we are going to learn about how to return an array in function as an ... Read More

How to Return a String from the Function in Golang?

Aman Sharma
Updated on 10-Jul-2023 17:10:56

1K+ Views

In programming, to make the code more modular, usable, and readable we break the code into different small blocks and these blocks are known as functions. A string is a data structure consisting of a set of alphabets. In solving any programming problem we want that the function should return some set of alphabets then we create a string in the function that the function returns in the end. This tutorial will explain this concept with the help of two examples. In the first example, we will define two strings and create a function that will return the string ... Read More

How to Pass an Array to the Function in Golang?

Aman Sharma
Updated on 10-Jul-2023 17:04:40

511 Views

In programming, to make the code more modular, usable, and readable we break the code into different functions. For example, we have to sort some set of numbers for which we will create a separate function. For this, we have a data structure called arrays in programming that is nothing but a collection of multiple values of the same type. Once the array of numbers is sorted then at the end of that function we have to return the sorted elements so in this article we will see how to return the array. Syntax The syntax to declare a function ... Read More

How to pass a string to the function in Golang?

Aman Sharma
Updated on 10-Jul-2023 16:59:44

774 Views

In this tutorial, we are going to learn about how to pass a string in function as an argument in Golang. In programming, to make the code more modular, usable, and readable we break the code into different small blocks and these blocks are known as functions. If you have created a string of alphabets and you want to perform some operations on the string then you need to pass that string to the function by passing it as an argument. This tutorial will explain this concept with the help of two examples. In the first example, we will ... Read More

Advertisements