Go – AppDividend https://appdividend.com Latest Code Tutorials Fri, 06 Sep 2019 08:58:13 +0000 en-US hourly 1 https://wordpress.org/?v=5.2.3 https://appdividend.com/wp-content/uploads/2017/08/cropped-ApDivi-32x32.png Go – AppDividend https://appdividend.com 32 32 Golang Maps Tutorial With Examples | Maps in Go Explained https://appdividend.com/2019/05/12/golang-maps-tutorial-with-examples-maps-in-go-explained/ https://appdividend.com/2019/05/12/golang-maps-tutorial-with-examples-maps-in-go-explained/#respond Sun, 12 May 2019 11:53:36 +0000 http://localhost/wordpress/?p=6952 Golang Maps Tutorial With Examples | Maps in Go Explained

Golang Maps Tutorial With Examples | Maps in Go Explained is today’s topic. One of the most useful data structures in computer science is the hash table. Many hash table implementations exist with varying properties, but in general, they offer fast lookups, adds, and deletes. Go provides a built-in map type that implements a hash […]

The post Golang Maps Tutorial With Examples | Maps in Go Explained appeared first on AppDividend.

]]>
Golang Maps Tutorial With Examples | Maps in Go Explained

Golang Maps Tutorial With Examples | Maps in Go Explained is today’s topic. One of the most useful data structures in computer science is the hash table. Many hash table implementations exist with varying properties, but in general, they offer fast lookups, adds, and deletes. Go provides a built-in map type that implements a hash table. Go map is an unordered collection of key-value pairs. They map keys to values. Go map keys are unique within the map while the values may or may not be the same.

Golang Maps Tutorial

Go provides another essential data type named the map which maps unique keys to values. A key is an object that you use to retrieve the value at a later date. Given a key and a value, you can store the value in a Map object. After the value is stored, you can retrieve it by using its key.

The map data structure is used for fast lookups, retrieval, and deletion of the data based on keys; that is why it is one of the most used data structures in computer science. There are also other data types available unlike maps for example arrays, structs, and slice in Golang. Let’s start our Golang maps tutorial.

Declaration and initialization of Maps in Go

A Go map type looks like the following.

map[KeyType]ValueType

where KeyType may be any comparable type (more on this later), and ValueType may be any type at all, including another map.

See the variable m is a map of string keys to int values.

var m map[string]int

Map types are reference types, like pointers or slices, and so the value of m above is nil.

A nil map has no keys. A nil map behaves like a blank map when reading. Any attempt to add keys to a nil map will result in a runtime error.

See the below code of nil variable in Go.

// hello.go

package main

import "fmt"

func main() {
	var app map[string]int
	fmt.Println(app)
	if app == nil {
		fmt.Println("app variable is nil")
	}
}

See the below output.

Golang Maps Tutorial

 

Now, let’s add the items to the nil map and see the output.

// hello.go

package main

import "fmt"

func main() {
	var app map[string]int
	app["dividend"] = 21
	fmt.Println(app)
}

See the below output.

Maps in Go Explained

 

That is why it is the requirement to initialize a map before adding items to it.

Initializing a map in Golang

We can initialize the go map using the following two ways.

  1. Initializing the map using a built-in make() function.
  2. Initializing a map using a map literal.

Let’s see one by one way to initialize the maps.

Initializing the map using the built-in make() function

You can initialize the map using a built-in make() function. You just need to pass the type of map to the make() function. See the below syntax.

var app = make(map[string]int)

Now, see the below code example.

// hello.go

package main

import "fmt"

func main() {
	var app = make(map[string]int)
	app["dividend"] = 21
	fmt.Println(app)
}

See the below output.

Initializing a map using the built-in make() function

 

See the second example.

// hello.go

package main

import "fmt"

func main() {
	app := make(map[int]string)
	app[21] = "facebook"
	app[19] = "instagram"
	app[46] = "whatapp"
	fmt.Println(app)
}

Now, run in your console and see the output. In this example, we have changed the key to integer and value to string.

Initializing the map using a map literal

A map literal is the very convenient way to initialize the map with some data. You just need to pass the key-value pairs separated by a colon inside the curly braces. See the following syntax.

var app = map[string]int{
   "k": 19,
   "l": 21,
   "a": 46,
}

Now, see the below full example code.

// hello.go

package main

import "fmt"

func main() {
	var app = map[string]int{
	   "k": 19,
	   "l": 21,
	   "a": 46,
	}
	fmt.Println(app)
}

The output is following.

Golang Maps

 

Adding items (key-value pairs) to a map

You can add new elements to the initialized map using the following syntax.

app[key] = value

We have does this in previous examples. We can add as many key/value pairs as possible.

See the following code.

// hello.go

package main

import "fmt"

func main() {
	got := make(map[int]string)
	got[1] = "ned"
	got[2] = "arya"
	got[3] = "jon"
	fmt.Println(got)
}

First, we have initialized the map and then add the three key/value pairs to the map and printed that map.

See the below output.

Adding items (key-value pairs) to a map

 

If you try to add the key that already exists in a map, then it will be overridden by the new value.

See the below code.

// hello.go

package main

import "fmt"

func main() {
	got := make(map[int]string)
	got[1] = "ned"
	fmt.Println("Before override the value")
	fmt.Println(got)
	fmt.Println("After override the value")
	got[1] = "jon"
	fmt.Println(got)
}

See the below output.

Initializing a map using a map literal

 

Deleting a key from a map in Go

The delete() function is used to delete the particular entry from the map. It requires the map and the corresponding key which is to be deleted. You can delete the entry from a map using the map key. See the following syntax.

delete(map, key)

Go map’s delete() function doesn’t return any value. Also, it doesn’t do anything if the key doesn’t exist on the map. See the following code.

// hello.go

package main

import "fmt"

func main() {
	got := make(map[int]string)
	got[1] = "ned"
	got[2] = "arya"
	got[3] = "jon"
	fmt.Println(got)
	fmt.Println("Let's delete the ned")
	delete(got, 1)
	fmt.Println(got)
}

In the above code, we have integer keys. If we want to delete an item then in the parameter we need two things.

  1. Map
  2. Key

We have used the delete() function and provide the map and key arguments to remove the ned value.

See the below output.

Deleting a key from a map in Go

 

Retrieving the value in Map

You can retrieve the value assigned to the key in a map using the syntax map[key].

If a key exists in the map, we’ll get the assigned value. Otherwise, we’ll get the 0 value of the map’s value type. See the following code.

