Let’s Go ~ A Complete Guide (Part ~ V)

Himanshu Singh
MindOrks
Published in
2 min readAug 9, 2018

Hey, Welcome to the series Let Go. This is the Part ~ V of the series. If you have not seen the previous parts, Click Here. Till now we have covered Installation and Basics,Control statement and Functions.
In this part we will cover statements and functions.

The Index for this series is as followed,

  1. Introduction to Go
  2. Go Environment Setup
  3. Go Basics
  4. Control Statement and Functions
  5. Structs
  6. Object Oriented Programming in Go
  7. Concurrency

Structs:

  • A struct is a user defined type which represents a collection of variables of different or same datatype
  • It is used where we use to group the data into a single unit rather than declaring it individually.
  • To understand Struct, we can consider this structs as classes as there are not classes provided in Go.
  • The type keyword introduces a new type. It's followed by the name of the type (UserDetail), the keyword struct to indicate that we are defining a struct type and a list of fields inside of curly braces. Each field has a name and a type.

Example,

type UserDetail struct {firstName string
lastName string
age int
}
  • In Structs, we can also embed one or more Structs in one struct.
  • The embedded field from a struct will become the fields in the struct in which it has been embedded
  • We can also pass Structs(Structures ) as a parameter to a function. It works the same
  • We can use pointers to structures in the same way as we define pointer to any other variable in Go.
  • This is how we will use Pointer with the above structs,
userDetails *UserDetails

Let’s move to , Part ~ VI, to move ahead and learn some awesome things. See you there !

If you are liking this series, add 👏 and show some love. 💌

Follow me on Facebook, Twitter, Instagram 😃

--

--