Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go error: unexpected Nul in input

Tags:

go

I just installed the go.msi in C:/Go. And I set my Path(C:\Go\bin) and GOPATH(E:\code\go).But when I try to run "go run test.go" I get the following error: test.go:2:8: read C:\Go\src\fmt\export_test.go: unexpected NUL in input package main imports runtime: read C:\Go\src\runtime\export_unix_test.go: unexpected NUL in input
I can not open these files. The code i have is:

    package main

    import "fmt"

    func main()  {
        fmt.Println("Something")
    }

The path of the test.go file is E:\code\go\test.go When i run go env i get:

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=E:\code\go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config

the output of go version is: go version go1.9.2 windows/amd64

like image 560
Traqn Raykovski Avatar asked Nov 17 '17 09:11

Traqn Raykovski


2 Answers

I had the same problem with golang 1.10.0 on Windows 10:
When creating the file to run with echo "my go program" > myProgram.go the wrong encoding was generated: UCS-2 LE BOM.

Converting to UTF-8 resolved the NUL in input.

Looks like it's PowerShell that encodes in Windows-1252 by default (windows system locale), with CMD and PowerShell Core this problem should not happen.

like image 66
Giulio Caccin Avatar answered Nov 20 '22 20:11

Giulio Caccin


You are missing some things in your GOPATH. You need a folder structure like the following:

E:\code\go\src\{repository}\{package}\gofile.go

So for this, you could have it be:

E:\code\go\src\local-only\testing\test.go
like image 38
Jacob Lambert Avatar answered Nov 20 '22 20:11

Jacob Lambert