[Go 1.13] What to do when unexpected directory layout: appears


 I think this will work.

---

 An error that occurred when I was developing with Go and tried to separate packages using files.
 I solved it for the time being, so I made a note immediately. .. ..


## environment

version go version go1.13.14 linux/amd64 centos 7

Directory structure ./ | |--sample/ | | | |--sample.go | |--main.go


## Actual code


#### **`main.go`**
```go

package main

import "./sample"

func main() {
	a := sample.Foo("test")
	sample.PrintFoo(a)
}

sample.go


package sample

import "fmt"

func Foo(s string) string {
	return "aaa " + s + " bbb"
}

func PrintFoo(s string) {
	fmt.Println(s)
}
[[email protected] ---]# go build -o practice
unexpected directory layout:
        import path: _/develop/go/src/test/marny/sample
        root: /develop/go/src
        dir: /develop/go/src/test/marny/sample
        expand root: /develop/go
        expand dir: /develop/go/src/test/marny/sample
        separator: /

What kind of error is it

The error ʻunexpected directory layout:` seems to be an error that the path of the imported package is not specified.

I myself edited centos7 (vbox) by connecting it to windows with samba, so there was no error in the source code ...

Solution

In my case, ** $ GOPATH ** is specified as / develop / go. According to the GOPATH specifications, I generate bins and srcs and develop Go, but an error occurs here.

The solution is to change import./sample in main.go to the relative path seen from $ GOPATH / src.

Therefore,

main.go


package main

import "test/marny/sample"

func main() {
	a := sample.Foo("test")
	sample.PrintFoo(a)
}

I think this will solve it.

GOPATH is annoying.

Recommended Posts

[Go 1.13] What to do when unexpected directory layout: appears
[openpyxl] What to do when IllegalCharacterError appears in pandas.DataFrame.to_excel
What to do when [Errno 2] No such file or directory appears in Python
What to do when Ubuntu crashes
What to do when "SSL: CERTIFICATE_VERIFY_FAILED _ssl.c: 1056" appears in Python
OSError: [Errno 40] What to do when Message too long appears
What to do when "Invalid HTTP_HOST header" appears in Django
What to do if Insecure Platform Warning appears when running Python
[Memorandum] What to do when a warning appears after executing pip list
What to do when pyinstaller: error: argument --add-binary: invalid add_data_or_binary value: appears
[Docker] What to do when error Couldn't find the binary git appears
What to do when the warning "The environment is in consistent ..." appears in the Anaconda environment
What to do when PermissionError of tempfile.mkstemp occurs
What to do when "TypeError: must be string, not int…" appears when using strptime
What to do when a warning appears around Python integration in Neovim's CheckHealth
What to do when "TypeError: data type not understood" appears in python's numpy.zeros
What I do when imitating embedded go in python
curl: (60) What to do when Issuer certificate is invalid.
What to do when gdal_merge creates a huge file
What to do when raise ValueError, "unsupported hash type"
What to do when "cannot import name xxx" [Python]
What to do when you can't bind CaboCha to Python
[Python] What to do when No module named'pyproj.datadir' appears when Exe is done with PyInstaller
What to do if ENOENT: no such file or directory appears during npm install
What to do when "Type Error: must be _socket.socket, not socket" appears on GAE
[AWS] What to do when you want to pip with Lambda
What to do when Japanese is not displayed on matplotlib
What to do when PyCharm font is strange or garbled
What to do when a Remove Error occurs when updating conda
What to do when Unalignable boolean Series provided as indexer
What to do when an error occurs with import _ssl
What to do if package installation fails when deploying to heroku
ImportError: No module What to do when you are told
[AWS] What to do when the ping command causes a "timeout"
What to do if yum breaks
What to do with Magics install
[virtualbox] What to do when [Could not retrieve mirrorlist] appears when yum update is performed on CentOS7
TypeError: __init__ () got an unexpected keyword argument What to do with'status'
What to do when a video cannot be read by cv2.VideoCapture
[Beanstalk] What to do when an error occurs with import uuid
What to do when the jupyterlab extension settings are not reflected
What to do with PYTHON release?
What to do when you get "I can't see the site !!!!"
What to do when UnicodeDecodeError occurs during read_csv in pandas (pd.read_table ())
What to do to get tensorflow-gpu to work
What to do when ModuleNotFoundError: No module named'XXX' occurs in Python
What to do when the value type is ambiguous in Python?
What to do if grep: empty (sub) expression appears on Mac grep
A story about what to do when a bad interpreter: Not such file or directory appears in Anaconda3 and how to investigate the cause.
[Python] What to do when PEP8 is violated in the process of importing from the directory added to sys.path
What to do when "OS Error: [WinError 126] The specified module cannot be found" appears in import torch
What to do when the result downloaded via scrapy is in English
What to do if No Python documentation found for ... appears in pydoc
[Python] What to do when an error related to SSL authentication is returned
What to do if an error occurs when importing numpy with VScode
What to do if you get an error when trying to load mnist
What to do if fprintd requires a password when registering your fingerprint
Notes on what to do when matplotlib scatter () / scatter3d () does not work
What to do if you get an error when installing Dlib (Ubuntu)
[OSX] [pyenv] What to do when an SSL error occurs in pip
What to do when psycopg2 throws an error when pipenv lock under Pipenv environment