Found 1082 Articles for Go Programming

Golang program to format time in AM-PM format

Akhil Sharma
Updated on 03-May-2023 13:01:03

690 Views

In Go language article, we will write programs to format time in AM-PM format using now and format package, as well as using now and format function with minutes and seconds. The current time can be obtained using Now function from the time package whereas we can format the time using Format function as we are going to use in this article. In this article we will use “now and format function” to get the formatted time in AM-PM format. Syntax funcNow() Time The Now() function is defined in time package. This function generates the current local time. To ... Read More

Golang program to display current date and time

Akhil Sharma
Updated on 03-May-2023 12:58:46

813 Views

In Golang we can display current date and time using “now and format function”, “now function”, and “strconv package” to display the current date and time. In this article we are going to learn how to create a golang program to display current date and time using various Examples. Syntax funcNow() 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. strconv.Quote() This function belongs to the strconv package. It’s goal is to return the output in ... Read More

Golang program to get the hash elements as a sorted array from the hash collection

Akhil Sharma
Updated on 03-May-2023 12:54:13

212 Views

In golang we can obtain the hash elements as a sorted array from the hash collection using iteration, sort package as well as slice function. A hash collection contains a hashmap which is used to store items in the form of key value pairs. A hashmap is implemented using a hash function. 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 used to ... Read More

Golang program to replace the items of hash collection from another hash collection

Akhil Sharma
Updated on 03-May-2023 12:53:21

89 Views

In this Go language article, we learn how to replace the items of hash collection from another hash collection using ok idiom method as well as a loop to replace the items of hash collection. A hash collection contains a hashmap which is an efficient data structure 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 of the variable. Algorithm ... Read More

Golang program to delete the item from the hash collection based on a specific key

Akhil Sharma
Updated on 03-May-2023 12:51:24

80 Views

In this article, we will learn how tp write a Go language programs to delete the item from the hash collection based on a specified key using ok idiom method and delete keyword A hash map is a part of the hash collection. It stores the data as key value pairs which helps in the efficient execution of the program. Algorithm Step 1 − This program imports two packages fmt and main where fmt helps in the formatting of input and output and main helps in generating executable codes Step 2 − Create a main function Step 3 ... Read More

Golang program to get value from the hash collection based on specified key

Akhil Sharma
Updated on 03-May-2023 12:20:11

83 Views

In this golang article, we will write Go language programs to get the value from the hash collection based on a specified key using found variable as well as using ok idiom method. A hash map is a data structure that belongs to the hash collection. It stores the data in the form of key value pairs. 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. Algorithm Step 1 − This program imports ... Read More

Golang Program to check a file has readable permission or not

Akhil Sharma
Updated on 03-May-2023 12:17:05

1K+ Views

While working with file in go language it is very important to check if a file has readable permission or not, because without the read permissions a program cannot read the content of files. Here we will use os.Stat() function , os.Open() function, as well as ,ioutil.Readfile() function to check if a file has readable permission or not. Algortihm First, we need to import the "fmt" and "os" packages. Then, store the text file into a variable and call the specified function present in the respective package. If an error is generated then print it on the screen. ... Read More

Golang Program to Find the current working directory

Akhil Sharma
Updated on 03-May-2023 12:16:09

383 Views

In go language we can use the functions present in os package like Getwd() and Args to find the current directory in which our code is getting executed. The directory from which the program is currently being run is called the current directory. It is also known as present working directory. The directory in which the program is currently running is called the working directory. It is the parent directory for any files or the or directory that are created during runtime. Algorithm First, we need to import the "fmt" and "os" packages. Then, start the main() function. Inside ... Read More

Golang Program to Get the size of a directory

Akhil Sharma
Updated on 03-May-2023 12:15:07

1K+ Views

In golang, it is easy to get the size of file, but getting the size of a directory is a bit complex. Here in this article we will use os.Open() function , walk function as well as readdir() function to get the size of a directory. Syntax funcReadDir(dirname string) ([]fs.FileInfo, error) The ReadDir() function is present in os package and is used to read the directory. The function accepts one argument which is the name of the directory which is to be read and returns a list FileInfo for directory’s content. If an error is generated while reading the ... Read More

Golang Program to Display all the directories in a directory

Akhil Sharma
Updated on 03-May-2023 12:14:12

98 Views

In this golang article, we will write a go language program to display all the directories in a given directory using the Go programming language using the open() function, using the walk function as well as using the readdir function. Method 1 In this Example we will write a go language program to display all the directories in a directory by using the open() function present in os package. One of the simplest methods to display the directories in a given directory is to use the os.Open() function. Example package main import ( "fmt" ... Read More

Advertisements