Update GetLanguageID to return a found boolean per code review

This commit is contained in:
Luke Francl
2021-04-22 16:55:42 -07:00
parent eb043e80a8
commit cabfdaffc0
2 changed files with 16 additions and 12 deletions

View File

@ -491,11 +491,13 @@ func GetLanguageExtensions(language string) []string {
}
// GetLanguageID returns the ID for the language. IDs are assigned by GitHub.
// The input must be the canonical language name. Aliases are not supported.
//
// NOTE: The zero value (0) is a valid language ID, so this API has no way to
// distinguish an invalid language name and a match on the language with ID 0.
func GetLanguageID(language string) int {
return data.IDByLanguage[language]
// NOTE: The zero value (0) is a valid language ID, so this API mimics the Go
// map API. Use the second return value to check if the language was found.
func GetLanguageID(language string) (int, bool) {
id, ok := data.IDByLanguage[language]
return id, ok
}
// Type represent language's type. Either data, programming, markup, prose, or unknown.