Skip to content

Commit d7b6c76

Browse files
committed
Translation of section 2.3 to Portuguese (PT_BR).
1 parent b37884a commit d7b6c76

File tree

9 files changed

+166
-167
lines changed

9 files changed

+166
-167
lines changed

pt-br/02.3.md

+124-124
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Example code for Chapter 2.3 from "Build Web Application with Golang"
2-
// Purpose: Creating a basic function
1+
// Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
2+
// Propósito: Criando uma função básica
33
package main
44

55
import "fmt"
66

7-
// return greater value between a and b
7+
// retorna o maior valor entre a e b
88
func max(a, b int) int {
99
if a > b {
1010
return a
@@ -17,10 +17,10 @@ func main() {
1717
y := 4
1818
z := 5
1919

20-
max_xy := max(x, y) // call function max(x, y)
21-
max_xz := max(x, z) // call function max(x, z)
20+
max_xy := max(x, y) // chama a função max(x, y)
21+
max_xz := max(x, z) // chama a função max(x, z)
2222

2323
fmt.Printf("max(%d, %d) = %d\n", x, y, max_xy)
2424
fmt.Printf("max(%d, %d) = %d\n", x, z, max_xz)
25-
fmt.Printf("max(%d, %d) = %d\n", y, z, max(y, z)) // call function here
25+
fmt.Printf("max(%d, %d) = %d\n", y, z, max(y, z)) // chama a função aqui
2626
}

pt-br/code/src/apps/ch.2.3/hidden_print_methods/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// As of Google go 1.1.2, `println()` and `print()` are hidden functions included from the runtime package.
2-
// However it's encouraged to use the print functions from the `fmt` package.
1+
// A partir do Google go 1.1.2, `println()` e `print()` são funções ocultas incluídas no pacote de tempo de execução.
2+
// No entanto, é encorajado utilizar as funções de impressão do pacote `fmt`
33
package main
44

55
import "fmt"

pt-br/code/src/apps/ch.2.3/import_packages/main.go

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
// Example code for Chapter 2.3 from "Build Web Application with Golang"
2-
// Purpose: Shows different ways of importing a package.
3-
// Note: For the package `only_call_init`, we reference the path from the
4-
// base directory of `$GOPATH/src`. The reason being Golang discourage
5-
// the use of relative paths when import packages.
1+
// Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
2+
// Propósito: mostra diferentes formas de importar um pacote.
3+
// Nota: para o pacote `only_call_init`, fazemos referência ao caminho a partir do diretório
4+
// base de `$GOPATH/src`. Golang desencoraja o uso de caminhos relativos para importar pacotes.
65
// BAD: "./only_call_init"
76
// GOOD: "apps/ch.2.3/import_packages/only_call_init"
87
package main
98

109
import (
11-
// `_` will only call init() inside the package only_call_init
10+
// `_` irá chamar apenas init() dentro do pacote only_call_init
1211
_ "apps/ch.2.3/import_packages/only_call_init"
13-
f "fmt" // import the package as `f`
14-
. "math" // makes the public methods and constants global
15-
"mymath" // custom package located at $GOPATH/src/
16-
"os" // normal import of a standard package
17-
"text/template" // the package takes the name of last folder path, `template`
12+
f "fmt" // importa o pacote como `f`
13+
. "math" // torna os métodos públicos e constantes globais
14+
"mymath" // pacote personalizado localizado em $GOPATH/src/
15+
"os" // import normal de um pacote padrão
16+
"text/template" // o pacote leva o nome do último caminho da pasta, `template`
1817
)
1918

2019
func main() {
2120
f.Println("mymath.Sqrt(4) =", mymath.Sqrt(4))
22-
f.Println("E =", E) // references math.E
21+
f.Println("E =", E) // referencia math.E
2322

2423
t, _ := template.New("test").Parse("Pi^2 = {{.}}")
2524
t.Execute(os.Stdout, Pow(Pi, 2))

pt-br/code/src/apps/ch.2.3/main.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Example code for Chapter 2.3 from "Build Web Application with Golang"
2-
// Purpose: Goes over if, else, switch conditions, loops and defer.
1+
// Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
2+
// Propósito: mostra alguns exemplos de if, else, switch, loops e defer.
33
package main
44

55
import "fmt"
@@ -30,25 +30,25 @@ func show_if() {
3030
}
3131
func show_if_var() {
3232
fmt.Println("\n#show_if_var()")
33-
// initialize x, then check if x greater than
33+
// inicializa x, então verifica se x é maior
3434
if x := computedValue(); x > 10 {
3535
fmt.Println("x is greater than 10")
3636
} else {
3737
fmt.Println("x is less than 10")
3838
}
3939

40-
// the following code will not compile, since `x` is only accessible with the if/else block
40+
// o seguinte código não irá compilar, porque `x` é acessível apenas pelo bloco if/else
4141
// fmt.Println(x)
4242
}
4343
func show_goto() {
4444
fmt.Println("\n#show_goto()")
45-
// The call to the label switches the goroutine it seems.
45+
// A chamada para o label altera o fluxo da goroutine.
4646
i := 0
47-
Here: // label ends with ":"
47+
Here: // label termina com ":"
4848
fmt.Println(i)
4949
i++
5050
if i < 10 {
51-
goto Here // jump to label "Here"
51+
goto Here // pule para label "Here"
5252
}
5353
}
5454
func show_for_loop() {
@@ -60,7 +60,7 @@ func show_for_loop() {
6060
fmt.Println("part 1, sum is equal to ", sum)
6161

6262
sum = 1
63-
// The compiler will remove the `;` from the line below.
63+
// O compilador irá remover o `;` da linha abaixo.
6464
// for ; sum < 1000 ; {
6565
for sum < 1000 {
6666
sum += sum
@@ -69,7 +69,7 @@ func show_for_loop() {
6969

7070
for index := 10; 0 < index; index-- {
7171
if index == 5 {
72-
break // or continue
72+
break // ou continue
7373
}
7474
fmt.Println(index)
7575
}

pt-br/code/src/apps/ch.2.3/panic_and_recover/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Example code for Chapter 2.3 from "Build Web Application with Golang"
2-
// Purpose: Showing how to use `panic()` and `recover()`
1+
// Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
2+
// Propósito: mostrar como usar `panic()` e `recover()`
33
package main
44

55
import (
@@ -22,7 +22,7 @@ func throwsPanic(f func()) (b bool) {
2222
b = true
2323
}
2424
}()
25-
f() // if f causes panic, it will recover
25+
f() // se f causar pânico, isto irá recuperar
2626
return
2727
}
2828
func main(){

pt-br/code/src/apps/ch.2.3/pass_by_value_and_pointer/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Example code for Chapter 2.3 from "Build Web Application with Golang"
2-
// Purpose: Shows passing a variable by value and reference
1+
// Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
2+
// Propósito: mostra como passar uma variável por valor e por referência
33
package main
44

55
import "fmt"
@@ -21,7 +21,7 @@ func show_add_by_value() {
2121
func show_add_by_reference() {
2222
x := 3
2323
fmt.Println("x = ", x)
24-
// &x pass memory address of x
24+
// &x passa o endereço de memória de x
2525
fmt.Println("add_by_reference(&x) =", add_by_reference(&x) )
2626
fmt.Println("x = ", x)
2727
}

pt-br/code/src/apps/ch.2.3/type_function/main.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Example code for Chapter 2.3 from "Build Web Application with Golang"
2-
// Purpose: Shows how to define a function type
1+
// Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
2+
// Propósito: mostra como definir um tipo de função
33
package main
44

55
import "fmt"
66

7-
type testInt func(int) bool // define a function type of variable
7+
type testInt func(int) bool // define uma função como um tipo de variável
88

99
func isOdd(integer int) bool {
1010
if integer%2 == 0 {
@@ -20,7 +20,7 @@ func isEven(integer int) bool {
2020
return false
2121
}
2222

23-
// pass the function `f` as an argument to another function
23+
// passa a função `f` como um argumento para outra função
2424

2525
func filter(slice []int, f testInt) []int {
2626
var result []int
@@ -37,7 +37,7 @@ func init() {
3737
func main() {
3838
slice := []int{1, 2, 3, 4, 5, 7}
3939
fmt.Println("slice = ", slice)
40-
odd := filter(slice, isOdd) // use function as values
40+
odd := filter(slice, isOdd) // usa funções como valores
4141
fmt.Println("Odd elements of slice are: ", odd)
4242
even := filter(slice, isEven)
4343
fmt.Println("Even elements of slice are: ", even)

pt-br/code/src/apps/ch.2.3/variadic_functions/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Example code for Chapter 2.3 from "Build Web Application with Golang"
2-
// Purpose: Shows how to return multiple values from a function
1+
// Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
2+
// Propósito: mostra como retornar múltiplos valores de uma função
33
package main
44

55
import "fmt"
66

7-
// return results of A + B and A * B
7+
// retorna os resultados de A + B e A * B
88
func SumAndProduct(A, B int) (int, int) {
99
return A + B, A * B
1010
}

0 commit comments

Comments
 (0)