func LanguageByFilename(filename string) string {
	if l := filenames[filename]; len(l) == 1 {
		return l[0]
	}
	ext := filepath.Ext(filename)
	if ext != "" {
		if l := extensions[ext]; len(l) == 1 {
			return l[0]
		}
	}
	return ""
}
Attempts to determine the language of a source file based solely on
common naming conventions and file extensions
from the languages.yml file provided by https://github.com/github/linguist

Returns the empty string in ambiguous or unrecognized cases.
package linguist
import (
	"bufio"
	"bytes"
	"log"
	"path/filepath"
	"regexp"
	"gopkg.in/yaml.v1"
)
var (
	extensions   = map[string][]string{}
	filenames    = map[string][]string{}
	interpreters = map[string][]string{}
	colors       = map[string]string{}
	shebangRE       = regexp.MustCompile(`^#!\s*(\S+)(?:\s+(\S+))?.*`)
	scriptVersionRE = regexp.MustCompile(`((?:\d+\.?)+)`)
)
func init() {
	type language struct {
		Extensions   []string `yaml:"extensions,omitempty"`
		Filenames    []string `yaml:"filenames,omitempty"`
		Interpreters []string `yaml:"interpreters,omitempty"`
		Color        string   `yaml:"color,omitempty"`
	}
	languages := map[string]*language{}
	bytes := []byte(files["data/languages.yml"])
	if err := yaml.Unmarshal(bytes, languages); err != nil {
		log.Fatal(err)
	}
	for n, l := range languages {
		for _, e := range l.Extensions {
			extensions[e] = append(extensions[e], n)
		}
		for _, f := range l.Filenames {
			filenames[f] = append(filenames[f], n)
		}
		for _, i := range l.Interpreters {
			interpreters[i] = append(interpreters[i], n)
		}
		colors[n] = l.Color
	}
}
func LanguageColor(language string) string {
	if c, ok := colors[language]; ok {
		return c
	}
	return ""
}