-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (45 loc) · 1.36 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
package main
import (
"log"
"os"
"net/http"
"github.com/deyvisonguilherme/viajar_brasil/controllers"
"github.com/deyvisonguilherme/viajar_brasil/models"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
func init() {
// Conexão com banco de dados
models.InitDB("postgres://developer:colleto@localhost/viajar_brasil?sslmode=disable")
log.SetOutput(os.Stdout)
}
func main() {
// Echo Instance
e := echo.New()
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
//CORS
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{echo.GET, echo.HEAD, echo.PUT, echo.PATCH, echo.POST, echo.DELETE},
}))
// Router => handler
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Olá benvindo a API viaja Brasil!")
})
// Index
e.GET("/locais/:regiao/:categoria", controllers.GetLocais)
e.GET("/pesquisa", controllers.Pesquisar)
// Pages
e.GET("/page", controllers.Page)
e.GET("/page/votar/:usuario/:local/:votacao", controllers.Votar)
e.GET("/page/comentar/:usuarios/:local/:comentario", controllers.Comentar)
// Usuários
e.GET("/user/logar", controllers.Logar)
e.GET("/user/cadastro", controllers.Cadastro)
e.GET("/user/logout", controllers.Logout)
e.GET("/user/dadosuser", controllers.DadosUser)
// Start server
e.Logger.Fatal(e.Start(":1323"))
}