๐ Basics
package
: package declaration which is mandatory for all Go programs.import "fmt"
: used to import built-in fmt package.func main()
: function is the starting point of execution of any Go program.fmt.printf
: inbuilt library function which is used to print the given message.fmt.Scanf
: inbuilt library function which is used to read the data.//
: to comment a single line/**/
: to comment multiple lines
๐ฆ Variables
๐ Constants
const
values are immutable and evaluated at compile time.
๐ข Data types
1
byte0
to 255
1
byte-128
to 127
2
bytes-32768
to 32767
2
bytes0
to 65,535
4
bytes-2,147,483,648
to 2,147,483,647
4
bytes0
to 4,294,967,295
8
bytes-9e18
to 9e18
8
bytes0
to 18e18
4
bytes8
bytes8
bytes16
bytes1
bytetrue
or false
Example
โ Operators
- Arithmetic:
+
,-
,*
,/
,%
- Comparison:
<
,>
,<=
,>=
,!=
,==
- Bitwise:
&
,^
,|
,&^
,<<
,>>
- Logical:
&&
,||
,!
- Assignment:
=
,+=
,-=
,*=
,%=
๐ค String Functions
len(str)
: returns the length of the string.strings.Compare(a, b)
: compares two strings.strings.Contains(str, substr)
: checks if substr is in str.strings.ToUpper(str)
: converts str to uppercase.strings.ToLower(str)
: converts str to lowercase.strings.HasPrefix(str,"prefix")
: checks if str starts with "prefix".strings.HasSuffix(str,"suffix")
: checks if str ends with "suffix".strings.Index(str, substr)
: returns the index of substr in str.strings.Join([]string, sep)
: joins a slice of strings with sep.strings.Count(str, sep)
: counts occurrences of sep in str.
๐ Arrays
๐ Slice
๐บ Maps
๐ Conditional Statements
๐ Loops
๐ Functions
๐ Pointers
๐ค Structures
โก Concurrency
1. Go-routines
2. Channels
3. Buffered Channels
4. Select
โณ Defer, Panic & Recover
๐งฉ Generics (Go 1.18+)
๐งฑ Interface
๐ฆ Packages & Modules
๐งช Testing
Git
HTML
Want to update?
Subscribe to my blog to receive the latest updates from us.
Monthly articles
New articles will be created every month. No spam
All notifications are notified to you, not spam or advertising.