|
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. |
6 | 5 | // BAD: "./only_call_init"
|
7 | 6 | // GOOD: "apps/ch.2.3/import_packages/only_call_init"
|
8 | 7 | package main
|
9 | 8 |
|
10 | 9 | import (
|
11 |
| - // `_` will only call init() inside the package only_call_init |
| 10 | + // `_` irá chamar apenas init() dentro do pacote only_call_init |
12 | 11 | _ "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` |
18 | 17 | )
|
19 | 18 |
|
20 | 19 | func main() {
|
21 | 20 | f.Println("mymath.Sqrt(4) =", mymath.Sqrt(4))
|
22 |
| - f.Println("E =", E) // references math.E |
| 21 | + f.Println("E =", E) // referencia math.E |
23 | 22 |
|
24 | 23 | t, _ := template.New("test").Parse("Pi^2 = {{.}}")
|
25 | 24 | t.Execute(os.Stdout, Pow(Pi, 2))
|
|
0 commit comments