Categorygithub.com/JoseGaldamez/go_introduction_course
repository
0.0.0-20231024231359-ed82bbb5740a
Repository: https://github.com/josegaldamez/go_introduction_course.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

Indice

Variables

Podemos definir una variable indicando el tipo de dato

var int myVar
myVar = 64

O podemos utilizar el dos puntos igual (:=) para instanciar y asignar al mismo tiempo, va a tomar el tipo de dato del valor que le pasamos

myVar := 64

Int

var int64 myVar
myVar = 64
TipoTamañoRango
int88 bits-128 hasta 127
int1616 bits-215 hasta 215 -1
int3232 bits-231 hasta 231 -1
int6464 bits-263 hasta 263 -1
intDepende plataformaDepende plataforma

Uint

var uint64 myVar
myVar = 64
TipoTamañoRango
uint88 bits0 hasta 255
uint1616 bits0 hasta 216 -1
uint3232 bits0 hasta 232 -1
uint6464 bits0 hasta 264 -1
uintDepende plataformaDepende plataforma

Float

var float64 myVar
myVar = 64.55
TipoTamaño
float3232 bits
float6464 bits

String

Los strings son cadenas de bytes

var string myVar
myVar = "My string"

Operadores Logicos

Or

ABA or B
falsefalsefalse
falsetruetrue
truefalsetrue
truetruetrue
myValue1 := 3
myValue2 := 5

fmt.Println(myValue1 == myValue2 || myValue1 < myValue2) // (false or true) = true

And

ABA and B
falsefalsefalse
falsetruefalse
truefalsefalse
truetruetrue
myValue1 := 3
myValue2 := 5

fmt.Println(myValue1 == myValue2 && myValue1 < myValue2) // (false and true) = false

Vetores

Array

Tamaño fijo

	var myArrayVar [6]int
	fmt.Println(myArrayVar)

	myArrayVar1 := [3]string{"value1", "value2", "value3"}
	fmt.Println(myArrayVar1)

	myArrayVar[1] = 2
	myArrayVar[2] = 5
	myArrayVar[3] = 9
	fmt.Println(myArrayVar)

Slice

Tamaño dinamico

var slice1 []int

slice1 = append(slice1, 10, 20, 30, 40, 50)
fmt.Printf("size: %d, value %v\n", len(slice1), slice1)

Maps

// Declaracion e instancia de la variable
m1 := make(map[int]string)

// Asignamos valores
m1[1] = "A"
m1[2] = "B"
m1[3] = "C"

// Mostramos el valor de la key 1
fmt.Println(m1[1])

For

sum := 0
for i := 0; i < 10; i++ {
	sum++
}


arr := []int{1, 2, 3, 1, 2, 3}
for i, v := range arr {
	fmt.Println("Index: ",i ," - Value: ", v)
}

map2 := map[string]float64{
	"A": 12.3,
	"Z": 23.1,
	"C": 34,
}
for key, value := range map2 {
	fmt.Println("Key:", key, "Value:", value)
}

Functions

// x, y are int parameters & return int value
func MiFunction(x, y int) int {
	return x + y
}