// hello.go

package main

import "fmt"

func main() {
	got := make(map[int]string)
	got[1] = "ned"
	got[2] = "arya"
	got[3] = "jon"
	dead := got[1]
	fmt.Println(dead)
}

In the above code, we have retrieved the value ned from the map got using its key 1. We will get ned in the output. If we provide a key which does not exist in the map then it will return empty or nil.

// hello.go

package main

import "fmt"

func main() {
	got := make(map[int]string)
	got[1] = "ned"
	got[2] = "arya"
	got[3] = "jon"
	dead := got[19]
	fmt.Println(dead)
}

Here, 19 key is not present inside the map. That is why it will return nothing or ” “.

Check if the key exists in the map

When you retrieve the value assigned to the given key using the syntax map[key], it returns the additional boolean value as well which is true if the key exists in the map, otherwise false if it doesn’t exist.

So you can check for the existence of the key in the map by using the following two-value assignment syntax.

value, exist := map[key]

The boolean variable exist will be true if the key exists, if not then false otherwise. See the below code.

// hello.go

package main

import "fmt"

func main() {
	got := make(map[int]string)
	got[1] = "ned"
	got[2] = "arya"
	got[3] = "jon"
	dead, exist := got[1]
	fmt.Println(dead, exist)
}

See the below output.

Check if a key exists in a map

 

If you try to check the presence of key which not there then you will get false.

Maps are reference types

Maps are reference types and not value types. When you assign a map to the new variable, they both refer to the same underlying data structure.

Therefore changes done on the one variable will be visible to the other.

See the following code example.

// hello.go

package main

import "fmt"

func main() {
	got := make(map[int]string)
	got[1] = "ned"
	got[2] = "arya"
	got[3] = "jon"

	gameofthrones := got
	fmt.Println(got)
	fmt.Println(gameofthrones)
	fmt.Println("---Change the gameofthrones map---")
	got[4] = "Daenerys"
	fmt.Println(got)
	fmt.Println(gameofthrones)
}

In the above code, we have assigned the got map to the gameofthrones map and then modify the gameofthrones map to see if the got map is changed or not as well. See the output.

 

Maps are reference types

Here, if the one is modified the, both are modified that means maps in go is reference types.

Conclusively, Golang Maps Tutorial With Examples | Maps in Go Explained article is over.

The post Golang Maps Tutorial With Examples | Maps in Go Explained appeared first on AppDividend.

]]>
https://appdividend.com/2019/05/12/golang-maps-tutorial-with-examples-maps-in-go-explained/feed/ 0
Go Arrays Tutorial With Example | Arrays in Golang Explained https://appdividend.com/2019/05/11/go-arrays-tutorial-with-example-arrays-in-golang-explained/ https://appdividend.com/2019/05/11/go-arrays-tutorial-with-example-arrays-in-golang-explained/#respond Sat, 11 May 2019 11:07:50 +0000 http://localhost/wordpress/?p=6897 Go Arrays Tutorial With Example | Arrays in Golang Explained

Go Arrays Tutorial With Example | Arrays in Golang Explained is today’s topic. An array is a fixed-size collection of items of the same type. The items of an array are stored sequentially and can be accessed using their index. If we want to declare an array in Go, a programmer specifies the type of […]

The post Go Arrays Tutorial With Example | Arrays in Golang Explained appeared first on AppDividend.

]]>
Go Arrays Tutorial With Example | Arrays in Golang Explained

Go Arrays Tutorial With Example | Arrays in Golang Explained is today’s topic. An array is a fixed-size collection of items of the same type. The items of an array are stored sequentially and can be accessed using their index. If we want to declare an array in Go, a programmer specifies the type of the elements and the number of items required by an array.

Go Arrays Tutorial With Example

Go programming language provides a data structure called an array, which can store the fixed-size sequential collection of items of the same type. The array is used to store the collection of data, but it is often more useful to think of the array as the collection of variables of the same type.

Instead of declaring individual variables, such as no1, no2, …, and no99, you declare one array variable such as numbers and use no[0], no[1], and …, no[99] to represent individual variables.

Declaration of Array in Golang

An array belongs to type n[T]. The n denotes the number of elements in an array and T represents the type of each element. The number of items n is also a part of the kind.

There are different ways to declare arrays. Let’s look at them one by one.

var a[n]T

Here is how you can declare the array of 5 integers.

var a[5]int

See the following code example.

// hello.go

package main

import (
	"fmt"
)

func main() {
	var a [5]int //int array with length 5
	fmt.Println(a)
}

See the below output.

Go Arrays Tutorial With Example

The var a[5]int declares an integer array of length 5. All elements in the array are automatically assigned a zero value of the array type. In this case, variable a is the integer array, and hence all items of a are assigned to 0, the zero value of the integer.

An index of the array starts from 0 and ends with length – 1. Let’s assign some values to the above array.

// hello.go

package main

import "fmt"

func main() {
	var a [5]int
	a[0] = 18
	a[1] = 19
	a[2] = 21
	a[3] = 29
	a[4] = 46
	fmt.Println(a)
}

The output is following.

Arrays in Go

Shorthand declaration of Array in Golang

Let’s create the same array using the shorthand declaration. See the below code.

// hello.go

package main

import "fmt"

func main() {
	a := [5]int{18, 19, 21, 29, 46} // short hand declaration to create array
	fmt.Println(a)
}

It will give us the same output as the above program.

Shorthand declaration of Array in Golang

It is not necessary that all items in the array have to be assigned a value during the shorthand declaration. See the below scenario.

// hello.go

package main

import "fmt"

func main() {
	a := [5]int{18, 19, 21} // short hand declaration to create array
	fmt.Println(a)
}

In the above code, we have defined the size of an array 5 but declared only three items.

In this case, remaining items have 0 value by default. See the output of the above code.

Go Arrays Example

Array’s length is part of its type

The size of an array is a part of the type. Hence [15]int and [25]int are distinct types. Because of this, arrays cannot be resized. Don’t worry about the restriction because slices exist to overcome this disadvantage. That means that you cannot resize the array, because resizing the array would mean changing its type, and you are not allowed to change the type of a variable in Golang.

See the below code to understand better.

package main

// hello.go

func main() {
	a := [3]int{5, 78, 8}
	var b [5]int
	b = a
}

If you are using Visual Studio Code and you have installed all the Go extensions, then you might be getting an error inside the VSCode editor. Now, if you run the above code, then it will throw an error.

