github.com/SAP/cloud-mta-build-tool@v1.2.27/internal/conttype/process.go (about) 1 package conttype 2 3 import ( 4 "gopkg.in/yaml.v2" 5 6 "github.com/pkg/errors" 7 ) 8 9 // GetContentTypes - gets content types associated with files extensions from the configuration config_type_cgf.yaml 10 func GetContentTypes() (*ContentTypes, error) { 11 contentTypes := ContentTypes{} 12 err := yaml.UnmarshalStrict(ContentTypeConfig, &contentTypes) 13 if err != nil { 14 return &contentTypes, errors.Wrap(err, unmarshalFailed) 15 } 16 return &contentTypes, nil 17 } 18 19 // GetContentType - get content type by file extension 20 func GetContentType(cfg *ContentTypes, extension string) (string, error) { 21 for _, ct := range cfg.ContentTypes { 22 if ct.Extension == extension { 23 return ct.ContentType, nil 24 } 25 } 26 return "", errors.Errorf(ContentTypeUndefinedMsg, extension) 27 }