Skip to content

Commit b7d5553

Browse files
committed
apply go fmt
1 parent 3ffa263 commit b7d5553

7 files changed

+116
-116
lines changed

array.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import "fmt"
1414
// - TYPE: any of default types in Go or structs that you've created.
1515
// - DEFAULT_VALUES: this is optional but it is used when you want to create an array with default values on it.
1616
func main() {
17-
var words [2]string // declaring an array called words with 2 elements.
18-
words[0] = "Hello" // assign the word "Hello" to the first element into the array
19-
words[1] = "World" // assign the word "World" to the second element into the array
17+
var words [2]string // declaring an array called words with 2 elements.
18+
words[0] = "Hello" // assign the word "Hello" to the first element into the array
19+
words[1] = "World" // assign the word "World" to the second element into the array
2020

21-
fmt.Println(words[0], words[1]) // Prints the first and the second element of the array.
22-
fmt.Println(words) // Prints the whole array
21+
fmt.Println(words[0], words[1]) // Prints the first and the second element of the array.
22+
fmt.Println(words) // Prints the whole array
2323

24-
primes := [6]int{2, 3, 5, 7, 11, 13} // declaring an array for the 6 prime numbers.
25-
fmt.Println(primes)
24+
primes := [6]int{2, 3, 5, 7, 11, 13} // declaring an array for the 6 prime numbers.
25+
fmt.Println(primes)
2626
}

conditional_statements.go

+35-35
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,42 @@ import "fmt"
2121
//
2222
// In Golang we have two ways of doing conditional statements: `if/else` and `switch/case`.
2323
func main() {
24-
var age int
25-
var country string
26-
fmt.Println("How old are you?")
27-
fmt.Scanln(&age)
28-
fmt.Println("Where are you from?")
29-
fmt.Scanln(&country)
24+
var age int
25+
var country string
26+
fmt.Println("How old are you?")
27+
fmt.Scanln(&age)
28+
fmt.Println("Where are you from?")
29+
fmt.Scanln(&country)
3030

31-
// One good example is asking your age before visiting some websites.
32-
// If the person is a minor, we shouldn't allow him/her to visit the page.
33-
// This case is what we call `if/else` statement because it should choose between actions by evaluating expressions as true or false.
34-
// It will always execute the first true condition and if no condition is satisfied, it will execute the else.
35-
if age >= 21 {
36-
// If the provided age is equal or higher to 21, it will print "Welcome!"
37-
fmt.Println("Welcome!")
38-
} else if age >= 18 && country != "US" {
39-
// If the provided age is equal or higher to 18 and the user is not from the US it will print the message.
40-
fmt.Println("Quite young but still welcome!")
41-
} else {
42-
// If the age is below 18 it will print the following message.
43-
fmt.Println("hmmm... maybe you should not be allowed on here!")
44-
}
31+
// One good example is asking your age before visiting some websites.
32+
// If the person is a minor, we shouldn't allow him/her to visit the page.
33+
// This case is what we call `if/else` statement because it should choose between actions by evaluating expressions as true or false.
34+
// It will always execute the first true condition and if no condition is satisfied, it will execute the else.
35+
if age >= 21 {
36+
// If the provided age is equal or higher to 21, it will print "Welcome!"
37+
fmt.Println("Welcome!")
38+
} else if age >= 18 && country != "US" {
39+
// If the provided age is equal or higher to 18 and the user is not from the US it will print the message.
40+
fmt.Println("Quite young but still welcome!")
41+
} else {
42+
// If the age is below 18 it will print the following message.
43+
fmt.Println("hmmm... maybe you should not be allowed on here!")
44+
}
4545

46-
var animal string
47-
fmt.Println("What is your favorite animal?")
48-
fmt.Scanln(&animal)
46+
var animal string
47+
fmt.Println("What is your favorite animal?")
48+
fmt.Scanln(&animal)
4949

50-
// Sometimes, we do not want to check if something is true or false, but to check if it has a specific value.
51-
// This is the best option to use the switch statement.
52-
switch animal {
53-
case "dog":
54-
fmt.Println("Dogs bark, right?")
55-
case "cat":
56-
fmt.Println("Meow!")
57-
case "fish":
58-
fmt.Println("I've no clue how a fish sounds...")
59-
default:
60-
fmt.Println("Hm... I need to upgrady my animal list...")
61-
}
50+
// Sometimes, we do not want to check if something is true or false, but to check if it has a specific value.
51+
// This is the best option to use the switch statement.
52+
switch animal {
53+
case "dog":
54+
fmt.Println("Dogs bark, right?")
55+
case "cat":
56+
fmt.Println("Meow!")
57+
case "fish":
58+
fmt.Println("I've no clue how a fish sounds...")
59+
default:
60+
fmt.Println("Hm... I need to upgrady my animal list...")
61+
}
6262
}

