-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (35 loc) · 909 Bytes
/
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
package main
import (
"context"
"fmt"
"log"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
firebase "firebase.google.com/go"
"github.com/ihummer/go-firebase/handlers"
"google.golang.org/api/option"
)
func main() {
// Initialize firebase
opt := option.WithCredentialsFile("firebase-service-account.json")
app, err := firebase.NewApp(context.Background(), nil, opt)
if err != nil {
log.Fatal(err)
}
// Initialize Firestore database
db, err := app.Firestore(context.Background())
if err != nil {
log.Fatal(err)
}
defer db.Close()
// Creating Echo instance
e := echo.New()
// Register middleware for error handling
e.HTTPErrorHandler = handlers.ErrorHandler
e.Use(middleware.Recover())
// Creating petition handlers
handlers.RegisterHandlers(e, db)
// New http server
fmt.Println("Starting server on port 8080...")
log.Fatal(e.Start(":8080"))
}