-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (43 loc) · 1.2 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
package main
import (
"fmt"
"log"
"net/http"
"os"
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/limiter"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/joho/godotenv"
"github.com/kamva/mgm/v3"
"go.mongodb.org/mongo-driver/mongo/options"
"FullStackReview/api/controllers"
)
func main(){
godotenv.Load()
app := fiber.New()
err := mgm.SetDefaultConfig(nil, "UserTweeds", options.Client().ApplyURI(os.Getenv("MONGO_URI")))
tweedController := controllers.TweedController{}
requests := 30
if err != nil{
log.Fatal(err)
}
app.Use(cors.New())
app.Use(logger.New())
app.Use(limiter.New(limiter.Config{
Max: requests,
Expiration: 24 * time.Hour,
LimitReached: func(c *fiber.Ctx) error {
return c.Status(http.StatusBadRequest).JSON(fiber.Map{
"message": fmt.Sprintf("You reached your limit of %d tweeds per day. Come back tomorrow!", requests),
})
},
}))
tweedController.Init()
app.Mount("/api/v1/tweeds", tweedController.Router)
app.Get("/", func(c *fiber.Ctx) error {
return c.JSON(fiber.Map{"message": "hello world"})
})
app.Listen(fmt.Sprintf(":%s", os.Getenv("PORT")))
}