You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use govalidator and it always returns error even if i send the correct data, may i'm doing it wrong because this is my first time using this package.
package notifier
import (
"encoding/json"
"net/http"
"github.com/thedevsaddam/govalidator"
)
// Payload is request data structure expected
type Payload struct {
TransactionReference string `json:"transactionReference"`
Timestamp string `json:"timestamp"`
ItemID string `json:"itemId"`
AmountPaid govalidator.Int `json:"amountPaid"`
Status string `json:"status"`
}
type res struct {
Message string `json:"message"`
Data *Payload
}
// UpdatePayment Receives payment details and sends to accounting API
func UpdatePayment(w http.ResponseWriter, r *http.Request) {
p := new(Payload)
opts := govalidator.Options{
Request: r,
Data: &p,
Rules: rules,
RequiredDefault: true,
}
req := govalidator.New(opts)
e := req.Validate()
if len(e) > 0 {
validationErr := map[string]interface{}{"data": e, "status": "error"}
json.NewEncoder(w).Encode(validationErr)
return
}
retMsg := &res{
Message: "Payment notification recieved",
Data: p,
}
json.NewEncoder(w).Encode(retMsg)
}
I'm trying to use govalidator and it always returns error even if i send the correct data, may i'm doing it wrong because this is my first time using this package.
second file valitadions.go
The text was updated successfully, but these errors were encountered: