Saturday, January 19, 2019

Introduction of Go language ..


Go Language Introduction

Go Tutorial
Go tutorial provides basic and advanced concepts of Go programming. Our Go language tutorial is designed for beginners and professionals both.
Go is a programming language which is developed by Google with the vision of fast development and high performance.
Our Go Tutorial includes all topics of Go language such as what is go, how to install go, go if-else, go for, go for-range, go break, go continue, go struct, go interface, go ruin, go map, go string, go array, go http server, go rest api, go mutex etc.

Go Language Introduction

Go is a programming language which is developed by Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. Go is a statically-typed language. Go has a similar syntax to C. It is developed with the vision of high performance and fast development. Go provides type safety, garbage collection, dynamic-typing capability, many advanced built-in types such as variable length arrays and key-value maps etc.
  • Go is modern, fast and comes with a powerful standard library.
  • Go has built-in concurrency.
  • Go uses interfaces as the building blocks of code reusability.
The basic structure of a Go programs consists of following parts:-
  • Package Declaration
  • Import Packages
  • Variables
  • Statements and Expressions
  • Functions
  • Comments

Go Example

Let's see a simple example of Go programming language.
  1. package main  
  2. import "fmt"  
  3. func main() {  
  4.    fmt.Println("Hello, World")  
  5. }  
Output:
Hello, World

A complete explanation of "Go Hello World example" is given in next pages.


Go Data Types

Variables can be of different types like int, float, struct, slice or it can be of the interface.
The general form for declaring a variable uses the keyword var:
Syntax:-
  1. var identifier type  
Example

  1. var a int  
  2. var b bool  
  3. var str string  
when a variable is declared with var it automatically initializes it to the zero-value defined for its type. A type defines the set of values and the set of operations that can take place on those values.
GO Simple Data Type Example
  1. package main  
  2. import "fmt"  
  3. func main() {  
  4.    var i int  
  5.    var f float64  
  6.    var b bool  
  7.    var s string  
  8.    fmt.Printf("%T %T %T %T\n",i,f,b,s) // Prints type of the variable  
  9.    fmt.Printf("%v   %v      %v  %q     \n", i, f, b, s) //prints initial value of the variable  
  10. }  
Output:


int float64 bool string
0   0           false  ""    

Go Construct and Data Types

The Go source code is stored in .go file. The name of the file consists of lowercase letters. If the file name has several parts, it should be separated by underscore "_" .
Go file has a name or an identifier which is case sensitive like C.

For example: a, ax123, i etc.
The _ identifier is special. It is called blank identifier. It may be used in variable declarations.
It is like normal identifiers but its value is discarded, so it cannot be used anymore in the code.
It may happen that the variable, type, or function has no name and even enhance flexibility so it is called anonymous.


These are the 25 keywords for Go-code:
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough If range type
continue for import return var


Programs consist of keywords, constants, variables, operators, types and functions.
The following delimiters are used in constructs such as parentheses ( ), brackets [ ] and braces { }.
The following punctuation characters . , ; : and ... are used.

append bool byte cap close complex complex64 complex128 uint16
copy false float32 float64 imag int int8 int16 uint32
int32 int64 iota len make new nil panic uint64
print println real recover string true uint uint8 Uintptr

No comments:

Post a Comment