Posts for: #Go

Golang: JSON YAML TOML (config) File Reading.

Reading specific file types (JSON, YAML, TOML)

In the previous post, we have seen how to read files in golang, in this extended post of that part, we will look into reading some specific files used for configuration and storing data like JSON, YAML, TOML, CSV, etc.

We will see how to read files and get individual pieces in the files. We’ll use packages like os, ioutil and encoding to perform reading operations on file and file objects.

[]

Golang: File Reading

Introduction

In the 22nd post of the series, we will be looking into the file-handling process in golang, in the next few posts, we will cover the operations on file using golang. In this first entry of the file handling sub-series, we will understand the READ operation with files. We will see different ways to read a file, it can be word by word, line by line, or even custom chink by chunk.

[]

Golang: Paths

Introduction

In the 21st post of the series, we will be exploring the file paths in golang, we will be exploring how we can deal with paths. By using packages like os, path, io, we can work with file systems and operating system-specific details. In this section, we will see how to resolve paths, details from paths, extract relative or absolute paths, iterate over file systems, etc.

Starting from this post, it will follow a specific topic in the upcoming few posts which will be covering files and paths. We will be talking about dealing with paths and files in golang. This post is just about working with paths.

[]

Golang: Error Handling

Introduction

Error handling is quite an important feature of any programming language to improve the quality and transparency between the user and the application. By raising appropriate error messages, the user can get a clear idea about the things happening in the interface as well as the application can handle the errors with appropriate actions.

In the 20th post of the series, we will be exploring the concept of error handling in golang. From this article, we will be able to learn the fundamentals of error or exception handling in golang, create custom error classes, raise and ignore error messages, and exit or redirect the flow of state of the application when an error is raised.

[]

Golang: Interfaces

Introduction

In the 19th post of the series, we will be taking a look into interfaces in golang. Interfaces allow us to create function signatures common to different structs or types. So, we can allow multiple structs to have a common interface(method) that can have different implementations.

What are Interfaces

Interface as the name suggests is a way to create methods that are common to different structures or types but can have different implementations. It’s an interface to define the method or function signatures but not the implementation. Let’s take an example of Laptop and Phone having the functionality of wifi. We can connect to wifi more or the less in a similar way on both devices. The implementation behind the functionality might be different but they share the same operation. The WiFi can act as an interface for both devices to connect to the internet.

[]

Golang: Closures

Introduction

In the previous part of the series, we covered anonymous functions and in this section, we will look into closures which are quite a cool concept for various things. Closures are basically a function that returns a function instead of a value, so basically we will leverage anonymous functions for creating closures.

Simple Closures

A simple closure can be constructed for understanding how we can use closures in golang. We will return a function from a function, that is a simple closure. So, in the below code example, we have created a function gophy() which takes no parameters but returns a function that returns a string. The function simply returns an anonymous function that returns a string.

[]

Golang: Anonymous Functions

Introduction

We have looked at the defer keyword in golang in the previous part of the series, in this section, we will understand how we can use anonymous functions in golang. We will explore how to declare and use anonymous functions with a few examples.

What are Anonymous Functions

Anonymous functions are quite simple to understand, we don’t define a function, we declare it and call it instantly. An anonymous function doesn’t have a name so hence it is called an anonymous function. As a normal function it can take in parameters and return values. With anonymous functions, we can bind the operations to a variable or a constant as a literal(value). If an anonymous function takes in a parameter, it needs to be parsed immediately after the end of the function body. We will see how we define the syntax and specifications of the anonymous functions in golang.

[]

Golang: Defer

Introduction

In this part of the series, we will be taking a look at the defer keyword in golang. The defer keyword is used for delaying the function call in a particular block of program(function or a loop).

Defer Keyword

The defer keyword is an interesting keyword in golang, it basically holds up the execution of the statement until all the statements around the local scope has been executed. It is basically like a stack holding the execution of statements. You can have multiple defer keywords in the single code block(function or a loop), those will be called by the principle of first in last out.

[]

Golang: String Manipulation

Introduction

In the 15th post of the Series, we will be looking into the details of the String manipulation and performing types of operations in Golang. We will explore string manipulation, concatenation, helper functions, etc. which will help in working with strings in Golang.

String Concatenation

String Concatenation refers to the combining and formatting of strings in Golang. We can combine multiple strings and formating the way we display the strings in Golang. We have a few ways and functions to concatenate strings in Golang.

[]

Golang: Mutable and Immutable Data Types

Introduction

In this 14th Post of the 100 days of GOlang, we will be understanding about the mutable and immutable data types in Golang. Firstly, we will understand the concept of mutability and understand the differences in mutable and immutable data types, further we will explore which data types in Golang are Mutable and Immutable.

Mutable Data Type

Mutable data type is a data type which can be modified without reallocating any chunk of the memory assigned at the time of initialization. In simple words, a variable is mutable if its value can be altered without reallocating itself to a new memory space.

[]