Skip to content

Commit

Permalink
Merge pull request #52 from larien/traducao/dependency-injection
Browse files Browse the repository at this point in the history
Tradução de 9. Injeção de Dependência
  • Loading branch information
larien authored Aug 8, 2019
2 parents 161e14c + d371a97 commit b15fb53
Show file tree
Hide file tree
Showing 11 changed files with 308 additions and 297 deletions.
4 changes: 2 additions & 2 deletions build.books.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ docker run -v `pwd`:/source jagregory/pandoc -o aprenda-go-com-testes.pdf --late
primeiros-passos-com-go/structs-methods-and-interfaces.md \
primeiros-passos-com-go/pointers-and-errors.md \
primeiros-passos-com-go/maps.md \
primeiros-passos-com-go/dependency-injection.md \
primeiros-passos-com-go/injecao-de-dependencia.md \
primeiros-passos-com-go/mocking.md \
primeiros-passos-com-go/concurrency.md \
primeiros-passos-com-go/select.md \
Expand Down Expand Up @@ -41,7 +41,7 @@ docker run -v `pwd`:/source jagregory/pandoc -o aprenda-go-com-testes.epub --lat
primeiros-passos-com-go/structs-methods-and-interfaces.md \
primeiros-passos-com-go/pointers-and-errors.md \
primeiros-passos-com-go/maps.md \
primeiros-passos-com-go/dependency-injection.md \
primeiros-passos-com-go/injecao-de-dependencia.md \
primeiros-passos-com-go/mocking.md \
primeiros-passos-com-go/concurrency.md \
primeiros-passos-com-go/select.md \
Expand Down
16 changes: 0 additions & 16 deletions di/v1/di.go

This file was deleted.

18 changes: 0 additions & 18 deletions di/v1/di_test.go

This file was deleted.

25 changes: 0 additions & 25 deletions di/v2/di.go

This file was deleted.

18 changes: 0 additions & 18 deletions di/v2/di_test.go

This file was deleted.

16 changes: 16 additions & 0 deletions injecao-de-dependencia/v1/id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"fmt"
"io"
"os"
)

// Cumprimenta envia um cumprimento personalizado ao escritor
func Cumprimenta(escritor io.Writer, nome string) {
fmt.Fprintf(escritor, "Olá, %s", nome)
}

func main() {
Cumprimenta(os.Stdout, "Elodie")
}
18 changes: 18 additions & 0 deletions injecao-de-dependencia/v1/id_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"bytes"
"testing"
)

func TestCumprimenta(t *testing.T) {
buffer := bytes.Buffer{}
Cumprimenta(&buffer, "Chris")

resultado := buffer.String()
esperado := "Olá, Chris"

if resultado != esperado {
t.Errorf("resultado '%s', esperado '%s'", resultado, esperado)
}
}
25 changes: 25 additions & 0 deletions injecao-de-dependencia/v2/id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"fmt"
"io"
"net/http"
)

// Cumprimenta envia um cumprimento personalizado ao escritor
func Cumprimenta(escritor io.Writer, nome string) {
fmt.Fprintf(escritor, "Olá, %s", nome)
}

// ManipuladorMeuCumprimento diz Olá, mundo via HTTP
func ManipuladorMeuCumprimento(w http.ResponseWriter, r *http.Request) {
Cumprimenta(w, "mundo")
}

func main() {
err := http.ListenAndServe(":5000", http.HandlerFunc(ManipuladorMeuCumprimento))

if err != nil {
fmt.Println(err)
}
}
18 changes: 18 additions & 0 deletions injecao-de-dependencia/v2/id_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"bytes"
"testing"
)

func TestCumprimenta(t *testing.T) {
buffer := bytes.Buffer{}
Cumprimenta(&buffer, "Chris")

resultado := buffer.String()
esperado := "Olá, Chris"

if resultado != esperado {
t.Errorf("resultado '%s', esperado '%s'", resultado, esperado)
}
}
218 changes: 0 additions & 218 deletions primeiros-passos-com-go/dependency-injection.md

This file was deleted.

Loading

0 comments on commit b15fb53

Please sign in to comment.