Skip to content

Commit

Permalink
Merge pull request #88 from rezakhademix/feat-add-example-to-default-…
Browse files Browse the repository at this point in the history
…rule-comments

feat: added usage example to default rule comments
  • Loading branch information
rezakhademix authored Apr 10, 2024
2 parents 6e0f510 + 7e75e80 commit 74603f0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions default.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ package govalidator

// DefaultInt sets a default value for any pointer to an int thats is passed
// if value does not exists, then set the default specified as the new value.
//
// Example:
//
// v := validator.New()
// var ZeroKelvin int64
// v.DefaultInt(&s, -273)
func (v *Validator) DefaultInt(i *int, val int) *Validator {
if i == nil || *i == 0 {
*i = val
Expand All @@ -12,6 +18,12 @@ func (v *Validator) DefaultInt(i *int, val int) *Validator {

// DefaultFloat sets a default value for any pointer to an float thats is passed
// if value does not exists, then set the default specified as the new value.
//
// Example:
//
// v := validator.New()
// var f float64
// v.DefaultFloat(&f, 3.14)
func (v *Validator) DefaultFloat(f *float64, val float64) *Validator {
if f == nil || *f == 0 {
*f = val
Expand All @@ -22,6 +34,12 @@ func (v *Validator) DefaultFloat(f *float64, val float64) *Validator {

// DefaultString sets a default value for a pointer to a string.
// if value does not exists, then set the default specified as the new value.
//
// Example:
//
// v := validator.New()
// var lang string
// v.DefaultString(&s, "persian")
func (v *Validator) DefaultString(s *string, val string) *Validator {
if s == nil || *s == "" {
*s = val
Expand Down

0 comments on commit 74603f0

Please sign in to comment.