-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.go
More file actions
39 lines (34 loc) · 780 Bytes
/
data.go
File metadata and controls
39 lines (34 loc) · 780 Bytes
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
37
38
39
package licensematcher
import (
"bufio"
"embed"
"strings"
)
//go:embed license-data/*
var embeddedLicenseData embed.FS
type licSample struct {
ID string
Texts []string
}
var loadedLicenses []licSample
func init() {
entries, _ := embeddedLicenseData.ReadDir("license-data")
for _, entry := range entries {
f, _ := embeddedLicenseData.Open("license-data/" + entry.Name())
scanner := bufio.NewScanner(f)
scanner.Split(bufio.ScanLines)
scanner.Buffer(nil, 64*1024)
var lic = licSample{
ID: strings.TrimSuffix(entry.Name(), ".txt"),
}
for scanner.Scan() {
var txt = strings.TrimSpace(scanner.Text())
if len(txt) == 0 {
continue
}
lic.Texts = append(lic.Texts, txt)
}
_ = f.Close()
loadedLicenses = append(loadedLicenses, lic)
}
}