Skip to content

Commit

Permalink
golang example fix issue #7 and gitignore .env
Browse files Browse the repository at this point in the history
  • Loading branch information
leogregianin committed Nov 7, 2017
1 parent 7d87d9d commit 5865a81
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
3 changes: 0 additions & 3 deletions .env

This file was deleted.

3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cepabertoToken=
PORT=3000
export GIN_MODE=release
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
.glide/
/debug
/.vscode
/.env
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,53 @@ print(json.loads(data.decode(encoding)))

### Golang
```go
package main

import (
"encoding/json"
"fmt"
"log"
"net/http"
"net/url"
)

type brCep struct {
Cep string `json:"cep"`
Endereco string `json:"endereco"`
Bairro string `json:"bairro"`
Complemento string `json:"complemento"`
Cidade string `json:"cidade"`
Uf string `json:"uf"`
Ibge string `json:"ibge"`
Latitude string `json:"latitude"`
Longitude string `json:"longitude"`
}

func main() {
cep := "78048000"
cepSeguro := url.QueryEscape(cep)

url := fmt.Sprintf("https://brcep.herokuapp.com/%s/json", cepSeguro)

req, err := http.NewRequest("GET", url, nil)

client := &http.Client{}

resp, err := client.Do(req)
if err != nil {
log.Fatal("Do: ", err)
return
}

defer resp.Body.Close()
var resultado brCep

if err := json.NewDecoder(resp.Body).Decode(&resultado); err != nil {
log.Println(err)
}

fmt.Printf("%+v\n", resultado)
}
```

### Ruby
Expand Down Expand Up @@ -151,7 +197,9 @@ end;
- [ ] Implementar retorno da API com XML
- [ ] Implementar retorno da API com GraphQL
- [X] Implementar exemplos de uso da API em curl, Javascript, Python, Ruby, PHP e Delphi
- [ ] Implementar exemplos de uso da API em C#, Java e Go
- [X] Implementar exemplos de uso da API em Go
- [ ] Implementar exemplos de uso da API em Java
- [ ] Implementar exemplos de uso da API em C#
- [X] Arquivo .env define as configurações do ambiente
- [ ] Gravar as informações do CEP consultado em um banco de dados
- [ ] A cada requisição fazer a consulta em thread parallelism (goroutines) em todas as APIs e atualizar o banco de dados
Expand Down

0 comments on commit 5865a81

Please sign in to comment.