Skip to content

Commit 2db6d16

Browse files
committed
Translation of code from section 2.2 to Portuguese (PT_BR).
1 parent 5b3f629 commit 2db6d16

File tree

2 files changed

+77
-77
lines changed

2 files changed

+77
-77
lines changed

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

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
// Example code for Chapter 2.2 from "Build Web Application with Golang"
2-
// Purpose: Goes over the assignment and manipulation of basic data types.
1+
// Código de exemplo para o Capítulo 2.2 do "Build Web Application with Golang"
2+
// Propósito: Revisar os conceitos de atribuição e manipulação de tipos de dados básicos.
33
package main
44

55
import (
66
"errors"
77
"fmt"
88
)
99

10-
// constants
10+
// constantes
1111
const Pi = 3.1415926
1212

13-
// booleans default to `false`
14-
var isActive bool // global variable
15-
var enabled, disabled = true, false // omit type of variables
13+
// booleanos: padrão `false`
14+
var isActive bool // variável global
15+
var enabled, disabled = true, false // omite o tipo das variáveis
1616

17-
// grouped definitions
17+
// definições agrupadas
1818
const (
1919
i = 1e4
2020
MaxThread = 10
2121
prefix = "astaxie_"
2222
)
2323

2424
var (
25-
frenchHello string // basic form to define string
26-
emptyString string = "" // define a string with empty string
25+
frenchHello string // forma básica para definir strings
26+
emptyString string = "" // define uma string vazia
2727
)
2828

