-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
93 lines (73 loc) · 1.84 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"log"
"net/http"
database "go.demo/db"
"go.demo/routes"
"google.golang.org/api/iterator"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/mvc"
)
type PingResponse struct {
Message string `json:"message"`
Items []map[string]interface{} `json:"items"`
}
func main() {
app := iris.New()
// app.Logger().SetLevel("debug")
client, fbCtx := database.Firebase()
defer client.Close()
// db := database.InitializeDB()
ent, entCtx := database.Ent()
app.RegisterDependency(ent)
defer ent.Close()
redis := database.Redis()
app.RegisterDependency(redis)
defer redis.Close()
es, _ := database.Elasticsearch()
app.RegisterDependency(es)
// Auth Routes
authRoutes := app.Party("auth")
mvc.Configure(authRoutes, routes.AuthRouter)
// Member Routes
memberRoutes := app.Party("members")
// memberRoutes.Use(middleware.AuthMiddleware)
mvc.Configure(memberRoutes, routes.MemberRouter)
app.Get("ping", func(ctx iris.Context) {
var items []map[string]interface{}
documents := client.Collection("attachments").Limit(10).Documents(fbCtx)
for {
doc, err := documents.Next()
if err == iterator.Done {
break
}
if err == nil {
items = append(items, doc.Data())
}
}
res := PingResponse{
Message: "pong",
Items: items,
}
ctx.JSON(res)
})
app.Get("db", func(ctx iris.Context) {
// var members []models.Member
// db.Debug().Model(&models.Member{}).Find(&members)
members, err := ent.Debug().Member.Query().Limit(10).All(entCtx)
if err != nil {
log.Fatal(err)
}
ctx.JSON(iris.Map{
"status": http.StatusOK,
"items": members,
})
})
// Listens and serves incoming http requests
// on http://localhost:8080.
app.Listen(":8080")
}
func DemoMiddleware(ctx iris.Context) {
ctx.Application().Logger().Infof("Runs before %s", ctx.Path())
ctx.Next()
}