Array’s length is part of its type

So, in the above code, variables a and b have different array size. That is why we can not assign each other due to array length difference, and it is strictly prohibited in Go.

Arrays in Golang are value types

Arrays in Golang are value types unlike the other languages like C, C++, Python, and Java where arrays are reference types.

That means that when you assign the array to the new variable or pass the array to the function, the entire array is copied. So if you want to make any changes to the copied array, the original array won’t be affected and will remain unchanged. See the below code for understanding.

// hello.go

package main

import "fmt"

func main() {
	arrA := [5]string{"Ned", "Edd", "Jon", "Jeor", "Jorah"}
	arrB := arrA

	arrB[1] = "Gendry"

	fmt.Println("array A = ", arrA)
	fmt.Println("array B = ", arrB)
}

See the output.

Arrays in Golang Explained

In the above code, we have copied the content of arrA to arrB then we have modified the arrB, but still, arrA remains the same, and it does not change.

Length of the array in Go

We can get the length of an array by passing that array as a parameter to the len function in Go. See the below code.

// hello.go

package main

import "fmt"

func main() {
	data := [...]string{"Ned", "Edd", "Jon", "Jeor", "Jorah"}
	fmt.Println("length of data is", len(data))
}

See the below output.

Length of an array

Iterating over an array in Golang

You can use a for loop to iterate over the array like the following code.

// hello.go

package main

import "fmt"

func main() {
	data := [...]string{"Ned", "Edd", "Jon", "Jeor", "Jorah"}
	for i := 0; i < len(data); i++ { //looping from 0 to the length of the array
		fmt.Printf("%d th element of data is %s\n", i, data[i])
	}
}

See the below output.

Iterating over an array in Golang

Iterating over an array using a range operator

Golang provides a more robust form of for loop using the range operator. Here ‘s how you can use the range operator with for loop to iterate over the array.

// hello.go

package main

import "fmt"

func main() {
	data := [...]string{"Ned", "Edd", "Jon", "Jeor", "Jorah"}
	for index, value := range data {
		fmt.Printf("Character %d of GoT is = %s\n", index, value)
	}
}

See the below output.

Iterating over an array using a range operator

Multidimensional arrays in Golang

Till now, we have dealt with only a one-dimensional array. You can also create multi-dimensional arrays in Golang.

The following example demonstrates how to create multidimensional arrays.

// hello.go

package main

import "fmt"

func main() {
	multiA := [2][2]int{
		{19, 21},
		{29, 46},
	}
	fmt.Println(multiA)
}

See the below code.

Multidimensional arrays in Golang

That’s it for arrays. The disadvantage of an array is that they come with the restriction that the array’s length is fixed in Go. It is impossible to increase the length of the array. This is how the Golang slices come into the picture.

In Go language, slices are more common practices in programming than conventional arrays.

Finally, Go Arrays Tutorial With Example | Arrays in Golang Explained article is over.

Recommended Posts

Go Structs Tutorial With Example

Go Functions Tutorial With Example

Go Slices Tutorial With Example

Go Slice Append Example

Go For Loop Example

The post Go Arrays Tutorial With Example | Arrays in Golang Explained appeared first on AppDividend.

]]>
https://appdividend.com/2019/05/11/go-arrays-tutorial-with-example-arrays-in-golang-explained/feed/ 0
Go Structs Tutorial With Example | Structs In Golang Explained https://appdividend.com/2019/05/10/go-structs-tutorial-with-example-structs-in-golang-explained/ https://appdividend.com/2019/05/10/go-structs-tutorial-with-example-structs-in-golang-explained/#respond Fri, 10 May 2019 16:10:08 +0000 http://localhost/wordpress/?p=6810 Go Structs Tutorial With Example | Structs In Golang Explained

Go Structs Tutorial With Example | Structs In Golang Explained is today’s topic. A struct is a user-defined type that contains the collection of named fields/properties. It is used to group related data to form a single unit. Any real-world entity that has the set of properties can be represented using a struct. Structs are useful […]

The post Go Structs Tutorial With Example | Structs In Golang Explained appeared first on AppDividend.

]]>
Go Structs Tutorial With Example | Structs In Golang Explained

Go Structs Tutorial With Example | Structs In Golang Explained is today’s topic. A struct is a user-defined type that contains the collection of named fields/properties. It is used to group related data to form a single unit. Any real-world entity that has the set of properties can be represented using a struct. Structs are useful for grouping data together to create records. If you’re coming from the object-oriented programming background, you can think of a struct as the lightweight class that supports the composition but not an inheritance.

Go Structs Tutorial With Example

A structure is a user-defined type which represents the collection of fields. It can be used in the places where it makes sense to group a data into the single unit rather than maintaining each of them as the separate types.

For instance, a student has firstName, lastName, and age. It makes sense to group these three fields into the single structure student.

type Student struct {  
    firstName string
    lastName  string
    age       int
}

The above snippet declares a structure type Student who has fields first_name, last_name, and age. The structure can also be made more compact by declaring the fields that belong to the same type in the single line followed by a type name.

In the above struct program, firstName and lastName belong to the same type string, age as an interger, and hence the struct can be rewritten as following code.

type Student struct {  
    firstName, lastName string
    age int
}

Creating named structures in Go

Let’s define a named structure Student using a simple program.

// hello.go

package main

import "fmt"

// Student structure
type Student struct {
	firstName, lastName string
	age                 int
}

func main() {

	// creating first student structure using field names
	stud := Student{
		firstName: "Krunal",
		lastName:  "Lathiya",
		age:       26,
	}

	//creating second structure without using field names
	stud2 := Student{"Ankit", "Lathiya", 25}

	fmt.Println("Student 1", stud)
	fmt.Println("Student 2", stud2)
}

In the above program, we create a named struct Student. Then stud structure is defined by specifying the value for each field name. It is not necessary that an order of the field names should be the same as that while declaring the structure type.

In the above program, stud2 is defined by omitting the property names.

In that case, it is necessary to maintain an order of properties to be the same as the specified in the structure declaration.

Finally, we have printed both the structs into the terminal console. See the below output.

Go Structs Tutorial With Example

Creating anonymous structs in Go

See the below code example.

// hello.go

package main

import "fmt"

func main() {
	stud3 := struct {
		firstName, lastName string
		age                 int
	}{
		firstName: "Rushabh",
		lastName:  "Rupani",
		age:       27,
	}

	fmt.Println("Student 3", stud3)
}

