You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
832 B
33 lines
832 B
3 years ago
|
package metadata
|
||
|
|
||
|
import (
|
||
|
"regexp"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
type processedExtractor struct {
|
||
|
re *regexp.Regexp
|
||
|
cleaner *regexp.Regexp
|
||
|
}
|
||
|
|
||
|
func (e processedExtractor) Matches(line string) bool {
|
||
|
return e.re.MatchString(line)
|
||
|
}
|
||
|
func (e processedExtractor) Extract(metadata *BackupLogMetadata, line string) {
|
||
|
// Sample line: "processed 2 files, 24 B in 0:00"
|
||
|
var processed = BackupLogMetadataProcessed{}
|
||
|
split := strings.Split(line, "in")
|
||
|
processed.Duration = strings.TrimSpace(split[1])
|
||
|
split = strings.Split(split[0], ",")
|
||
|
processed.Files = e.cleaner.ReplaceAllString(split[0], "")
|
||
|
processed.Size = strings.TrimSpace(split[1])
|
||
|
metadata.Processed = processed
|
||
|
}
|
||
|
|
||
|
func NewProcessedExtractor() MetadatExtractor {
|
||
|
return processedExtractor{
|
||
|
regexp.MustCompile(`(?i)^processed \d* files`),
|
||
|
regexp.MustCompile(`(?i)[^\d]`),
|
||
|
}
|
||
|
}
|