github.com/shoshinnikita/budget-manager@v0.7.1-0.20220131195411-8c46ff1c6778/internal/web/api/models/utils.go (about)

     1  package models
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/ShoshinNikita/budget-manager/internal/pkg/errors"
     7  )
     8  
     9  func sanitizeString(s *string) {
    10  	if s == nil {
    11  		return
    12  	}
    13  
    14  	*s = strings.TrimSpace(*s)
    15  }
    16  
    17  // emptyFieldError must be used when field of type string is empty
    18  func emptyFieldError(fieldName string) error {
    19  	return errors.Errorf("%s can't be empty", fieldName)
    20  }
    21  
    22  // emptyOrZeroFieldError must be used when field of type int or float is empty or zero
    23  func emptyOrZeroFieldError(fieldName string) error {
    24  	return errors.Errorf("%s can't be empty or zero", fieldName)
    25  }
    26  
    27  // notPositiveFieldError must be used when field is negative or zero (<= 0)
    28  func notPositiveFieldError(fieldName string) error {
    29  	return errors.Errorf("%s must be greater than zero", fieldName)
    30  }
    31  
    32  // negativeFieldError must be used when field is negative (< 0)
    33  func negativeFieldError(fieldName string) error {
    34  	return errors.Errorf("%s must be greater or equal to zero", fieldName)
    35  }