gopkg.in/tools/godep.v60@v60.0.0-20160318205742-530caa84a45c/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 } 17 18 // LegalFileSubstring are substrings that indicate the file is likely 19 // to contain some type of legal declaration. "legal" is often used 20 // that it might moved to LicenseFilePrefix 21 var LegalFileSubstring = []string{ 22 "legal", 23 "notice", 24 "disclaimer", 25 "patent", 26 "third-party", 27 "thirdparty", 28 } 29 30 // IsLicenseFile returns true if the filename might be contain a 31 // software license 32 func IsLicenseFile(filename string) bool { 33 lowerfile := strings.ToLower(filename) 34 for _, prefix := range LicenseFilePrefix { 35 if strings.HasPrefix(lowerfile, prefix) { 36 return true 37 } 38 } 39 return false 40 } 41 42 // IsLegalFile returns true if the file is likely to contain some type 43 // of of legal declaration or licensing information 44 func IsLegalFile(filename string) bool { 45 lowerfile := strings.ToLower(filename) 46 for _, prefix := range LicenseFilePrefix { 47 if strings.HasPrefix(lowerfile, prefix) { 48 return true 49 } 50 } 51 for _, substring := range LegalFileSubstring { 52 if strings.Index(lowerfile, substring) != -1 { 53 return true 54 } 55 } 56 return false 57 }