jokes-bapak2/api/app/v1/app.go

41 lines
721 B
Go
Raw Normal View History

2021-07-09 12:13:19 +00:00
package v1
import (
"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"
"log"
2021-07-14 18:17:01 +00:00
2021-07-09 12:13:19 +00:00
"github.com/gofiber/fiber/v2"
gocache "github.com/patrickmn/go-cache"
2021-07-09 12:13:19 +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,
})
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
}