-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.go
59 lines (52 loc) · 1.36 KB
/
handler.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
57
58
59
package main
import (
"errors"
"github.com/gofiber/fiber/v2"
)
// GET /api/v1/
func rootV1Handler(c *fiber.Ctx) error {
return c.Status(fiber.StatusOK).JSON(map[string]any{
"owner": "M. Iqbal Effendi <iqbaleff214@gmail.com>",
"license": "MIT",
"source": "https://github.com/iqbaleff214/kamus-banjar-api",
"version": "1",
"endpoints": []map[string]string{
{
"path": "/api/v1/alphabets",
"method": "GET",
"description": "Returning a list of alphabet information.",
},
{
"path": "/api/v1/alphabets/{letter}",
"method": "GET",
"description": "Returning a list of Banjar words according to the given letter.",
},
{
"path": "/api/v1/entries/{word}",
"method": "GET",
"description": "Returning the definition and meaning according to the given Banjar word.",
},
},
})
}
// Error handler response
func errorHandler(c *fiber.Ctx, err error) error {
code := fiber.StatusInternalServerError
var e *fiber.Error
if errors.As(err, &e) {
code = e.Code
}
err = c.Status(code).JSON(map[string]any{
"code": code,
"message": e.Message,
"status": "error",
})
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(map[string]any{
"code": fiber.StatusInternalServerError,
"message": "Internal Server Error",
"status": "error",
})
}
return nil
}