In the above program, an anonymous structure variable stud3 is defined. As we have already mentioned, the above structure is called anonymous because it only creates a new struct variable stud3 and does not define any new struct type.

The output is following.

Creating anonymous structs in Go

Zero value of a structure in Go

When the struct is defined, and it is not explicitly initialized with any value, the properties of a struct are assigned their zero values by default. See the below code example.

// hello.go

package main

import (
	"fmt"
)

// Student struct
type Student struct {
	firstName, lastName string
	age                 int
}

func main() {
	var stud4 Student //zero valued structure
	fmt.Println("Student 4", stud4)
}

The above program defines stud4, but it is not initialized with any value. Hence the firstName and lastName are assigned the zero values of string which is “” and age is assigned the zero values of int which is 0. See the below output.

Zero value of a structure in Go

Accessing individual fields of a struct

The dot (.) operator is used to accessing the different fields of a structure.

See the below code.

// hello.go

package main

import "fmt"

// Student structure
type Student struct {
	firstName, lastName string
	age                 int
}

func main() {
	stud5 := Student{"Robert", "Downey", 55}
	fmt.Println("First Name:", stud5.firstName)
	fmt.Println("Last Name:", stud5.lastName)
	fmt.Println("Age:", stud5.age)
}

See the below output.

Accessing individual fields of a struct

It is also possible to create a zero struct and then assign the values to its fields later.

See the below code.

// hello.go

package main

import "fmt"

// Student strucutre
type Student struct {
	firstName, lastName string
	age                 int
}

func main() {
	var stud6 Student
	stud6.firstName = "Ken"
	stud6.lastName = "Adams"
	stud6.age = 30
	fmt.Println("First Name:", stud6.firstName)
	fmt.Println("Last Name:", stud6.lastName)
	fmt.Println("Age:", stud6.age)
}

In the above code, we have first created a zero struct and then assign the different fields to different value and then print in the console.

See the below output.

Structs In Golang Explained

Pointers to a struct

It is also possible to create the pointers to the struct. See the below code.

// hello.go

package main

import "fmt"

// Student structure
type Student struct {
	firstName, lastName string
	age                 int
}

func main() {
	stud7 := &Student{"Wade", "Wilson", 28}
	fmt.Println("First Name:", (*stud7).firstName)
	fmt.Println("Last Name:", (*stud7).lastName)
	fmt.Println("Age:", (*stud7).age)
}

The stud7 in the above program is a pointer to the Student struct. The (*stud7).firstName is the syntax to access the firstName field of the stud7 struct. See the below output.

Pointers to a struct

The Golang gives us the option to use stud7.firstName instead of the explicit dereference (*stud7).firstName to access the firstName field.

Anonymous fields in Golang

It is possible to create the structs with fields which contain only the type without the field name. This type of field is called an anonymous field. The snippet below creates a struct Student who has two anonymous fields string and int.

type Student struct {  
    string
    int
}

Let’s write a program using anonymous fields.

// hello.go

package main

import "fmt"

// Student struct
type Student struct {
	string
	int
}

func main() {
	s1 := Student{"Krunal", 26}
	fmt.Println(s1)
}

In the above program, Student is a struct with two anonymous fields. The s1 := Student{“Krunal”, 26}  defines a variable of type Student. Even though an anonymous field does not have a name, by default, the name of an anonymous field is the name of its type.

For example in the case of the Student struct above, although the fields are anonymous, by default, they take the firstName of the type of the fields. So Student struct has two fields with name string and int.

The output is following.

Anonymous fields in Golang

Nested structs in Golang

It is possible that a struct contains the field which in turn is the struct. This kind of structs is called nested structs. See the below code example.

// hello.go

package main

import "fmt"

// Address struct
type Address struct {
	city, state string
}

// Student struct
type Student struct {
	name    string
	age     int
	address Address
}

func main() {
	var s1 Student
	s1.name = "Krunal"
	s1.age = 26
	s1.address = Address{
		city:  "Rajkot",
		state: "Gujarat",
	}
	fmt.Println(s1)
}

The Student struct in the above program has a field address which in turn is a struct. This program outputs the following.

Nested structs in Golang

Struct Methods in Go

In the below code example, we will define a struct called Rectangle, and then we calculate the area of the rectangle by determining some methods.

// hello.go

package main

import (
	"fmt"
	"math"
)

// Rectangle Struct
type Rectangle struct {
	x1, y1, x2, y2 float64
}

func distance(x1, y1, x2, y2 float64) float64 {
	a := x2 - x1
	b := y2 - y1
	return math.Sqrt(a*a + b*b)
}

func (r *Rectangle) area() float64 {
	l := distance(r.x1, r.y1, r.x1, r.y2)
	w := distance(r.x1, r.y1, r.x2, r.y1)
	return l * w
}

func main() {
	r := Rectangle{0, 0, 19, 21}
	fmt.Println("The area of Rectangle is:", r.area())
}

In the above code, we have defined two methods.

  1. distance
  2. area

We need a distance to calculate the area. Finally, we have called the area method from the main() method. It gives the output. See the below output.

Struct Methods in Go

Creating a struct and obtaining the pointer to it using the built-in new() function

You can also use the new() function to create the instance of the struct.

A new() function allocates enough memory to fit all the struct properties, sets each of them to their zero value and returns the pointer to the newly allocated struct. See the below code.

// hello.go

package main

import "fmt"

// Student struct
type Student struct {
	name string
	age  int
}

func main() {
	s2 := new(Student)
	s2.name = "Krunal"
	s2.age = 26

	fmt.Println(s2)
}

See the below output.

Creating a struct and obtaining a pointer in Go

Struct Equality in Go

Two struct variables are count as equal if all their corresponding fields are equal. See the below code.

// hello.go

package main

import "fmt"

// Student struct
type Student struct {
	name string
	age  int
}

func main() {
	s1 := Student{"Krunal", 26}
	s2 := Student{"Krunal", 26}

	if s1 == s2 {
		fmt.Println("Student s1 and s2 are equal.")
	} else {
		fmt.Println("Student s1 and s2 are not equal.")
	}
}

In the above code, both the s1 and s2 are equal with the values that is why both the structs are identical.

If any struct values differ, then it will not equal to each other.

Conclusion of Go Structs Tutorial

In this post, we have seen how to initialize the struct, creating an anonymous struct, properties of structs, methods of structs, pointers in a struct, etc.

