github.com/Financial-Times/publish-availability-monitor@v1.12.0/content/genericContent.go (about)

     1  package content
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/Financial-Times/go-logger/v2"
     7  	uuidutils "github.com/Financial-Times/uuid-utils-go"
     8  )
     9  
    10  type GenericContent struct {
    11  	UUID          string `json:"uuid"`
    12  	Type          string `json:"-"` //This field is for internal application usage
    13  	BinaryContent []byte `json:"-"` //This field is for internal application usage
    14  	Deleted       bool   `json:"deleted,omitempty"`
    15  }
    16  
    17  func (gc GenericContent) Initialize(binaryContent []byte) Content {
    18  	gc.BinaryContent = binaryContent
    19  	return gc
    20  }
    21  
    22  func (gc GenericContent) Validate(externalValidationEndpoint, tid, username, password string, log *logger.UPPLogger) ValidationResponse {
    23  	if uuidutils.ValidateUUID(gc.GetUUID()) != nil {
    24  		log.WithUUID(gc.GetUUID()).Warn("Generic content UUID is invalid")
    25  		return ValidationResponse{IsValid: false, IsMarkedDeleted: gc.isMarkedDeleted()}
    26  	}
    27  
    28  	param := validationParam{
    29  		binaryContent:    gc.BinaryContent,
    30  		validationURL:    externalValidationEndpoint,
    31  		username:         username,
    32  		password:         password,
    33  		tid:              tid,
    34  		uuid:             gc.GetUUID(),
    35  		contentType:      gc.GetType(),
    36  		isGenericPublish: true,
    37  	}
    38  
    39  	return doExternalValidation(
    40  		param,
    41  		gc.isValid,
    42  		gc.isMarkedDeleted,
    43  		log,
    44  	)
    45  }
    46  
    47  func (gc GenericContent) GetType() string {
    48  	return gc.Type
    49  }
    50  
    51  func (gc GenericContent) GetUUID() string {
    52  	return gc.UUID
    53  }
    54  
    55  func (gc GenericContent) isValid(status int) bool {
    56  	return status == http.StatusOK
    57  }
    58  
    59  func (gc GenericContent) isMarkedDeleted(status ...int) bool {
    60  	return gc.Deleted
    61  }