How to validate slice MinLen #33
-
|
How to validate there must be a minimum 1 LineItem exists. I could not find any thing like this in Readme.md type SubscriptionLineItem struct {
ItemPriceID string
Quantity int
}
type CreateSubscriptionInput struct {
UserID string
LineItems []SubscriptionLineItem
} |
Beta Was this translation helpful? Give feedback.
Answered by
carlosforero
Jun 26, 2025
Replies: 1 comment
-
|
You can validate that a slice has a minimum length using the val := v.Is(
v.Int(len(input.LineItems), "line_items").GreaterThan(0, "must have at least 1 line item")
)This is related to #34 I'm closing this discussion, but if you have any feedback, don't hesitate to send it! |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
carlosforero
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can validate that a slice has a minimum length using the
Intvalidator withGreaterThan():This is related to #34
I'm closing this discussion, but if you have any feedback, don't hesitate to send it!