2021-07-09 12:13:19 +00:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2021-07-17 09:06:33 +00:00
|
|
|
"jokes-bapak2-api/app/v1/core"
|
|
|
|
"jokes-bapak2-api/app/v1/platform/cache"
|
|
|
|
"jokes-bapak2-api/app/v1/platform/database"
|
2021-07-14 18:17:01 +00:00
|
|
|
"jokes-bapak2-api/app/v1/routes"
|
2021-07-17 09:06:33 +00:00
|
|
|
"log"
|
2021-07-14 18:17:01 +00:00
|
|
|
|
2021-07-09 12:13:19 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
2021-07-17 09:06:33 +00:00
|
|
|
gocache "github.com/patrickmn/go-cache"
|
2021-07-09 12:13:19 +00:00
|
|
|
)
|
|
|
|
|
2021-07-17 09:06:33 +00:00
|
|
|
var memory = cache.InMemory()
|
|
|
|
var db = database.New()
|
|
|
|
|
2021-07-09 12:13:19 +00:00
|
|
|
func New() *fiber.App {
|
|
|
|
app := fiber.New(fiber.Config{
|
|
|
|
DisableKeepalive: true,
|
|
|
|
CaseSensitive: true,
|
|
|
|
})
|
|
|
|
|
2021-07-17 09:06:33 +00:00
|
|
|
checkCache := core.CheckJokesCache(memory)
|
|
|
|
|
|
|
|
if !checkCache {
|
|
|
|
jokes, err := core.GetAllJSONJokes(db)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
memory.Set("jokes", jokes, gocache.NoExpiration)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-09 12:13:19 +00:00
|
|
|
routes.Health(app)
|
|
|
|
routes.Joke(app)
|
|
|
|
|
|
|
|
return app
|
|
|
|
}
|