Go port of github linguist.
Linguist is a package that detects the language through the files or directories.
- To install linguist package, you need to install Go and set your Go workspace first.
go get -u github.com/ihangji/linguist
- Import linguist package.
import github.com/ihangji/linguist
Detecting the language through the files.
package main
import github.com/ihangji/linguist
func main() {
appPythonfile := filepath.Join("Testdata", "app-python", "app.py")
l, err := ProcessFile(appPythonfile)
if err != nil {
log.Fatalln(err)
}
fmt.Printf("language: %s", l)
// Output: language: Python
}
Detecting the language list of the directory.
package main
import github.com/ihangji/linguist
func main() {
var sortResult sortableResult
appPath := filepath.Join("Testdata", "app-python")
lanuages, err := ProcessDir(appPath)
if err != nil {
log.Fatalln(err)
}
sortResult = lanuages
sort.Sort(sortResult)
for _, i := range sortResult {
fmt.Printf("language: %s, Percent: %f, Color: %s\n",
i.Language, i.Percent, i.Color)
}
}
Welcome to contribute your code.
To update to the latest version of linguist, run
git clone https://github.com/github/linguist data/linguist
go generate .
go generate ./data
rm -rf data/linguist