fix formatting

This commit is contained in:
Peter Rounce 2023-02-17 10:51:46 +00:00
parent c54328001f
commit 10f2a756b9

View file

@ -2,8 +2,8 @@ package main
import (
log "github.com/sirupsen/logrus"
"strconv"
"net/http"
"strconv"
)
type card_wipe_info struct {
@ -17,34 +17,34 @@ type card_wipe_info struct {
}
func wipeboltcard(w http.ResponseWriter, r *http.Request) {
if db_get_setting("FUNCTION_INTERNAL_API") != "ENABLE" {
msg := "wipeboltcard: internal API function is not enabled"
log.Debug(msg)
write_error_message(w, msg)
return
}
if db_get_setting("FUNCTION_INTERNAL_API") != "ENABLE" {
msg := "wipeboltcard: internal API function is not enabled"
log.Debug(msg)
write_error_message(w, msg)
return
}
card_name := r.URL.Query().Get("card_name")
// check if card_name has been given
if card_name == "" {
msg := "wipeboltcard: the card name must be set"
log.Warn(msg)
write_error_message(w, msg)
return
msg := "wipeboltcard: the card name must be set"
log.Warn(msg)
write_error_message(w, msg)
return
}
// check if card_name exists
card_count, err := db_get_card_name_count(card_name)
if card_count == 0 {
msg := "the card name does not exist in the database"
log.Warn(msg)
write_error_message(w, msg)
return
}
if card_count == 0 {
msg := "the card name does not exist in the database"
log.Warn(msg)
write_error_message(w, msg)
return
}
// set the card as wiped and disabled, get the keys
@ -56,12 +56,12 @@ func wipeboltcard(w http.ResponseWriter, r *http.Request) {
// log the request
log.WithFields(log.Fields{
"card_name": card_name}).Info("wipeboltcard API request")
log.WithFields(log.Fields{
"card_name": card_name}).Info("wipeboltcard API request")
// generate a response
jsonData := `{"status":"OK",` +
jsonData := `{"status":"OK",` +
`"action": "wipe",` +
`"id": ` + strconv.Itoa(card_wipe_info_values.id) + `,` +
`"k0": "` + card_wipe_info_values.k0 + `",` +
@ -72,12 +72,12 @@ func wipeboltcard(w http.ResponseWriter, r *http.Request) {
`"uid": "` + card_wipe_info_values.uid + `",` +
`"version": 1}`
// log the response
// log the response
log.WithFields(log.Fields{
"card_name": card_name, "response": jsonData}).Info("wipeboltcard API response")
log.WithFields(log.Fields{
"card_name": card_name, "response": jsonData}).Info("wipeboltcard API response")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte(jsonData))
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte(jsonData))
}