github.com/haalcala/mattermost-server-change-repo@v0.0.0-20210713015153-16753fbeee5f/services/docextractor/combine.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package docextractor 5 6 import ( 7 "io" 8 9 "github.com/mattermost/mattermost-server/v5/mlog" 10 ) 11 12 type combineExtractor struct { 13 SubExtractors []Extractor 14 } 15 16 func (ce *combineExtractor) Add(extractor Extractor) { 17 ce.SubExtractors = append(ce.SubExtractors, extractor) 18 } 19 20 func (ce *combineExtractor) Match(filename string) bool { 21 for _, extractor := range ce.SubExtractors { 22 if extractor.Match(filename) { 23 return true 24 } 25 } 26 return false 27 } 28 29 func (ce *combineExtractor) Extract(filename string, r io.Reader) (string, error) { 30 for _, extractor := range ce.SubExtractors { 31 if extractor.Match(filename) { 32 text, err := extractor.Extract(filename, r) 33 if err != nil { 34 mlog.Warn("unable to extract file content", mlog.Err(err)) 35 continue 36 } 37 return text, nil 38 } 39 } 40 return "", nil 41 }