-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
38 lines (30 loc) · 863 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
package main
import (
"context"
"log"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"github.com/gabrielmvas/user-api-golang/http"
"github.com/gabrielmvas/user-api-golang/repository"
)
func main() {
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://127.0.0.1:27017"))
if err != nil {
log.Fatal(err)
}
if err := client.Connect(context.TODO()); err != nil {
log.Fatal(err)
}
repository := repository.NewRepository(client.Database("users"))
server := http.NewServer(repository)
router := gin.Default()
{
router.GET("/users/:email", server.GetUser)
router.GET("/users", server.GetUsers)
router.POST("/users", server.CreateUser)
router.PUT("/users/:email", server.UpdateUser)
router.DELETE("/users/:email", server.DeleteUser)
}
router.Run(":9090")
}