-
Notifications
You must be signed in to change notification settings - Fork 1
/
draft_content_validator_resolver.go
36 lines (29 loc) · 1.27 KB
/
draft_content_validator_resolver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package content
import (
"fmt"
)
// DraftContentValidatorResolver manages the validators available for a given originId/content-type pair.
type DraftContentValidatorResolver interface {
// ValidatorForContentType Resolves and returns a DraftContentValidator implementation if present.
ValidatorForContentType(contentType string) (DraftContentValidator, error)
}
// NewDraftContentValidatorResolver returns a DraftContentValidatorResolver implementation
func NewDraftContentValidatorResolver(contentTypeToValidator map[string]DraftContentValidator) DraftContentValidatorResolver {
return &draftContentValidatorResolver{contentTypeToValidator}
}
type draftContentValidatorResolver struct {
contentTypeToValidator map[string]DraftContentValidator
}
// ValidatorForContentType implementation checks the content-type validation for a validator resolution.
func (resolver *draftContentValidatorResolver) ValidatorForContentType(contentType string) (DraftContentValidator, error) {
contentType = stripMediaTypeParameters(contentType)
validator, found := resolver.contentTypeToValidator[contentType]
if !found {
return nil, fmt.Errorf(
"no validator configured for contentType: %s\ncontentTypeMap: %v",
contentType,
resolver.contentTypeToValidator,
)
}
return validator, nil
}