Translation of section 2.3 to Portuguese (PT_BR).

This commit is contained in:
Kelvin Salton do Prado
2016-12-21 19:05:13 -02:00
parent b37884a4a3
commit d7b6c763b4
9 changed files with 166 additions and 167 deletions

View File

@@ -1,10 +1,10 @@
// Example code for Chapter 2.3 from "Build Web Application with Golang"
// Purpose: Creating a basic function
// Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
// Propósito: Criando uma função básica
package main
import "fmt"
// return greater value between a and b
// retorna o maior valor entre a e b
func max(a, b int) int {
if a > b {
return a
@@ -17,10 +17,10 @@ func main() {
y := 4
z := 5
max_xy := max(x, y) // call function max(x, y)
max_xz := max(x, z) // call function max(x, z)
max_xy := max(x, y) // chama a função max(x, y)
max_xz := max(x, z) // chama a função max(x, z)
fmt.Printf("max(%d, %d) = %d\n", x, y, max_xy)
fmt.Printf("max(%d, %d) = %d\n", x, z, max_xz)
fmt.Printf("max(%d, %d) = %d\n", y, z, max(y, z)) // call function here
fmt.Printf("max(%d, %d) = %d\n", y, z, max(y, z)) // chama a função aqui
}

View File

@@ -1,5 +1,5 @@
// As of Google go 1.1.2, `println()` and `print()` are hidden functions included from the runtime package.
// However it's encouraged to use the print functions from the `fmt` package.
// 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.
// No entanto, é encorajado utilizar as funções de impressão do pacote `fmt`
package main
import "fmt"

View File

@@ -1,25 +1,24 @@
// Example code for Chapter 2.3 from "Build Web Application with Golang"
// Purpose: Shows different ways of importing a package.
// Note: For the package `only_call_init`, we reference the path from the
// base directory of `$GOPATH/src`. The reason being Golang discourage
// the use of relative paths when import packages.
// Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
// Propósito: mostra diferentes formas de importar um pacote.
// Nota: para o pacote `only_call_init`, fazemos referência ao caminho a partir do diretório
// base de `$GOPATH/src`. Golang desencoraja o uso de caminhos relativos para importar pacotes.
// BAD: "./only_call_init"
// GOOD: "apps/ch.2.3/import_packages/only_call_init"
package main
import (
// `_` will only call init() inside the package only_call_init
// `_` irá chamar apenas init() dentro do pacote only_call_init
_ "apps/ch.2.3/import_packages/only_call_init"
f "fmt" // import the package as `f`
. "math" // makes the public methods and constants global
"mymath" // custom package located at $GOPATH/src/
"os" // normal import of a standard package
"text/template" // the package takes the name of last folder path, `template`
f "fmt" // importa o pacote como `f`
. "math" // torna os métodos públicos e constantes globais
"mymath" // pacote personalizado localizado em $GOPATH/src/
"os" // import normal de um pacote padrão
"text/template" // o pacote leva o nome do último caminho da pasta, `template`
)
func main() {
f.Println("mymath.Sqrt(4) =", mymath.Sqrt(4))
f.Println("E =", E) // references math.E
f.Println("E =", E) // referencia math.E
t, _ := template.New("test").Parse("Pi^2 = {{.}}")
t.Execute(os.Stdout, Pow(Pi, 2))

View File

@@ -1,5 +1,5 @@
// Example code for Chapter 2.3 from "Build Web Application with Golang"
// Purpose: Goes over if, else, switch conditions, loops and defer.
// Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
// Propósito: mostra alguns exemplos de if, else, switch, loops e defer.
package main
import "fmt"
@@ -30,25 +30,25 @@ func show_if() {
}
func show_if_var() {
fmt.Println("\n#show_if_var()")
// initialize x, then check if x greater than
// inicializa x, então verifica se x é maior
if x := computedValue(); x > 10 {
fmt.Println("x is greater than 10")
} else {
fmt.Println("x is less than 10")
}
// the following code will not compile, since `x` is only accessible with the if/else block
// o seguinte código não irá compilar, porque `x` é acessível apenas pelo bloco if/else
// fmt.Println(x)
}
func show_goto() {
fmt.Println("\n#show_goto()")
// The call to the label switches the goroutine it seems.
// A chamada para o label altera o fluxo da goroutine.
i := 0
Here: // label ends with ":"
Here: // label termina com ":"
fmt.Println(i)
i++
if i < 10 {
goto Here // jump to label "Here"
goto Here // pule para label "Here"
}
}
func show_for_loop() {
@@ -60,7 +60,7 @@ func show_for_loop() {
fmt.Println("part 1, sum is equal to ", sum)
sum = 1
// The compiler will remove the `;` from the line below.
// O compilador irá remover o `;` da linha abaixo.
// for ; sum < 1000 ; {
for sum < 1000 {
sum += sum
@@ -69,7 +69,7 @@ func show_for_loop() {
for index := 10; 0 < index; index-- {
if index == 5 {
break // or continue
break // ou continue
}
fmt.Println(index)
}

View File

@@ -1,5 +1,5 @@
// Example code for Chapter 2.3 from "Build Web Application with Golang"
// Purpose: Showing how to use `panic()` and `recover()`
// Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
// Propósito: mostrar como usar `panic()` e `recover()`
package main
import (
@@ -22,7 +22,7 @@ func throwsPanic(f func()) (b bool) {
b = true
}
}()
f() // if f causes panic, it will recover
f() // se f causar pânico, isto irá recuperar
return
}
func main(){

View File

@@ -1,5 +1,5 @@
// Example code for Chapter 2.3 from "Build Web Application with Golang"
// Purpose: Shows passing a variable by value and reference
// Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
// Propósito: mostra como passar uma variável por valor e por referência
package main
import "fmt"
@@ -21,7 +21,7 @@ func show_add_by_value() {
func show_add_by_reference() {
x := 3
fmt.Println("x = ", x)
// &x pass memory address of x
// &x passa o endereço de memória de x
fmt.Println("add_by_reference(&x) =", add_by_reference(&x) )
fmt.Println("x = ", x)
}

View File

@@ -1,10 +1,10 @@
// Example code for Chapter 2.3 from "Build Web Application with Golang"
// Purpose: Shows how to define a function type
// Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
// Propósito: mostra como definir um tipo de função
package main
import "fmt"
type testInt func(int) bool // define a function type of variable
type testInt func(int) bool // define uma função como um tipo de variável
func isOdd(integer int) bool {
if integer%2 == 0 {
@@ -20,7 +20,7 @@ func isEven(integer int) bool {
return false
}
// pass the function `f` as an argument to another function
// passa a função `f` como um argumento para outra função
func filter(slice []int, f testInt) []int {
var result []int
@@ -37,7 +37,7 @@ func init() {
func main() {
slice := []int{1, 2, 3, 4, 5, 7}
fmt.Println("slice = ", slice)
odd := filter(slice, isOdd) // use function as values
odd := filter(slice, isOdd) // usa funções como valores
fmt.Println("Odd elements of slice are: ", odd)
even := filter(slice, isEven)
fmt.Println("Even elements of slice are: ", even)

View File

@@ -1,10 +1,10 @@
// Example code for Chapter 2.3 from "Build Web Application with Golang"
// Purpose: Shows how to return multiple values from a function
// Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
// Propósito: mostra como retornar múltiplos valores de uma função
package main
import "fmt"
// return results of A + B and A * B
// retorna os resultados de A + B e A * B
func SumAndProduct(A, B int) (int, int) {
return A + B, A * B
}