GO MOD 1
GO MOD 1
MOD 1:
- P.Priyanandini
Languages that influenced Go:
Go is known for its support for concurrency, which is the ability to run
multiple tasks simultaneously. Concurrency is achieved in Go through the use
of Goroutines and Channels, which allow you to write code that can run
multiple operations at the same time. This makes Go an ideal choice for
building high-performance and scalable network services, as well as for
solving complex computational problems.
Go is influenced by C
programming in Go:
: C/C++ was designed when the computer does not have that much
time.
Features of Golang:
compile time.
fast.
https://www.geeksforgeeks.org/how-to-install-go-on-windows/
?ref=lbp
1. File names that begin with "." or "_" are ignored by the go tool
2. Files with the suffix _test.go are only compiled and run by the go test
tool.
3. Files with os and architecture specific suffixes automatically follow those
same constraints, e.g. name_linux.go will only build on linux,
name_amd64.go will only build on amd64. This is the same as having a
//+build amd64 line at the top of the file
Elementary datatypes:
https://www.geeksforgeeks.org/data-types-in-go/
Keywords in Go Language:
Keywor Description
d
break It is used to break the execution of the loop or in simpler terms, we can
say that is used to terminate the loop.
case The case keyword is used inside the switch statements, and it is used to
match a certain condition that we passed in the switch statement.
chan The chan keyword is used to create a channel in Go. A channel is a way
with which goroutines communicate with each other.
contin The continue keyword is used to pass the control back to the starting of
ue the loop once encountered.
defaul The default keyword is used inside the switch statements and is used to
t denote the case when none of the above-mentioned cases in the switch
statements satisfies the given conditions.
defer The defer keyword is used when we want certain things to work after the
completion of the given function.
else The else keyword or sometimes also known as the else clause is used in
conditional branching, and mainly inside the If/Else statements in Go. It
is used when we want to run a certain code that doesn't satisfy the if
condition.
import The import keyword is used when want to import certain third-party or
Go standard library packages into our code. The import statement is
generally followed by the name of the package that we want to make use
of in our program.
interf The interface keyword is used in Go when we want to create a named
ace collection of method signatures.
map The map keyword is used to create a map data structure in Go. A map is
a collection of key-value pairs in Go.
packag The package keyword in Go is used to declare the name of the package
e for our program. The name of the package is generally main if it is an
executable or else it is the name of the folder it is in.
range The range keyword or sometimes also known as range clause is used
mainly when we are iterating over a ceratin type in Go. It is used with the
for keyword when we want to iterate over an iterable object.
select The select keyword is used when we want to wait on multiple Go channel
operations.
struct The struct keyword is used when we want to create a struct in Go
switch The switch keyword is used to create a switch statement in Go. A switch
statement is a conditional statement
type The type keyword is used when we want to create a new type. The
process of creating a new type is called type definition
var The var keyword is used when we want to create variables in Go.
Identifiers in GO:
compile-time errors will occur. These errors will interrupt the execution of
the program.
The name of an identifier can be a combination of alphabets,
alphabets.
an identifier.
letters.
Now let's look into the table given below to understand which are the valid
can be used.
can be used.
letter.
hello_world valid The name of an identifier can be a
and digits.
an identifier.
an identifier.
Constants in GO:
https://www.geeksforgeeks.org/constants-go-language/
Operators in GO:
https://www.geeksforgeeks.org/go-operators/
Strings in GO:
https://www.geeksforgeeks.org/strings-in-golang/
Syntax:
func (t Time) Date() (year int, month Month, day int)
Return Value: It returns year, month and day of the stated “t”.
package main
import "fmt"
import "time"
// Calling main
func main() {
// Declaring t in UTC
t := time.Date(2020, 5, 6, 11, 45, 04, 0, time.UTC)
// Prints year
fmt.Printf("The stated year is: %v\n", yyyy)
// Prints month
fmt.Printf("The stated month is: %v\n", mm)
// Prints day
fmt.Printf("The stated day is: %v\n", dd)
}
Output:
The stated year is: 2020
The stated month is: May
The stated day is: 6
Pointers in GO:
https://www.tutorialspoint.com/go/go_pointers.htm