Skip to content

Commit

Permalink
check min max
Browse files Browse the repository at this point in the history
  • Loading branch information
cadyrov committed Apr 23, 2020
1 parent 8e859be commit d7770ff
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion minmax.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package validation
import (
"errors"
"fmt"
"mime/multipart"
"reflect"
"time"
)
Expand Down Expand Up @@ -108,7 +109,21 @@ func (r *ThresholdRule) Validate(value interface{}) ExternalError {
}

default:
return NewExternalError(fmt.Errorf("type not supported: %v", rv.Type()), 1000)
sliceHeaders, ok := value.([]multipart.FileHeader)
if !ok {
return NewExternalError(fmt.Errorf("type not supported: %v", rv.Type()), 1000)
}
var sum int64
for i := range sliceHeaders {
sum += sliceHeaders[i].Size
}
v, err := ToUint(sum)
if err != nil {
return NewExternalError(err, 1000)
}
if r.compareUint(rv.Uint(), v) {
return nil
}
}

return NewExternalError(errors.New(r.message), 1000)
Expand Down

0 comments on commit d7770ff

Please sign in to comment.