
The GO language is part of languages with static and strongly typed typing. So a variable is assigned a type from the start and cannot change it in time.
During compilation, the compiler will perform checks on the respect of the types on these.
The GO language has several type families as in other languages.
The GO Language has several entries for declaring variables.
Common types
Here is a presentation of the types that will be frequently manipulated through developments in GO language..
This type represents true/false logic.
bool
Example in action
package main import "fmt" func main() { var hasValided bool = false hasPublished := true fmt.Printf("%v - %T \n", hasValided, hasValided) fmt.Printf("%v - %T \n", hasPublished, hasPublished) }
This type allows to represent string in UNICODE and immutable format.
string
the string in quotation marks.
Example in action
package main import "fmt" func main() { var message string = "Hello and Welcome to you dear" name := "John Doe" fmt.Printf("%s %s \n"", message, name) fmt.Printf("Message variable is : len(%d) - type(%T) \n"", len(message), message) fmt.Printf("The first letter for the name is %c\n"", name[0]) }
Allows to represent all the numbers said integer, as for example: 10, 20, 1920, 2020. On a certain number of bytes.
int
Signed or not signed values on 32 or 64 bits.
Example in action
package main import "fmt" func main() { valeur1, valeur2 := 100, 150 result := valeur1 + valeur2 fmt.Printf("%d + %d = %d\n", valeur1, valeur2, result) fmt.Printf("valeur1 variable is type(%T) \n"", valeur1) }
Allows to store values between 0.. 256. Byte corresponds to type uint8. So has an unsigned 8-bit integer.
byte
Unsigned values from 0 to 256.
Example in action
package main import "fmt" func main() { var message string = "Hello and Welcome to you dear" var firstLettre byte = message[0] fmt.Printf("%s\n", message) fmt.Printf("Message variable is : len(%d) - type(%T) \n", len(message), message) fmt.Printf("The first letter for the name is %c with the value of %d of type %T\n", firstLettre, firstLettre, firstLettre) }
Stores a floating point number according to IEEE-754.
float32 (simple precision)
float64 (double precision)
Decimal values on 32 or 64 precision bits.
Example in action
package main import ( "fmt" "math" ) func main() { var valeur float32 = 1.25662 valeurOfPi := math.Pi fmt.Printf("%f %T\n"", valeur, valeur) fmt.Printf("%f %T %T\n"", valeurOfPi, valeurOfPi, math.Pi) }
There are also these common types of uses. The following types: the signed integers
Allows to represent all the numbers said integer with the representation of negatives and positives
int8
int16
int32
int64
values signed according to the value of the number to be represented. For example for int8 will be values from -128 to 127.
unsigned integers
Allows to represent all the numbers said integer with the representation of positives only
uint8
uint16
uint32
uint64
values signed according to the value of the number to be represented. For example for int8 will be values from 0 to 255.