github.com/k0marov/go-socnet@v0.0.0-20220715154813-90d07867c782/features/comments/domain/validators/validators.go (about)

     1  package validators
     2  
     3  import (
     4  	"github.com/k0marov/go-socnet/core/general/client_errors"
     5  	"github.com/k0marov/go-socnet/features/comments/domain/values"
     6  )
     7  
     8  type CommentValidator func(values.NewCommentValue) (client_errors.ClientError, bool)
     9  
    10  const MaxTextLength = 255
    11  
    12  func NewCommentValidator() CommentValidator {
    13  	return func(newComment values.NewCommentValue) (client_errors.ClientError, bool) {
    14  		if newComment.Text == "" {
    15  			return client_errors.EmptyText, false
    16  		}
    17  		if len(newComment.Text) > MaxTextLength {
    18  			return client_errors.TextTooLong, false
    19  		}
    20  		return client_errors.ClientError{}, true
    21  	}
    22  }