Finally, Go Structs Tutorial With Example is over.

Recommended Posts

Go Functions Tutorial With Example

Go Slices Tutorial With Example

Go Slice Append Example

Go For Loop Example

Go Custom Type Declarations Tutorial With Example

The post Go Structs Tutorial With Example | Structs In Golang Explained appeared first on AppDividend.

]]>
https://appdividend.com/2019/05/10/go-structs-tutorial-with-example-structs-in-golang-explained/feed/ 0
Go Interface Tutorial With Example | Interface Implementation in Go https://appdividend.com/2019/05/09/go-interface-tutorial-with-example-interface-implementation-in-go/ https://appdividend.com/2019/05/09/go-interface-tutorial-with-example-interface-implementation-in-go/#respond Thu, 09 May 2019 21:33:13 +0000 http://localhost/wordpress/?p=6790 Go Interface Tutorial With Example | Interface Implementation in Go

Go Interface Tutorial With Example | Interface Implementation in Go is today’s topic. If you are new to Go language then, you may be heard or seen in the code about interface{} a lot in code snippets and tutorials. This can be very daunting seeing this at first. Interface implementation is one of the core […]

The post Go Interface Tutorial With Example | Interface Implementation in Go appeared first on AppDividend.

]]>
Go Interface Tutorial With Example | Interface Implementation in Go

Go Interface Tutorial With Example | Interface Implementation in Go is today’s topic.

If you are new to Go language then, you may be heard or seen in the code about interface{} a lot in code snippets and tutorials. This can be very daunting seeing this at first. Interface implementation is one of the core concepts of Object-oriented programming language. If you have used Java, PHP, or Python then you might know what interface is and how it can be useful to build a scalable application.

An interface is a type defined using a set of method signatures. It describes the behavior of a similar kind of objects. Go programming provides another data type called interfaces which represents a set of method signatures. The struct data type implements these interfaces to have method definitions for the method signature of the interfaces. A Go interface is a type that consists of the collection of method signatures.

Go Interface Tutorial With Example

The interface is defined using the type keyword, followed by a name and the keyword interface. Then we specify a set of method signatures inside curly braces.

A prominent feature of Golang is that interfaces are implemented implicitly. The programmer doesn’t have to specify that type T implements interface I. That work is done by the Go compiler (never send a human to do a machine’s job). The nice implication of these behaviors is the possibility to define an interface which can be automatically implemented by the types already written.

In Go we’ve two concepts related to interfaces:

  1. Interface : a set of methods required to implement such an interface. It’s defined using keyword interface.
  2. Interface type:  variable of interface type which can hold any value implementing a particular interface.

Syntax of Go Interface

type interface_name interface {
   method_name1 [return_type]
   method_name2 [return_type]
   method_name3 [return_type]
}

By defining an interface in Golang, we essentially define a contract which in the future must be implemented. If we define a type based on the interface, then we are forced to implement all of the methods or functions defined within that interface type. An interface contains a method name and its return type. Go structs implement methods. It is like the class in other programming languages.

Implementing an interface in Go

Go interfaces can be implemented as methods on the structs. In many programming languages like Python, Java, or PHP, there is a concept of the base class that can be used to implement the shared functionality used by all sub-classes. Go (rightfully) prefers composition to inheritance.

Let’s get an example; let say we wanted to define an interface for a DanceOn. We could define our interface to include a Dance() function like the following.

type DanceOn interface {
  // Dance prints out "Let's dance" to the terminal
  Dance()
}

With our DanceOn interface defined, we could define the BreakDancer and AerialDancer structs which implements the DanceOn interface.

See the below code example.

// hello.go

package main

import "fmt"

// DanceOn Interface Defined
type DanceOn interface {
	Dance()
}

// BreakDance Struct Defined
type BreakDance struct {
	Name string
}

// AerialDance Struct Defined
type AerialDance struct {
	Name string
}

// Dance Function implemented from DanceOn Interface
func (b BreakDance) Dance() {
	fmt.Printf("%s is doing Breakdance on the floor\n", b.Name)
}

// Dance Function implemented from DanceOn Interface
func (a AerialDance) Dance() {
	fmt.Printf("%s is doing Aerialdance on the air\n", a.Name)
}

func main() {
	var breakdancer BreakDance
	breakdancer.Name = "Michael Jackson"
	breakdancer.Dance()

	var aerialdancer AerialDance
	aerialdancer.Name = "Krunal"
	aerialdancer.Dance()
}

If we want to implement an interface, you need to implement all the methods declared in the interface. Go Interfaces are implemented implicitly

Unlike other languages like Java, you don’t need to explicitly specify that a type implements an interface using something like an implement keyword.

In the above code, we have defined one interface called DanceOn.
Now that interface has declared one method called Dance().
We have defined the two Go structs.
1) BreakDance
2) AerialDance
Both the structs implements the DanceOn interface that is why they both have to implement the Dance() method.

Then inside the main() function, we have declared the struct variable breakdancer and aerialdancer.

Then we have assigned the Name property to value Michael Jackson and Krunal.

Finally, called the Dance() function and printed the message inside the console of the terminal. See the below output.

Go Interface Tutorial With Example

Interface makes the code more scalable, flexible, and it’s a path to achieve the polymorphism in Go programming language. Instead of requiring the particular type, interfaces allow specifying that only some behavior is needed. A set of methods defines behavior.

Why use Go Interfaces

Go interfaces are a way to construct a backbone of your program.

Objects should interact with each other through the interfaces and not through the concrete objects. It means that you should build an object model for your application that consists only of the interfaces and basic types of data objects (structs whose members are basic types or other data objects).

Conclusively, Go Interface Tutorial With Example | Interface Implementation in Go is over.

Recommended Posts

Go Arrays Tutorial With Example

Go Structs Tutorial With Example

Go Functions Tutorial With Example

Go Slices Tutorial With Example

Go Slice Append Example

The post Go Interface Tutorial With Example | Interface Implementation in Go appeared first on AppDividend.

]]>
https://appdividend.com/2019/05/09/go-interface-tutorial-with-example-interface-implementation-in-go/feed/ 0
Golang Receiver Function Tutorial | Go Function Receivers Example https://appdividend.com/2019/03/23/golang-receiver-function-tutorial-go-function-receivers-example/ https://appdividend.com/2019/03/23/golang-receiver-function-tutorial-go-function-receivers-example/#respond Sat, 23 Mar 2019 16:24:43 +0000 http://localhost/wordpress/?p=5330 Golang Receiver Function Tutorial

