-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (38 loc) · 990 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"log"
"os"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/iqbaleff214/kamus-banjar-api/domain/dictionary"
)
func main() {
app := setup()
port := os.Getenv("PORT")
if port == "" {
port = ":8001"
}
log.Fatal(app.Listen(port))
}
func setup() *fiber.App {
dictionaryRepository := dictionary.NewRepository()
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,
}
}