-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (41 loc) · 1.02 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
54
55
56
package main
import (
"embed"
"log"
"os"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/iqbaleff214/kamus-banjar-api/domain/dictionary"
)
//go:embed data/*.json
var data embed.FS
func main() {
app := setup()
port := os.Getenv("PORT")
if port == "" {
port = ":8001"
}
log.Fatal(app.Listen(port))
}
func setup() *fiber.App {
dictionaryRepository := dictionary.NewRepository(data)
dictionaryService := dictionary.NewService(dictionaryRepository)
dictionaryHandler := dictionary.NewHandler(dictionaryService)
// app setup
app := fiber.New(config())
app.Use(cors.New())
// api route
api := app.Group("/api")
// api v1
api.Get("/v1", rootV1Handler)
api.Get("/v1/alphabets", dictionaryHandler.GetAlphabets)
api.Get("/v1/alphabets/:letter", dictionaryHandler.GetWordsByAlphabet)
api.Get("/v1/entries/:word", dictionaryHandler.GetWord)
return app
}
func config() fiber.Config {
return fiber.Config{
AppName: "Kamus Banjar API",
ErrorHandler: errorHandler,
}
}