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