navid/veinsforge / ff3477091cc92ed92cd07ce1e14ccc09435b1ea57933a80577d80dc351eb838a / internal/web/license.go
license.go
← internal/web · 773 bytes · raw · download
package web
import (
"strings"
"github.com/google/licensecheck"
)
func firstLicense(files []string) string {
for _, want := range []string{
"license", "licence", "license.md", "licence.md", "license.txt", "licence.txt",
"copying", "copying.md", "copying.txt", "copyright", "copyright.md", "copyright.txt",
} {
for _, file := range files {
if !strings.Contains(file, "/") && strings.EqualFold(file, want) {
return file
}
}
}
return ""
}
func licenseName(data []byte) string {
coverage := licensecheck.Scan(data)
best := ""
bestLength := 0
for _, match := range coverage.Match {
if match.ID == "" {
continue
}
if length := match.End - match.Start; length > bestLength {
best = match.ID
bestLength = length
}
}
return best
}