navid/veinsforge / bc4e645857484ed3c16dd0b284a930b0e61c517ae435c02c9875c2a6e85b6e31 / 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
}