- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 555 Articles for Go Programming

Updated on 01-Mar-2023 12:00:19
In Go programming language, a new module is initiated using init command after which we can import other modules in our code. There is no concept of class in Go, only structs are used. In this article, we will use one example to include a module inside the class. In this example, we will create a Circle struct whose area will be printed on the console. For this example, we will import math and fmt packages outside the struct but they can be used anywhere. The print statement is executed using Printf function from the fmt package. Algorithm Import ... Read More 
Updated on 01-Mar-2023 11:59:43
We can create a block in golang using curly braces and then create a variable inside the block to have the scope only inside the block and not outside it. In this article, we will use three examples to create a block using curly braces. In the first example few statements will be printed inside and outside the block, in the second example comparison value will be printed inside the block and in the third example function will be used to demonstrate the use of block. Algorithm Import the required packages in the program Create a main function In ... Read More 
Updated on 01-Mar-2023 11:58:41
Golang has json package that is used for converting the hask collection into strin. A hashmap belongs to hash collection which stores the data as key:value pairs, whereas a string is a sequence of characters and it is immutable. In this article, we will use two examples to convert the hash collection into string. In the first example, the Json package will be used to convert the map to encoded byte array whereas in the second example sort package will be use along the loops. Syntax json.Marshal() This function belongs to the JSON package and it converts the value ... Read More 
Updated on 01-Mar-2023 11:56:22
We are going to calculate the current time using the Now function from time package in Go programming language for demonstrating the time arithmetic. The time arithmetic is calculated using mathematical functions. In both examples, we will use mathematical calculations to find the past, future and the duration using Sub function. The output is printed using Println function from the fmt package. 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. func sub() ... Read More 
Updated on 22-Feb-2023 15:32:35
Golang has a large range of internal packages to work with the directory. The directory in which the application is operating is known as the current working directory. Here we can use the OS packages as well as the path/filepath package of Golang to get current working directory. In the OS package we can use os.Getwd() function to the current working director. Whereas in path/filepath package we can use filepath.Abs and filepath.dir to get the filepath of the current working directory. Method 1: Using os.Getwd() function This method uses the os.Getwd function from the os package to get ... Read More 
Updated on 22-Feb-2023 15:31:47
In go we can use io and os package to perform various operations with file. In this article, we are going to use ioutil.readfile function to read the file and then the string function to convert the file data to string. From OS package we are going to use os.open to open the file and use string operation to convert the data to string. Method 1: Using io/ioutil package In this illustration, the file's contents are read into a byte slice using the ioutil.ReadFile function. The byte slice is subsequently transformed into a string using the string function. The contents ... Read More 
Updated on 22-Feb-2023 15:29:47
Golang has packages like os, io, and Archie/zip that can be used to read and print all the files from a zipped file. A zip file is a compressed collection of a set of files/folders. The OS package is used for performing copy operations, the io pacakge is for reading and writing operations whereas the archive/zip package is for unzipping and zipping the file. In this article, we are going to learn about using all these packages to perform the copy and unzipping of the files and printing the same. Method 1: Using io and os package This program uses ... Read More 
Updated on 22-Feb-2023 15:27:42
In golang there are various internal packages such as bufio, os and io that can be used for reading the content of a file line by line. The bufio and os packages are used for opening and scanning the file using os.open and bufio.NewScanner function. The io package we are going to use ioutil.ReadFile to read the file from the given destination and the use the string function to display it in the output. Method 1: Using bufio and os package In this illustration, bufio.NewScanner is used to read line by line content and os.Open is used to open the ... Read More 
Updated on 22-Feb-2023 15:26:31
Golang has OS package such as OS.open(), os.closs(), os.copy() and move more that are used for performing different operations with the external files. Similiary we have io package in golang that is used for performing read and write operations on the external file. Here in this article, we are going to use these two packages to print all the files in the given directory. Method 1: Using OS Package This program opens the provided directory and reads its contents using the os package. A slice of os.FileInfo objects, which are returned by the Readdir function and include details about each ... Read More 
Updated on 22-Feb-2023 14:52:52
In Golang, we can use io and os packages to append a string in an existing file. file contains data that can be manipulated in many ways like editing and writing the data. In this article the first method will demonstrate the application of os.Open file of OS package. In the second method, we are going to demonstrate the application of io package. Method 1: Using OS Package In this method, we are going to use os.OpenFile function of OS package in Golang. The permissions for the file are specified by the 0644 parameters. The file will be created ... Read More Advertisements