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