8000 GitHub - ihangji/linguist: Go port of github linguist.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ihangji/linguist

Repository files navigation

linguist

Go Report Card GoDoc

Go port of github linguist.

Overview

Linguist is a package that detects the language through the files or directories.

Install

  1. To install linguist package, you need to install Go and set your Go workspace first.
go get -u github.com/ihangji/linguist
  1. Import linguist package.
import github.com/ihangji/linguist

Quick start

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)
    }
}

Contibuting code

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

About

Go port of github linguist.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0