github.com/glimps-jbo/go-licenses@v0.0.0-20230908151000-e06d3c113277/licenses/restrictiveness.go (about) 1 package licenses 2 3 type LicenseRestrictiveness string 4 5 const ( 6 RestrictionsShareLicense LicenseRestrictiveness = "ShareLicense" 7 RestrictionsShareCode LicenseRestrictiveness = "ShareCode" 8 RestrictionsUnknown LicenseRestrictiveness = "Unknown" 9 RestrictionsNotAllowed LicenseRestrictiveness = "NotAllowed" 10 ) 11 12 func LicenseTypeRestrictiveness(licenseTypes ...Type) LicenseRestrictiveness { 13 if len(licenseTypes) == 0 { 14 // No licenses foundm, so we don't know what the restrictions are 15 return RestrictionsUnknown 16 } 17 18 // Find any non-allowed licenses 19 for _, licenseType := range licenseTypes { 20 switch licenseType { 21 case Notice, Permissive, Unencumbered, 22 Restricted, Reciprocal, 23 Unknown: 24 // these are allowed/ handled by following logic 25 default: 26 return RestrictionsNotAllowed 27 } 28 } 29 30 // Find unknown licenses 31 for _, licenseType := range licenseTypes { 32 switch licenseType { 33 case Unknown: 34 return RestrictionsUnknown 35 } 36 } 37 38 // Find any licenses that require sharing code 39 for _, licenseType := range licenseTypes { 40 switch licenseType { 41 case Restricted, Reciprocal: 42 return RestrictionsShareCode 43 } 44 } 45 46 // Find any licenses that require sharing license 47 for _, licenseType := range licenseTypes { 48 switch licenseType { 49 case Notice, Permissive, Unencumbered: 50 return RestrictionsShareLicense 51 } 52 } 53 54 panic("unreachable") 55 }