- 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 22-Feb-2023 14:33:43
In Golang, we can use openfile() and Stat() function to check whehter a file has writable permission or not. Here we have written two examples. in the first one we are using OpenFile() method present in the os package while in the second one we are using the Stat() method present in the os package respectively. Method 1: Using OpenFile() Method In this method, we will use the OpenFile() function to check the write permission of a file. This function opens a file with the given name and options, and returns a pointer to a File structure. Syntax func OpenFile(name ... Read More 
Updated on 22-Feb-2023 14:27:40
In golang we have different inbuild function like Stat(), Open() and mkdir() to check whether a directory exist or not . Here we are using three functions. in the first one we are using the Stat() function present in the os package while in the second and third example we are using Open() and mkdir() function respectively to implement the result. Method 1: Using os.stat() Method The os package provides the Stat() function to get information about a file or directory. If the directory exists, the function returns a FileInfo structure, otherwise, it returns an error. Syntax func ... Read More 
Updated on 22-Feb-2023 14:25:39
Golang provides several methods to remove a specified directory, including using the os and filepath packages. Removing a directory is a critical operation, and caution should be exercised when performing this task. This article will discuss the different methods to remove a directory in Golang, along with the syntax and algorithm for each method. Method 1: Using The os Package The os package in Golang provides several functions to perform operating system-related operations, including removing a directory. The Remove function of the os package is used to remove a directory. Syntax Remove(dirName) The Remove() function is present in os ... Read More 
Updated on 22-Feb-2023 14:24:24
In Golang, we have two internal functions - ReadDir() and Walk function to get a list of filenames prenent in a specific directory. Here we have write three examples. In the first example We will use the ReadDir() function present in ioutil package while in the second one we are using the walk function present in the filepath package. Method 1: Using ioutil PACKAGE The ioutil package in Golang provides several functions to perform input/Output operations, including reading the files and directories. The ReadDir() function of the ioutil package is used to get the list of files in a specified ... Read More 
Updated on 22-Feb-2023 14:23:29
The Go programming language provides various methods to obtain the home directory of the current user. This information can be useful in many applications, such as file management, system configuration, etc. In this article, we will discuss different methods to get the home directory in Go along with syntax and examples. Method 1: Using os.UserHomeDir() The os.UserHomeDir() function is part of the Go standard library and is the simplest and most efficient method to get the home directory of the current user. Here is an example that demonstrates the usage of os.UserHomeDir() Syntax func UserHomeDir() (string, error) The UserHomeDir() ... Read More 
Updated on 22-Feb-2023 14:20:48
One of the features of Go is the ability to search and retrieve files based on a specified pattern. In this article, we will discuss different methods to get the list of filenames that match a specified wildcard pattern in Go, and provide syntax and examples for each method. Method 1: Using the "filepath.glob" The "filepath.Glob" method is the easiest and most straightforward way to retrieve the list of filenames that match a specified wildcard pattern. The function takes a pattern as input and returns a slice of strings that match the pattern. Syntax filenames, err := filepath.Glob(pattern) The ... Read More 
Updated on 22-Feb-2023 14:18:40
In Go, a directory is a special type of file that holds other files and directories. A directory is used to organize files on a file system and provides a structure to the file system. Go provides several functions in the os package to work with directories, including: os.mkdir, os.remove, os.open, etc. Syntax func Stat(name string) (fi FileInfo, err error) The Stat() function is present in os package and is used to check the status of a particular directory. The function takes a string parameter name, which represents the path of the directory. It returns a FileInfo structure, fi, ... Read More 
Updated on 22-Feb-2023 14:17:00
In the Go programming language, a file is a named resource for storing data that can be read from or written to. It provides a way for the program to persist data, even after the program has finished executing. Here in this article we will discuss different methods using which we can count the number of lines in a file. Method 1: Using a user-defined function In this method, we will write a go language program to count the number of lines present in the file by using bufio, fmt and os packages. Algorithm Step 1 − First, ... Read More 
Updated on 22-Feb-2023 14:14:39
In Go, postorder tree traversal is a technique in which the left child is visited first, then the right child, and finally the root node is the definition of the order. This order is frequently used to carry out certain activities on a tree, including releasing memory that the tree has consumed. We will implement postorder tree traversal using two methods the first one uses slices and the second one uses stacks. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first argument ... Read More 
Updated on 22-Feb-2023 14:02:39
In Go programming language, a tree is a data structure in which each node has a value and zero to many nodes as children. The root node is the node without a parent, while the leaf node is the node without children. Trees can be employed for a variety of tasks, including data storage, sorting, and searching in hierarchical structures. We will use two methods to count no. of leaf nodes in a tree. In the first method TreeNode struct is used whereas queue is used in the second example to execute the program. Method 1: Using TreeNode Struct This ... Read More Advertisements