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