Golang Receiver Function Tutorial With Example is today’s topic. Go is very similar to C due to the presence of pointers, static typing, and many other things. But Go is the modern language and so it has many new features baked in it, and Function Receiver is one of it. Go is not Object-Oriented Programming […]

The post Golang Receiver Function Tutorial | Go Function Receivers Example appeared first on AppDividend.

]]>
Golang Receiver Function Tutorial

Golang Receiver Function Tutorial With Example is today’s topic. Go is very similar to C due to the presence of pointers, static typing, and many other things. But Go is the modern language and so it has many new features baked in it, and Function Receiver is one of it. Go is not Object-Oriented Programming Language.

Golang Receiver Function Tutorial

Function Receiver sets a method on variables that we create. This seems weird at first, but when you get the example, it will be clear as crystal.

Let’s create a custom type in Golang and then assign that type to a variable. Now, you can set a method on that variable, and that method is Receiver function.

With the receiver functions, you don’t have to mess around with classes or deal with inheritance. One advantage of using receiver function is when we couple it with interfaces.

Let’s understand with the following example.

If you do not know how to install Go on local, then please go through the how to install Go tutorial.

Create a file called app.go and add the following code inside it.

/* app.go */

package main

import "fmt"

type app []string

func (a app) print() {
   for i, app := range a {
	fmt.Println(i, app)
   }
}

In the above code, we have created a custom type called app. 

Then we have defined one receiver’s function for this app type.

Now, let’s see the syntax of function receiver.

func(t type) functionName() {}

In the above code, the type is our custom defined type, and in our case it is app.

So, when we create a variable from that type, it has access to this print() method, which is in our case, a receiver function.

Now, the last step is to create a variable from the custom defined type inside the hello.go file.

So write the following code inside the hello.go file.

/* hello.go */

package main

func main() {
   apps := app{"Facebook", "Instagram", "WhatsApp"}
   apps.print()
}

In this code, we have created a variable from the custom type declaration which is app. 

It consists of a slice which has three items.

Then we have called a receiver function called print() which we have defined inside the app.go file.

So, when the print() function is called, it will execute the body of the print() function which will iterate the slice and display the item one by one through for loop.

You can run the files using the following command.

go run hello.go app.go

The output is following.

Golang Receiver Function Tutorial | Go Function Receivers Example

Finally, Golang Receiver Function Tutorial | Go Function Receivers Example is over.

Recommended Posts

Go Interface Tutorial With Example

Go Arrays Tutorial With Example

Go Structs Tutorial With Example

Go Functions Tutorial With Example

Go Slices Tutorial With Example

The post Golang Receiver Function Tutorial | Go Function Receivers Example appeared first on AppDividend.

]]>
https://appdividend.com/2019/03/23/golang-receiver-function-tutorial-go-function-receivers-example/feed/ 0
Go Custom Type Declarations Tutorial With Example https://appdividend.com/2019/03/22/go-custom-type-declarations-tutorial-with-example/ https://appdividend.com/2019/03/22/go-custom-type-declarations-tutorial-with-example/#respond Fri, 22 Mar 2019 18:58:13 +0000 http://localhost/wordpress/?p=5321 Go types example

Go Custom Type Declarations Tutorial With Example is today’s topic. Go is not Object Oriented Programming language like Java, PHP, or Python. It has a unique design pattern. In this tutorial, we will see an approach in which we will define our custom types in Go. Go Custom Type Declarations Tutorial We can define our […]

The post Go Custom Type Declarations Tutorial With Example appeared first on AppDividend.

]]>
Go types example

Go Custom Type Declarations Tutorial With Example is today’s topic. Go is not Object Oriented Programming language like Java, PHP, or Python. It has a unique design pattern. In this tutorial, we will see an approach in which we will define our custom types in Go.

Go Custom Type Declarations Tutorial

We can define our own types in Go. Let’s create a new file inside your folder called hello.go and add the following code.

/* hello.go */

package main

import "fmt"

func main() {
   apps := []string{"Facebook", "Instagram", "WhatsApp"}

   for i, app := range apps {
	fmt.Println(i, app)
   }
}

The output of the above code is following.

 

Go Custom Type Declarations Tutorial

So, we have defined one slice called apps and then iterated a for loop on the slice.

Now, here, we can define the type app.

Okay, so create a new file in the same folder called app.go and add the following code.

/* app.go */

package main

type app []string

So, in this file, we have defined a type app.

Now, we can use this type inside the hello.go file.

Also, we can define a receiver’s function inside the app.go file. See the following code.

/* app.go */

package main

import "fmt"

type app []string

func (a app) print() {
   for i, app := range a {
	 fmt.Println(i, app)
   }
}

In the above code, the receiver’s function is print() which we can use directly inside the hello.go file, and it will print all the apps.

Here, we have defined the same for loop, which we have defined in the hello.go file earlier.

So, now we do not need to write this code on hello.go. Our final hello.go code is following.

/* hello.go */

package main

func main() {
   apps := app{"Facebook", "Instagram", "WhatsApp"}
   apps.print()
}

Here, inside the func main(), see the first line, we have defined the type app.

We do not need to import the app.go file in this file; it will take directly. We need to run both files at the same time, and we are good to go.

Also, we have called the receiver’s function defined inside the app.go file, and it will print all the apps.

Now, run the following command in the terminal.

go run hello.go app.go

The output is following.

 

Go Custom Type Declarations Tutorial With Example

See this is how we can define our own types and use them in another file.

Finally, Go Custom Type Declarations Tutorial With Example is over.

The post Go Custom Type Declarations Tutorial With Example appeared first on AppDividend.

]]>
https://appdividend.com/2019/03/22/go-custom-type-declarations-tutorial-with-example/feed/ 0
Go For Loop Example | Golang Loops Tutorial https://appdividend.com/2019/03/22/go-for-loop-example-golang-loops-tutorial/ https://appdividend.com/2019/03/22/go-for-loop-example-golang-loops-tutorial/#respond Fri, 22 Mar 2019 12:05:38 +0000 http://localhost/wordpress/?p=5306 Golang Loops Tutorial

Go For Loop Example | Golang Loops Tutorial is today’s topic. Go has only one looping construct which is the for loop. The for loop has three components separated by semicolons which are following. The init statement: The init statement executed before the first iteration. This step allows us to declare and initialize any for loop control […]