constants_and_variables.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ import "fmt"
3535
const hello = "Hello, World." // Defining a constant
3636

3737
func main() {
38-
var number int // Declaring an integer variable
39-
number = 10 // Assign 10 to this variable
40-
fmt.Println("Number =", number) // Printing number to the screen
41-
// number = "maybe?" // if you un-comment, it will raise a compilation error.
38+
var number int // Declaring an integer variable
39+
number = 10 // Assign 10 to this variable
40+
fmt.Println("Number =", number) // Printing number to the screen
41+
// number = "maybe?" // if you un-comment, it will raise a compilation error.
4242

43-
var name = "Matheus" // Declaring a string variable and assigning a text to it.
44-
fmt.Println(hello, "I'm", name) // Printing the constant hello and the variable name to the screen
45-
// hello = "hm..." // if you un-comment, it will raise a compilation error.
46-
name = "Mina"
47-
fmt.Println(hello, "I'm", name) // Printing the constant hello and the variable name to the screen
43+
var name = "Matheus" // Declaring a string variable and assigning a text to it.
44+
fmt.Println(hello, "I'm", name) // Printing the constant hello and the variable name to the screen
45+
// hello = "hm..." // if you un-comment, it will raise a compilation error.
46+
name = "Mina"
47+
fmt.Println(hello, "I'm", name) // Printing the constant hello and the variable name to the screen
4848

49-
pi := 3.1415 // Declaring a variable called pi and assigning a value to it
50-
fmt.Println("Pi =", pi) // Printing pi to the screen
49+
pi := 3.1415 // Declaring a variable called pi and assigning a value to it
50+
fmt.Println("Pi =", pi) // Printing pi to the screen
5151
}

functions.go

+25-25
Original file line numberDiff line numberDiff line change
@@ -21,52 +21,52 @@ import "fmt"
2121
// To run a Go code, we always define a function called main, which will be executed when you call:
2222
// $ go run file.go
2323
func main() {
24-
// This is how a function can be called.
25-
hi()
24+
// This is how a function can be called.
25+
hi()
2626

27-
// The return of functions can be stored as variables.
28-
// Also, to provide the arguments to the functions you don't need to say the type.
29-
value := add(1, 1)
30-
fmt.Println("1 + 1 =", value)
27+
// The return of functions can be stored as variables.
28+
// Also, to provide the arguments to the functions you don't need to say the type.
29+
value := add(1, 1)
30+
fmt.Println("1 + 1 =", value)
3131

32-
x := 1
33-
y := 2
34-
// This is how we call a function with pointers.
35-
// We can see the variables from main function got their value changed.
36-
swap(&x, &y)
37-
fmt.Println("x =", x)
38-
fmt.Println("y =", y)
32+
x := 1
33+
y := 2
34+
// This is how we call a function with pointers.
35+
// We can see the variables from main function got their value changed.
36+
swap(&x, &y)
37+
fmt.Println("x =", x)
38+
fmt.Println("y =", y)
3939

40-
// Passing array to a function.
41-
array := []int{1, 2, 3, 4, 5}
42-
print_elements(array, 5)
40+
// Passing array to a function.
41+
array := []int{1, 2, 3, 4, 5}
42+
print_elements(array)
4343
}
4444

4545
// We are declaring a function called `hi`, which will add two numbers.
4646
// As you can see, it receives no parameters and will not return anything to the main function.
4747
func hi() {
48-
fmt.Println("Hello!")
48+
fmt.Println("Hello!")
4949
}
5050

5151
// We are declaring a function called `add`, which will add two numbers.
5252
// As you can see, it receives two parameters of `int` type: `x` and `y`.
5353
// It will always returns another `int`.
5454
func add(x int, y int) int {
55-
return x + y
55+
return x + y
5656
}
5757

5858
// Functions can receive pointers as arguments.
5959
// This is really useful when we want to change values in variables from different contexts.
6060
// In this case, we are receive pointers for two integers and we are swaping their values.
6161
func swap(x *int, y *int) {
62-
temp := *x
63-
*x = *y
64-
*y = temp
62+
temp := *x
63+
*x = *y
64+
*y = temp
6565
}
6666

