github.com/go-email-validator/go-email-validator@v0.0.0-20230409163946-b8b9e6a0552e/pkg/presentation/as-email-verifier/gravatar.go (about)

     1  package asemailverifier
     2  
     3  import (
     4  	"github.com/go-email-validator/go-email-validator/pkg/ev"
     5  	"github.com/go-email-validator/go-email-validator/pkg/ev/evmail"
     6  	"github.com/go-email-validator/go-email-validator/pkg/presentation/converter"
     7  )
     8  
     9  // GravatarPresentation is presentation for ev.GravatarValidationResult
    10  type GravatarPresentation struct {
    11  	HasGravatar bool
    12  	GravatarURL string
    13  }
    14  
    15  // GravatarConverter converts ev.ValidationResult in GravatarPresentation
    16  type GravatarConverter struct{}
    17  
    18  // Can ev.ValidationResult be converted in GravatarPresentation
    19  func (GravatarConverter) Can(_ evmail.Address, result ev.ValidationResult, _ converter.Options) bool {
    20  	return result.ValidatorName() == ev.GravatarValidatorName
    21  }
    22  
    23  // Convert ev.ValidationResult in GravatarPresentation
    24  func (GravatarConverter) Convert(_ evmail.Address, result ev.ValidationResult, _ converter.Options) interface{} {
    25  	gravatarResult := result.(ev.GravatarValidationResult)
    26  	presentation := &GravatarPresentation{HasGravatar: gravatarResult.IsValid()}
    27  
    28  	if presentation.HasGravatar {
    29  		presentation.GravatarURL = gravatarResult.URL()
    30  	}
    31  
    32  	return presentation
    33  }