The post Go For Loop Example | Golang Loops Tutorial appeared first on AppDividend.

]]>
Golang Loops Tutorial

Go For Loop Example | Golang Loops Tutorial is today’s topic. Go has only one looping construct which is the for loop. The for loop has three components separated by semicolons which are following.

  • The init statement: The init statement executed before the first iteration. This step allows us to declare and initialize any for loop control variables. You are not required to put the statement here, as long as the semicolon appears.
  • The condition expression: This statement is evaluated before every iteration. If a condition is true, the body of the loop is executed. If the condition is false, then the body of the loop does not execute, and the control flow jumps to a next statement just after a for loop.
  • The post statement: This statement executed at the end of every iteration. If the range is available, then the for loop executes for each item in the range.

The for loop without a condition will repeatedly loop until you break out of the loop or return from the enclosing function. You can also continue to the next iteration of the loop.

Go For Loop Example

The syntax of for loop in Go is following.

for [condition |  ( init; condition; increment ) | Range] {
   body
}

Let’s see the example.

/* hello.go */

package main

func main() {
   apps := []string{"Facebook", "Instagram", "WhatsApp"}

   for i := 0; i < len(apps); i++ {
	println(i, apps[i])
   }
}

Okay, so we have defined one slice called apps. Then we have iterated that variable in for loop, and we get the following output.

 

Go For Loop Example | Golang Loops Tutorial

The for loop will stop iterating once the boolean condition evaluates to false.

Unlike the other languages like C, C++, Java, or JavaScript, no parentheses are required to surround the three components of a for statement, but the braces { } are always required.

We can also use the range function with for loop. Let’s see the following example.

/* hello */

package main

import "fmt"

func main() {
   apps := []string{"Facebook", "Instagram", "WhatsApp"}

   for i, app := range apps {
	 fmt.Println(i, app)
   }
}

The output of the above code is the same.

 

Go For Loop Example

We have used the range keyword when we need to iterate each element of the slice in Go.

The post Go For Loop Example | Golang Loops Tutorial appeared first on AppDividend.

]]>
https://appdividend.com/2019/03/22/go-for-loop-example-golang-loops-tutorial/feed/ 0
Go Slice Append Example | Golang Append Tutorial https://appdividend.com/2019/03/20/go-slice-append-example-golang-append-tutorial/ https://appdividend.com/2019/03/20/go-slice-append-example-golang-append-tutorial/#respond Wed, 20 Mar 2019 19:41:02 +0000 http://localhost/wordpress/?p=5294 Go Slice Append Example or Golang Append Tutorial

Go Slice Append Example | Golang Append Tutorial is today’s topic. The built-in append function appends any number of elements to the end of a slice. Append returns the updated slice and it does not modify the existing one. So it is Pure function in terms of Javascript. The resulting value of append() function is a slice containing all the […]

The post Go Slice Append Example | Golang Append Tutorial appeared first on AppDividend.

]]>
Go Slice Append Example or Golang Append Tutorial

Go Slice Append Example | Golang Append Tutorial is today’s topic. The built-in append function appends any number of elements to the end of a slice. Append returns the updated slice and it does not modify the existing one. So it is Pure function in terms of Javascript. The resulting value of append() function is a slice containing all the elements of the original slice plus the provided values.

Go Slice Append Example

In Golang, a slice is a reference to the contiguous segment of the array. Slice is the pointer, with additional properties about an array.

A slice is consists of 3 fields.

  • The Pointer to the underlying array.
  • Length of the slice.
  • The capacity of the slice.

Slicing does not copy the slice’s data. It creates the new slice value that points to an original array. It makes slice operations as efficient as manipulating the array indices.

If we want to increase the capacity of the slice, one must create the new, larger slice and copy the contents of an original slice into it. 

Due to this technique, how the dynamic array implementations from other languages work behind the scenes.

Let’s see the syntax of Go Slice append() function.

func append(s []T, x ...T) []T

The append function appends the items x to the end of the slice s and grows the slice if greater capacity is needed.

Now, let’s see the example of appending an item to Slice.

/* hello.go */

package main

import "fmt"

func newChar() string {
   return "Jon Snow"
}

func main() {
   characters := []string{"Tyrion Lannister", newChar()}
   characters = append(characters, "Daenerys Targaryen")
   fmt.Println("The characters of Game of Thrones are: ", characters)
}

In the above code, first, we have defined a slice with initial data.

Then we have appended one more string to the characters array, but it will create a new array and then return it. So no side effects should be there.

The output of the code is following.

Go Slice Append Example

Let’s see another example.

/* hello.go */

package main

import "fmt"

func main() {
   apps := []string{"Facebook", "Instagram", "WhatsApp"}
   newApps := []string{"Uber", "Ola"}
   apps = append(apps, newApps...)
   fmt.Println("All IMP Apps are: ", apps)
}

In the above code, we have first defined the two slices.

Then, we have appended apps slice to the newApps slice.

The (…) unpacks the newApps slice. Without the three dots, the code would attempt to append the slice as a whole, which is invalid.

The output of the code is following.

Go Slice Append Example | Golang Append Tutorial

Finally, Go Slice Append Example | Golang Append Tutorial is over.

Recommended Posts

Go For Loop Example

Go Custom Type Declarations Tutorial With Example

Golang Receiver Function Tutorial With Example

Interface Implementation in Go

Arrays in Golang Explained

The post Go Slice Append Example | Golang Append Tutorial appeared first on AppDividend.

]]>
https://appdividend.com/2019/03/20/go-slice-append-example-golang-append-tutorial/feed/ 0
Go Slices Tutorial With Example | Slices in Golang https://appdividend.com/2019/03/20/go-slices-tutorial-with-example-slices-in-golang/ https://appdividend.com/2019/03/20/go-slices-tutorial-with-example-slices-in-golang/#respond Wed, 20 Mar 2019 17:07:41 +0000 http://localhost/wordpress/?p=5282 Go Slices Tutorial With Example | Slices in Golang

Go Slices Tutorial With Example | Slices in Golang is today’s topic. An array has a fixed size. A slice, on the other hand, is a dynamically-sized, flexible view into the elements of an array. A Slice is the segment of an array. The slices build on arrays and provide more power, flexibility, and convenience […]

The post Go Slices Tutorial With Example | Slices in Golang appeared first on AppDividend.

]]>
Go Slices Tutorial With Example | Slices in Golang

