Skip to content
Snippets Groups Projects

Initial implementation of an elasticsearch indexer in Go

Merged Nick Thomas requested to merge 1-initial-implementation into master
All threads resolved!
6 files
+ 4150
5
Compare changes
  • Side-by-side
  • Inline
Files
6
+ 16
5
@@ -6,6 +6,8 @@ import (
"io/ioutil"
"srcd.works/go-git.v4/plumbing/object"
"gitlab.com/gitlab-org/es-git-go/linguist"
)
var (
@@ -93,17 +95,26 @@ func (i *Indexer) BuildBlob(file *object.File, commitSHA string) (*Blob, error)
Content: content,
Path: file.Name,
Filename: file.Name,
Language: DetectLanguage(b),
Language: DetectLanguage(file.Name, b),
}, nil
}
// FIXME: implement this
func DetectLanguage(data []byte) string {
// DetectLanguage returns a string describing the language of the file. This is
// programming language, rather than natural language.
//
// If no language is detected, "Text" is returned.
func DetectLanguage(filename string, data []byte) string {
lang := linguist.DetectLanguage(filename, data)
if lang != nil {
return lang.Name
}
return "Text"
}
// Check whether the passed-in data contains a NUL byte. Only scan the start of
// large blobs. This is the same test performed by git to check text/binary
// DetectBinary checks whether the passed-in data contains a NUL byte. Only scan
// the start of large blobs. This is the same test performed by git to check
// text/binary
func DetectBinary(data []byte) bool {
searchLimit := binarySearchLimit
if len(data) < searchLimit {
Loading