-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
65 lines (53 loc) · 1.39 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"pokemon-golang/adapter"
"pokemon-golang/core/ports"
"pokemon-golang/core/usecases"
_ "pokemon-golang/docs"
"pokemon-golang/helpers"
"time"
)
// @title Pokemon GO lang
// @version 1.0
// @description Example of ports and adapters architecture with Golang.
// @termsOfService https://google.com
// @contact.name Tardelli Moura
// @contact.url https://google.com
// @contact.email [email protected]
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost:8080
// @BasePath /api/v1
func main() {
useCasePokemon := usecases.NewPokemonUseCase()
// up gin server in a new Goroutine
go runWithGinHttp(useCasePokemon)
// this delay is for gin server up
time.Sleep(2 * time.Second)
runWithTerminalScan(useCasePokemon)
}
func runWithGinHttp(useCasePokemon ports.PokemonUseCase) {
g := adapter.SetupRouter(useCasePokemon)
err := g.Run(":8080")
if err != nil {
panic(err)
}
}
func runWithTerminalScan(useCase ports.PokemonUseCase) {
scan := adapter.NewScan()
operationsFromScan, err := scan.ScanOperations()
if err != nil {
panic(err)
}
//mudar depois
print(operationsFromScan)
feeResults, err := useCase.GetAllPokemons()
if err != nil {
panic(err)
}
fmt.Println("\n[SCAN] Result: ")
helpers.PrettyPrint(&feeResults)
fmt.Print("\n")
runWithTerminalScan(useCase)
}