-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.go
65 lines (54 loc) · 1.54 KB
/
handlers.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
60
61
62
63
64
65
package main
import (
"context"
"net/url"
"prox/pgsql"
"time"
"github.com/gofiber/fiber/v2"
)
const (
TELEGRAM = "telegram"
SLACK = "slack"
MSTEAM = "msteam"
LINE = "line"
LINENOTIFY = "line-notify"
EMAIL = "email"
WEBHOOK = "webhook"
NATIVE = "native"
)
type NotifyPayload struct {
Message string `json:"msg"`
}
func fiberThrowError(c *fiber.Ctx, code int, err error) error {
return c.Status(code).JSON(fiber.Map{"code": code, "error": err.Error()})
}
func handlerPutNotify(ctx context.Context, pgx *pgsql.Client) fiber.Handler {
return func(c *fiber.Ctx) error {
var req *NotifyPayload = &NotifyPayload{
Message: c.Query("msg"),
}
var err error
if req.Message != "" {
if req.Message, err = url.QueryUnescape(req.Message); err != nil {
return fiberThrowError(c, fiber.StatusBadRequest, err)
}
} else {
if err = c.BodyParser(&req); err != nil {
return fiberThrowError(c, fiber.StatusBadRequest, err)
}
}
epochMilliseconds := time.Now().UnixMilli()
// result, err := pgx.DB.ExecContext(ctx, `
// INSERT INTO "notice"."history" () VALUES
// `)
// err = stx.Execute(fmt.Sprintf(`
// INSERT INTO "app"."notice_history" ("notice_room_id", "o_sender", "b_sended")
// VALUES %s;
// `, strings.Join(historyInserted, ",")))
// if db.IsRollback(err, stx) {
// return api.ErrorHandlerThrow(c, fiber.StatusInternalServerError, err)
// }
estimated := time.Now().UnixMilli() - epochMilliseconds
return c.JSON(fiber.Map{"code": fiber.StatusOK, "used": estimated})
}
}