Image for post
Image for post
Photo by tofayel ahmed on Unsplash

Anonymous functions are functions without a name. They are also known as Function literals.

This article is part of the Functions in Go series

You define anonymous functions using the usual func keyword, but with a slightly different syntax. first as a reminder, here’s what a regular function’s syntax looks like:

func FunctionName() {  
...
}

Now here’s what an Anonymous Function’s syntax looks like:

func() {  
...
}()

Notice we have an extra pair of round brackets at the end. Those are used for passing in arguments; we’ll cover that a bit later. …


Image for post
Image for post
Photo by Anthony on Unsplash

Variadic functions are functions that are flexible about the number of arguments you can pass into it.

This article is part of the Functions in Go series

Variadic functions are defined using 3 dots, ..., here’s an example of this, where shoppingList ( line 8) is a variadic function.


Image for post
Image for post
Photo by freestocks on Unsplash

The Go standard library's errors package makes it quick and easy to create error variables. Once the error variables are created, you can then use the if-statement pattern to decide what to do with it.

This article is part of the Error Handling in Go series.

The error’s package is a popular alternative to using Go’s built-in error type. That’s because using this built-in (interface) type requires a bit of leg-work, in terms of defining an error (struct) data type and a corresponding Error() method (as demoed in Part 2).

On the other hand, the errors package doesn’t require any…


Image for post
Image for post
Photo by Vitaly Sacred on Unsplash

To understand what error types are and how they work, you first need to be familiar with Go structs, methods, interfaces, and pointers.

This article is part of the Error Handling in Go series.

The error type is an interface type that comes built-in with Go.

type error interface {
Error() string
}

This essentially means that if we define a user-defined data type (i.e. …


Image for post
Image for post
Photo by Erik Mclean on Unsplash

When something unexpected occurs, then you want your app to raise that as an error and then perform some follow on tasks to address that error, aka error handling. Raising errors and error handling are common traits in well-written programs.

This article is part of the Error Handling in Go series.

In a lot of modern programming languages, raising errors + error-handling is done with something like a try...catch construct, however that construct doesn’t exist in Go. Instead, Go takes an errors as values approach. This approach involves capturing errors into variables using Go’s built-in error type. …


Image for post
Image for post
Photo by Jonas Jacobsson on Unsplash

This article is part of the Data Types in Go series.

In Go, creating a variable can be done in 2 parts.


Image for post
Image for post
Photo by C Dustin on Unsplash

Go comes built-in with a number of Primitive and Composite Data Types. However, you can also create your own custom user-defined data types, and that’s done using Structs.

This article is part of the Data Types in Go series.

Structs (short for “structure”) lets you create composite data types for storing a collection of key-value pairs. Structs are often used for representing real-world entities.

Structs are defined using the type statement (lines 10–16). After that, you can use your new data type to create variables (lines 18–24).

Sher Chowdhury

Blogger at codingbee.net

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store