2929
func show_multiple_assignments() {
3030
fmt.Println("show_multiple_assignments()")
3131
var v1 int = 42
3232

33-
// Define three variables with type "int", and initialize their values.
34-
// vname1 is v1, vname2 is v2, vname3 is v3
33+
// Define três variáveis com o tipo "int" e inicializa seus valores.
34+
// vname1 é v1, vname2 é v2, vname3 é v3
3535
var v2, v3 int = 2, 3
3636

37-
// `:=` only works in functions
38-
// `:=` is the short way of declaring variables without
39-
// specifying the type and using the keyboard `var`.
37+
// `:=` funciona somente em funções
38+
// `:=` é a maneira curta de declarar variáveis sem
39+
// especificar o tipo e usando a palvra-chave `var`.
4040
vname1, vname2, vname3 := v1, v2, v3
4141

42-
// `_` disregards the returned value.
42+
// `_` desconsidera o valor retornado.
4343
_, b := 34, 35
4444

4545
fmt.Printf("vname1 = %v, vname2 = %v, vname3 = %v\n", vname1, vname2, vname3)
@@ -48,9 +48,9 @@ func show_multiple_assignments() {
4848
}
4949
func show_bool() {
5050
fmt.Println("show_bool()")
51-
var available bool // local variable
52-
valid := false // Shorthand assignment
53-
available = true // assign value to variable
51+
var available bool // variável local
52+
valid := false // declara a variável e infere o tipo booleano (declaração curta)
53+
available = true // atribui um valor a variável
5454

5555
fmt.Printf("valid = %v, !valid = %v\n", valid, !valid)
5656
fmt.Printf("available = %v\n", available)
@@ -78,14 +78,14 @@ func show_different_types() {
7878
}
7979
func show_strings() {
8080
fmt.Println("show_strings()")
81-
no, yes, maybe := "no", "yes", "maybe" // brief statement
81+
no, yes, maybe := "no", "yes", "maybe" // declaração curta
8282
japaneseHello := "Ohaiyou"
83-
frenchHello = "Bonjour" // basic form of assign values
83+
frenchHello = "Bonjour" // forma básica de atribuir valores
8484

8585
fmt.Println("Random strings")
8686
fmt.Println(frenchHello, japaneseHello, no, yes, maybe)
8787

88-
// The backtick, `, will not escape any character in a string
88+
// A crase, `, não deixa escapar qualquer caractere da string
8989
fmt.Println(`This
9090
is on
9191
multiple lines`)
@@ -94,18 +94,18 @@ func show_string_manipulation() {
9494
fmt.Println("show_string_manipulation()")
9595
var s string = "hello"
9696

97-
//You can't do this with strings
97+
//Você não pode fazer isso com strings
9898
//s[0] = 'c'
9999

100100
s = "hello"
101-
c := []byte(s) // convert string to []byte type
101+
c := []byte(s) // converte string para o tipo []byte
102102
c[0] = 'c'
103-
s2 := string(c) // convert back to string type
103+
s2 := string(c) // converte novamente para o tipo string
104104

105105
m := " world"
106106
a := s + m
107107

108-
d := "c" + s[1:] // you cannot change string values by index, but you can get values instead.
108+
d := "c" + s[1:] // você não pode alterar valores de string pelo índice, mas você pode obter os valores desta maneira
109109
fmt.Printf("%s\n", d)
110110

111111
fmt.Printf("s = %s, c = %v\n", s, c)
@@ -125,66 +125,66 @@ func show_iota() {
125125
x = iota // x == 0
126126
y = iota // y == 1
127127
z = iota // z == 2
128-
w // If there is no expression after constants name,
129-
// it uses the last expression, so here is saying w = iota implicitly.
130-
// Therefore w == 3, and y and x both can omit "= iota" as well.
128+
w // Se não houver nenhuma expressão após o nome da constante,
129+
// ela usa a última expressão, ou seja, neste caso w = iota implicitamente.
130+
// Portanto w == 3, e tanto y quanto z podem omitir "= iota" também.
131131
)
132132

133-
const v = iota // once iota meets keyword `const`, it resets to `0`, so v = 0.
133+
const v = iota // uma vez que iota encontra a palavra-chave `const`, ela é redefinida para `0`, então v = 0.
134134

135135
const (
136-
e, f, g = iota, iota, iota // e=0,f=0,g=0 values of iota are same in one line.
136+
e, f, g = iota, iota, iota // e=0,f=0,g=0 valores de iota são iguais quando estão na mesma linha.
137137
)
138138
fmt.Printf("x = %v, y = %v, z = %v, w = %v\n", x, y, z, w)
139139
fmt.Printf("v = %v\n", v)
140140
fmt.Printf("e = %v, f = %v, g = %v\n", e, f, g)
141141
}
142142

143-
// Functions and variables starting with a capital letter are public to other packages.
144-
// Everything else is private.
143+
// Funções e variáveis começando com uma letra maiúscula são públicas para outros pacotes.
144+
// Todo o resto é privado.
145145
func This_is_public() {}
146146
func this_is_private() {}
147147

148148
func set_default_values() {
149-
// default values for the types.
149+
// valores padrão para os tipos.
150150
const (
151151
a int = 0
152152
b int8 = 0
153153
c int32 = 0
154154
d int64 = 0
155155
e uint = 0x0
156-
f rune = 0 // the actual type of rune is int32
157-
g byte = 0x0 // the actual type of byte is uint8
158-
h float32 = 0 // length is 4 byte
159-
i float64 = 0 //length is 8 byte
156+
f rune = 0 // o tipo real de rune é int32
157+
g byte = 0x0 // o tipo real de byte é uint8
158+
h float32 = 0 // comprimento é 4 bytes
159+
i float64 = 0 // comprimento é 8 bytes
160160
j bool = false
161161
k string = ""
162162
)
163163
}
164164
func show_arrays() {
165165
fmt.Println("show_arrays()")
166-
var arr [10]int // an array of type int
167-
arr[0] = 42 // array is 0-based
168-
arr[1] = 13 // assign value to element
166+
var arr [10]int // um array do tipo int
167+
arr[0] = 42 // array é baseado em 0
168+
arr[1] = 13 // atribui valor ao elemento
169169

170-
a := [3]int{1, 2, 3} // define a int array with 3 elements
170+
a := [3]int{1, 2, 3} // define um array do tipo int com 3 elementos
171171

172172
b := [10]int{1, 2, 3}
173-
// define a int array with 10 elements,
174-
// and first three are assigned, rest of them use default value 0.
173+
// define um array do tipo int com 10 elementos,
174+
// e os três primeiros são atribuídos, o restante usa o valor padrão 0.
175175

176-
c := [...]int{4, 5, 6} // use `…` replace with number of length, Go will calculate it for you.
176+
c := [...]int{4, 5, 6} // usa `…` para substituir o número do comprimento, Go irá calcular isto para você.
177177

178-
// define a two-dimensional array with 2 elements, and each element has 4 elements.
178+
// define um array bidimensional com 2 elementos, e onde cada elemento possui 4 elementos.
179179
doubleArray := [2][4]int{[4]int{1, 2, 3, 4}, [4]int{5, 6, 7, 8}}
180180

181-
// You can write about declaration in a shorter way.
181+
// Você pode escrever a declaração de forma curta.
182182
easyArray := [2][4]int{{1, 2, 3, 4}, {5, 6, 7, 8}}
183183

184184
fmt.Println("arr =", arr)
185-
fmt.Printf("The first element is %d\n", arr[0]) // get element value, it returns 42
185+
fmt.Printf("The first element is %d\n", arr[0]) // obtém o valor do elemento, retorna 42
186186
fmt.Printf("The last element is %d\n", arr[9])
187-
//it returns default value of 10th element in this array, which is 0 in this case.
187+
// retorna o valor padrão do décimo elemento do array, que neste caso é 0.
188188

189189
fmt.Println("array a =", a)
190190
fmt.Println("array b =", b)
@@ -195,36 +195,36 @@ func show_arrays() {
195195
}
196196
func show_slices() {
197197
fmt.Println("show_slices()")
198-
// define a slice with 10 elements which types are byte
198+
// define um slice de tipo byte com 10 elementos
199199
var ar = [10]byte{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}
200200

201-
// define two slices with type []byte
201+
// define dois slices com o tipo []byte
202202
var a, b []byte
203203

204-
// a points to elements from 3rd to 5th in array ar.
204+
// a aponta para os elementos da posição 3 até a 5 do array ar.
205205
a = ar[2:5]
206-
// now a has elements ar[2]ar[3] and ar[4]
206+
// agora a possui os elementos ar[2], ar[3] e ar[4]
207207

208-
// b is another slice of array ar
208+
// b é outro slice do array ar
209209
b = ar[3:5]
210-
// now b has elements ar[3] and ar[4]
210+
// agora b possui os elementos de ar[3] e ar[4]
211211

212-
// define an array
212+
// define um array
213213
var array = [10]byte{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}
214-
// define two slices
214+
// define dois slices
215215
var aSlice, bSlice []byte
216216

217-
// some convenient operations
218-
aSlice = array[:3] // equals to aSlice = array[0:3] aSlice has elements a,b,c
219-
aSlice = array[5:] // equals to aSlice = array[5:10] aSlice has elements f,g,h,i,j
220-
aSlice = array[:] // equals to aSlice = array[0:10] aSlice has all elements
217+
// algumas operações convenientes
218+
aSlice = array[:3] // igual a aSlice = array[0:3] aSlice possui os elementos a,b,c
219+
aSlice = array[5:] // igual a aSlice = array[5:10] aSlice possui os elementos f,g,h,i,j
220+
aSlice = array[:] // igual a aSlice = array[0:10] aSlice possui todos os elementos
221221

222-
// slice from slice
223-
aSlice = array[3:7] // aSlice has elements d,e,f,g,len=4,cap=7
224-
bSlice = aSlice[1:3] // bSlice contains aSlice[1], aSlice[2], so it has elements e,f
225-
bSlice = aSlice[:3] // bSlice contains aSlice[0], aSlice[1], aSlice[2], so it has d,e,f
226-
bSlice = aSlice[0:5] // slcie could be expanded in range of cap, now bSlice contains d,e,f,g,h
227-
bSlice = aSlice[:] // bSlice has same elements as aSlice does, which are d,e,f,g
222+
// slice de slice
223+
aSlice = array[3:7] // aSlice possui os elementos d,e,f,g,len=4,cap=7
224+
bSlice = aSlice[1:3] // bSlice contém aSlice[1], aSlice[2], ou seja, ele possui os elementos e,f
225+
bSlice = aSlice[:3] // bSlice contém aSlice[0], aSlice[1], aSlice[2], ou seja, ele possui os elementos d,e,f
226+
bSlice = aSlice[0:5] // bSlice pode ser expandido de acordo com cap, agora bSlice contém d,e,f,g,h
227+
bSlice = aSlice[:] // bSlice possui os mesmos elementos de aSlice, os quais são d,e,f,g
228228

229229
fmt.Println("slice ar =", ar)
230230
fmt.Println("slice a =", a)
@@ -236,30 +236,30 @@ func show_slices() {
236236
}
237237
func show_map() {
238238
fmt.Println("show_map()")
239-
// use string as key type, int as value type, and you have to use `make` initialize it.
239+
// use tipo string para a chave, tipo int para o valor, e você precisa usar `make` para inicializar
240240
var numbers map[string]int
241-
// another way to define map
241+
// outra forma de declarar map
242242
numbers = make(map[string]int)
243-
numbers["one"] = 1 // assign value by key
243+
numbers["one"] = 1 // atribui valor pela chave
244244
numbers["ten"] = 10
245245
numbers["three"] = 3
246246

247-
// Initialize a map
247+
// Inicializa um map
248248
rating := map[string]float32{"C": 5, "Go": 4.5, "Python": 4.5, "C++": 2}
249249

250250
fmt.Println("map numbers =", numbers)
251-
fmt.Println("The third number is: ", numbers["three"]) // get values
252-
// It prints: The third number is: 3
251+
fmt.Println("The third number is: ", numbers["three"]) // obtém os valores
252+
// Isto irá imprimir: The third number is: 3
253253

254-
// map has two return values. For second value, if the key doesn't exist,ok is false,true otherwise.
254+
// map possui dois valores de retorno. Se a chave não existir, o segundo valor, neste caso "ok", será falso (false). Caso contrário será verdadeiro (true).
255255
csharpRating, ok := rating["C#"]
256256
if ok {
257257
fmt.Println("C# is in the map and its rating is ", csharpRating)
258258
} else {
259259
fmt.Println("We have no rating associated with C# in the map")
260260
}
261261

262-
delete(rating, "C") // delete element with key "c"
262+
delete(rating, "C") // deleta o elemento com a chave "c"
263263
fmt.Printf("map rating = %#v\n", rating)
264264
}
265265
func main() {

pt-br/code/src/apps/ch.2.2/what_is_wrong_with_this/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Example code for Chapter 2.2 from "Build Web Application with Golang"
2-
// Purpose: Try to fix this program.
3-
// From the console, type `go run main.go`
1+
// Código de exemplo para o Capítulo 2.2 do "Build Web Application with Golang"
2+
// Propósito: Tente corrigir este programa.
3+
// No console, digite `go run main.go`
44
package main
55

66
func main() {

0 commit comments

Comments
 (0)