6767
// Functions can receive arrays as arguments.
68-
func print_elements(array []int, size int) {
69-
for i := 0; i < size; i++ {
70-
fmt.Println(array[i])
71-
}
68+
func print_elements(array []int) {
69+
for _, v := range array {
70+
fmt.Println(v)
71+
}
7272
}

pointers.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,32 @@ import "fmt"
99
// Unlike C, Go has no pointer arithmetic.
1010

1111
type Rectangle struct {
12-
lenght int
13-
width int
12+
lenght int
13+
width int
1414
}
1515

1616
func main() {
17-
// Defining a pointer p.
18-
var p *int
19-
i := 42
17+
// Defining a pointer p.
18+
var p *int
19+
i := 42
2020

21-
// If you want to get the pointer for another variable you can use the & operator.
22-
p = &i
21+
// If you want to get the pointer for another variable you can use the & operator.
22+
p = &i
2323

24-
// To access value from pointer you should use the * operator.
25-
fmt.Println("Value holded by p", p)
26-
fmt.Println("Reading i through p", *p)
24+
// To access value from pointer you should use the * operator.
25+
fmt.Println("Value holded by p", p)
26+
fmt.Println("Reading i through p", *p)
2727

28-
// setting i through the pointer p
29-
// This is known as "dereferencing" or "indirecting".
30-
*p = 21
31-
fmt.Println("New value at i through p", *p)
28+
// setting i through the pointer p
29+
// This is known as "dereferencing" or "indirecting".
30+
*p = 21
31+
fmt.Println("New value at i through p", *p)
3232

33-
r := Rectangle{1, 2}
34-
// Defining a pointer for r
35-
r_pointer := &r
33+
r := Rectangle{1, 2}
34+
// Defining a pointer for r
35+
r_pointer := &r
3636

37-
// If you have a pointer for a struct, you can call its attributes in the same way if it was not a pointer.
38-
area := r_pointer.lenght * r_pointer.width
39-
fmt.Println("rectangle area's:", area)
37+
// If you have a pointer for a struct, you can call its attributes in the same way if it was not a pointer.
38+
area := r_pointer.lenght * r_pointer.width
39+
fmt.Println("rectangle area's:", area)
4040
}

stdin_stdout.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import "fmt"
66
// In basic programs like ours, we do that by reading information from the terminal and printing it back there.
77
// This is what we call "reading from the `stdin`" and "printing to the `stdout`"
88
func main() {
9-
var name string
9+
var name string
1010

11-
// We are printing a question to the stdout
12-
fmt.Println("What is your name?")
11+
// We are printing a question to the stdout
12+
fmt.Println("What is your name?")
1313

14-
// We are reading the awnser from the user and storing it in a variable called name.
15-
fmt.Scanln(&name)
14+
// We are reading the awnser from the user and storing it in a variable called name.
15+
fmt.Scanln(&name)
1616

17-
fmt.Println("Hello", name)
17+
fmt.Println("Hello", name)
1818
}

structs.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ import "fmt"
1313
// - FIELD_NAME: the name that you're gonna use for the field.
1414
// - FIELD_TYPE: any of default types in Go or structs that you've created.
1515
type Rectangle struct {
16-
lenght int
17-
width int
16+
lenght int
17+
width int
1818
}
1919

2020
func main() {
21-
var rectangle_1 Rectangle // Declaring a struct without any default value.
22-
fmt.Println(rectangle_1)
21+
var rectangle_1 Rectangle // Declaring a struct without any default value.
22+
fmt.Println(rectangle_1)
2323

24-
// To set the fields of the struct, you use `variable.field_name` and then the operator =
25-
rectangle_1.width = 1
26-
rectangle_1.lenght = 2
27-
fmt.Println(rectangle_1)
24+
// To set the fields of the struct, you use `variable.field_name` and then the operator =
25+
rectangle_1.width = 1
26+
rectangle_1.lenght = 2
27+
fmt.Println(rectangle_1)
2828

29-
rectangle_2 := Rectangle{3, 2} // Declaring a struct with default values.
29+
rectangle_2 := Rectangle{3, 2} // Declaring a struct with default values.
3030

31-
// To get the fields of the struct, you use `variable.field_name`
32-
area := rectangle_2.lenght * rectangle_2.width
31+
// To get the fields of the struct, you use `variable.field_name`
32+
area := rectangle_2.lenght * rectangle_2.width
3333

34-
fmt.Println("rectangle_2 area's:", area)
34+
fmt.Println("rectangle_2 area's:", area)
3535
}

0 commit comments

Comments
 (0)