github.com/mayur-tolexo/godep@v0.0.0-20170205210856-a9cd0561f946/license.go (about)

     1  package main
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  // LicenseFilePrefix is a list of filename prefixes that indicate it
     8  //  might contain a software license
     9  var LicenseFilePrefix = []string{
    10  	"licence", // UK spelling
    11  	"license", // US spelling
    12  	"copying",
    13  	"unlicense",
    14  	"copyright",
    15  	"copyleft",
    16  	"authors",
    17  	"contributors",
    18  }
    19  
    20  // LegalFileSubstring are substrings that indicate the file is likely
    21  // to contain some type of legal declaration.  "legal" is often used
    22  // that it might moved to LicenseFilePrefix
    23  var LegalFileSubstring = []string{
    24  	"legal",
    25  	"notice",
    26  	"disclaimer",
    27  	"patent",
    28  	"third-party",
    29  	"thirdparty",
    30  }
    31  
    32  // IsLicenseFile returns true if the filename might be contain a
    33  // software license
    34  func IsLicenseFile(filename string) bool {
    35  	lowerfile := strings.ToLower(filename)
    36  	for _, prefix := range LicenseFilePrefix {
    37  		if strings.HasPrefix(lowerfile, prefix) {
    38  			return true
    39  		}
    40  	}
    41  	return false
    42  }
    43  
    44  // IsLegalFile returns true if the file is likely to contain some type
    45  // of of legal declaration or licensing information
    46  func IsLegalFile(filename string) bool {
    47  	lowerfile := strings.ToLower(filename)
    48  	for _, prefix := range LicenseFilePrefix {
    49  		if strings.HasPrefix(lowerfile, prefix) {
    50  			return true
    51  		}
    52  	}
    53  	for _, substring := range LegalFileSubstring {
    54  		if strings.Index(lowerfile, substring) != -1 {
    55  			return true
    56  		}
    57  	}
    58  	return false
    59  }