Go Slices Tutorial With Example | Slices in Golang is today’s topic. An array has a fixed size. A slice, on the other hand, is a dynamically-sized, flexible view into the elements of an array. A Slice is the segment of an array. The slices build on arrays and provide more power, flexibility, and convenience compared to the arrays. Unlike the arrays, slices are typed only by the elements they contain. Slices support several more that make them richer than arrays. One is the builtin append, which returns a slice containing one or more new values.

Go Slices Tutorial With Example

If you do not know how to install Golang on mac the check out my How To Install Go On Mac tutorial.

Just like the arrays, Slices are indexable and have a length. But unlike arrays, they can be resized. In terms of programming paradigm, The Slice is just a reference to the underlying array. Let’s see the syntax of Slices in Golang.

Declaring a Slice

You can declare a slice using the following code.

var variablename []data type

Let’s declare an actual slice.

var sl = []string

Now, let’s define a slice in go.

var sl = []string{"AppDividend", "Krunal"}

Okay, now let’s take an actual example and print the slice on the console.

/* hello.go */

package main

import "fmt"

func main() {
  var sl = []string{"AppDividend", "Krunal"}

  fmt.Println("Slice Example: ", sl)
}

So, the main function, we have defined the slice using two strings and then display the slice on the console. Run the file using the following command.

go run hello.go

The output is following.

Go Slices Tutorial With Example

We can also initialize the slice like the following code.

/* hello.go */

package main

import "fmt"

func main() {
  sl := []string{
	"AppDividend",
	"Krunal"}

  fmt.Println("Slice Example: ", sl)
}

We will get the same output.

Creating the slice from an array

Since the slice is the segment of an array, we can create the slice from an array.

Let’s take the following example.

/* hello.go */

package main

import "fmt"

func main() {
   var a = [5]string{"Javascript", "PHP", "Go", "Python", "Dart"}
   var b = a[1:3]
   fmt.Println("Slice Example: ", b)
   fmt.Println("Array Example: ", a)
}

Here, first, we have defined a fixed-length array called a.

Since the slice is formed by specifying two indices, a low and high bound, separated by a colon.

a[1:3]

That means, from an array a, start the element from 0 and pick the values between 1(low) to 3(high). Which means we will form the slice whose index in an array is and 2. 

In the above example, PHP and Go have index 1 and 2. So the output slice will be of those elements.

Let’s see the output of Slice and Array in the console.

Creating a slice from an array

The low and high indices in a slice expression are optional. The default value for low is 0 and high is the length of a slice.

A slice is like an array which is a container to hold elements of same data type, but slice can vary in size.

Finally, Go Slices Tutorial With Example | Slices in Golang is over.

Recommended Posts

Go Slice Append Example

Go For Loop Example

Go Custom Type Declarations Tutorial With Example

How To Install Go On Mac

Golang Receiver Function Tutorial With Example

The post Go Slices Tutorial With Example | Slices in Golang appeared first on AppDividend.

]]>
https://appdividend.com/2019/03/20/go-slices-tutorial-with-example-slices-in-golang/feed/ 0
Go Functions Tutorial With Example | Introduction to Functions in Golang https://appdividend.com/2019/03/20/go-functions-tutorial-with-example-introduction-to-functions-in-golang/ https://appdividend.com/2019/03/20/go-functions-tutorial-with-example-introduction-to-functions-in-golang/#respond Wed, 20 Mar 2019 11:49:24 +0000 http://localhost/wordpress/?p=5266 Go Functions Tutorial With Example | Introduction to Functions in Golang

Go Functions Tutorial With Example | Introduction to Functions in Golang is today’s topic. A function is the group of statements that together perform the task. Every Go program has at least one function, which is the main() function. You can divide your code into the separate functions. The function can take zero or more arguments. The […]

The post Go Functions Tutorial With Example | Introduction to Functions in Golang appeared first on AppDividend.

]]>
Go Functions Tutorial With Example | Introduction to Functions in Golang

Go Functions Tutorial With Example | Introduction to Functions in Golang is today’s topic. A function is the group of statements that together perform the task. Every Go program has at least one function, which is the main() function. You can divide your code into the separate functions. The function can take zero or more arguments. The Go standard library provides different built-in functions that your program can call.

Go Functions Tutorial With Example

A function declaration tells a compiler about the function name, return type, and parameters. The function definition provides the actual body of the function.

Defining a Function in Go

The syntax of the function in Go is following.

func functionName() datatype { }

In the above syntax, the func is a keyword.

Then you need to provide the functionName.

Then you need to provide the return data type of the function.

Let’s see the following example.

/* hello.go */

package main

import "fmt"

func greet() string {
   return "Hello World!!\n"
}

func main() {
   fmt.Printf(greet())
}

In the above code, first, we have defined the package main.

Then we have imported the Go Standard Library’s package called fmt. 

That package provides some I/O methods that can be used to display the output on the console.

Next, we have defined the User Defined Function which is greet(). It returns the string Hello World.

You can notice here that we have written the string as a return data type of the function, which means that the function must have to return the value which is the type of String. It can not return the integer or other data type.

While creating the Go Programming function, you give the definition of what a function has to do and to use the function; you will need to call that function to perform a defined task.

When a program calls the function, the program control is transferred to the called function. The called function performs the defined task, and when its return statement is executed, or body of the function is complete, it returns the program control to the main program.

Then we have written the main function which prints the output of the greet() function in the console. Let’s see the output.

Go Functions Tutorial With Example

Let’s see another example.

/* hello.go */

package main

import "fmt"

func multiply(a int, b int) int {
   return a * b
}

func main() {
   fmt.Println(multiply(19, 21))
}

Here, we have passed the two parameters called and b.

You can notice here that we have defined its data type in the parentheses in the function argument.

It returns the multiplication of and b.

See the output below.

 

Introduction to Functions in Golang

Finally, Go Functions Tutorial With Example | Introduction to Functions in Golang is over.

Recommended Posts

How To Install Go On Mac | Go Programming Language

Go Slices Tutorial With Example | Slices in Golang

Go Slice Append Example | Golang Append Tutorial

Go For Loop Example | Golang Loops Tutorial

Go Custom Type Declarations Tutorial With Example

The post Go Functions Tutorial With Example | Introduction to Functions in Golang appeared first on AppDividend.

]]>
https://appdividend.com/2019/03/20/go-functions-tutorial-with-example-introduction-to-functions-in-golang/feed/ 0