forked from boltcard/boltcard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetboltcard.go
47 lines (38 loc) · 1.24 KB
/
getboltcard.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
package internalapi
import (
"net/http"
"strconv"
"github.com/boltcard/boltcard/db"
"github.com/boltcard/boltcard/resp_err"
log "github.com/sirupsen/logrus"
)
func Getboltcard(w http.ResponseWriter, r *http.Request) {
if db.Get_setting("FUNCTION_INTERNAL_API") != "ENABLE" {
msg := "getboltcard: internal API function is not enabled"
log.Debug(msg)
resp_err.Write_message(w, msg)
return
}
card_name := r.URL.Query().Get("card_name")
// log the request
log.WithFields(log.Fields{
"card_name": card_name}).Info("getboltcard API request")
// get the card record
c, err := db.Get_card_from_card_name(card_name)
if err != nil {
msg := "getboltcard: a non-wiped card with the card_name does not exist in the database"
log.Warn(msg)
resp_err.Write_message(w, msg)
return
}
jsonData := []byte(`{"status":"OK",` +
`"uid": "` + c.Db_uid + `",` +
`"lnurlw_enable": "` + c.Lnurlw_enable + `",` +
`"tx_limit_sats": "` + strconv.Itoa(c.Tx_limit_sats) + `",` +
`"day_limit_sats": "` + strconv.Itoa(c.Day_limit_sats) + `", ` +
`"pin_enable": "` + c.Pin_enable + `", ` +
`"pin_limit_sats": "` + strconv.Itoa(c.Pin_limit_sats) + `"}`)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(jsonData)
}