How to build custom tokenizer?

example

#1

Hello,

I would like to use custom tokenizer with dGraph, but I’m not golang pro user.
When I use docker for building tokenizer in same version of go lang like dGraph uses:

docker run -it --rm -v /dgraph/migration/:/out golang:1.11.1 bash
vim nfd.go
go build -buildmode=plugin -o ./nfd.so ./nfd.go

I end with this errors:

nfd.go:6:8: cannot find package "golang.org/x/text/transform" in any of:
	/usr/local/go/src/golang.org/x/text/transform (from $GOROOT)
	/go/src/golang.org/x/text/transform (from $GOPATH)
nfd.go:7:12: cannot find package "golang.org/x/text/unicode/norm" in any of:
	/usr/local/go/src/golang.org/x/text/unicode/norm (from $GOROOT)
	/go/src/golang.org/x/text/unicode/norm (from $GOPATH)

(Daniel Mai) #2

Have you tried using xgo to build the plugin? With xgo you can run go build with a specific Go version for a specific target arch.

xgo -targets=linux/amd64 -go=1.11.1 -buildmode=plugin -out nfd.so .

#3

Something is missing:

xgo -targets=linux/amd64 -go=1.11.1 -buildmode=plugin -out nfd.so .

Checking docker installation...
Client:
 Version:           18.09.0
 API version:       1.39
 Go version:        go1.10.4
 Git commit:        4d60db4
 Built:             Wed Nov  7 00:49:01 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.0
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.4
  Git commit:       4d60db4
  Built:            Wed Nov  7 00:16:44 2018
  OS/Arch:          linux/amd64
  Experimental:     false

Checking for required docker image karalabe/xgo-1.11.1... found.
Cross compiling ....
Building locally ....
Compiling for linux/amd64...
can't load package: package .: no Go files in /
2018/12/21 20:22:45 Failed to cross compile package: exit status 1.
ls -l .

total 4
-rw-r--r-- 1 root root 785 Dec 21 20:09 nfd.go

(Daniel Mai) #4

Is this done somewhere within your $GOPATH?