@fernandob/

Go lang Overview

Go

No description

fork
loading
Files
  • main.go
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main

import (
    "fmt"
    "strings"
)

// INT TYPES
// int, int8, int16, int32, int64

// UINT - Can ONLY hold positive numbers
// uint, uint8, uint16, uint32, uint64

// FLOAT TYPES
// float32, float64

// Capital CONTANTS AND FUNCTIONS will be exported
// lowercase CONTANTS AND FUNCTIONS will only be accessible from the local package scope

type Parent struct {
  name string
  children []string
}

func main() {
    funWithTypes()
}

func funWithStructs(){
    mike := Parent{name: "Mike"}
    mike.children = append(mike.children, "MJ")
    mike.children = append(mike.children, "Sofi")


    frank := Parent{name: "Frank"}
    frank.children = append(frank.children, "Franky")
    frank.children = append(frank.children, "Christopher")
    fmt.Println(mike)
    fmt.Println(frank)
}

func hello(name string) {
    fmt.Println("Hello " + name)
}

func getArea(w, l float64) string {
    // Formatted String
    return fmt.Sprintf("The area of %v and %v is %v", l, w, l * w)
}

func CalculateTax(salesTotal, taxRate float64) float64 {
  return salesTotal * taxRate
}

func funWithPointers(){
    num := 42
    var pointToNumAdd *int = &num
    fmt.Printf("%v is the address of variable num \n", pointToNumAdd)
    fmt.Printf("%v is the value of variable num", *pointToNumAdd)
}

func usingPointers(number *int) {
    t := *number
    *number = *number / 2
    fmt.Printf("%v divided by 2 is %v\n", t ,*number)
    fmt.Println("the mem address is",number)
}

func funWithArrays(){
    var brothers [3]string
    brothers[0] = "mike"
    brothers[1] = "frank"
    brothers[2] = "fernando"

    siblingOffspring := [4]string { "Mj", "Sofi", "Franky", "Christopher" }
    
    for i:=0; i < len(siblingOffspring); i++ {
        fmt.Println(siblingOffspring[i])
    }

    fmt.Println("_____________________")

    for _, sibling := range brothers {
        fmt.Println(sibling)
    }
}

func funWithSlices(){
    s := []int {1,2,3}
    otherslice := []int {}
    for _, i := range s {
        otherslice = append(otherslice, i)
    }
    fmt.Println(len(otherslice) == 3)
}

func funWithMaps(){
    temp := map[string]float64 {"OCKOPROG": 89.99, "ALBOÖMME": 129.99, "TRAALLÅ": 49.99}
    fmt.Println(HalfPriceSale(temp))
}

func HalfPriceSale(prices map[string]float64) map[string]float64 {
    temp := map[string]float64 {}
    for k, v := range prices {
      temp[k] = v/2
    }
    return temp
}

type Parent string
func (p Parent) FixCase() string {
    return strings.Title(string(p))
}

func funWithTypes(){
    
    Mike := Parent("mike")
    FixCase(Mike)
}