Golang进口问题

I'm trying to use import a package for internal use, but I have been having some issues.
My directory structure looks like this:

  app/
    model/
      file1.go
      file2.go
      ...
    main.go

When I try to build the program, I get an error that looks something like this:

/usr/local/go/src/pkg/model (from $GOROOT)

I want to be able to call the model programs in any of my other programs in the app simply using:

import "app/model"

What are my options when it comes to doing this?

You import from GOPATH level .. all of your packages should live there.

For example, assuming your application is here:

$GOPATH/src/dtrinh100/app/

..and your package you wish to import is here:

$GOPATH/src/github.com/other/package

Your import would be:

import "github.com/other/package"

You should review the literature around what the GOPATH environment variable is all about. When beginning Go, it is important you understand its purpose and initially, you should place all of your projects/packages inside of the GOPATH.

When you import a custom package, Go looks for its definition in each workspace listed in the GOPATH environment variable. Your custom package should be defined in a src subdirectory.

If you keep your code in a source repository somewhere, then you should use the root of that source repository as your base path. For instance, if you have a GitHub account at github.com/user, that should be your base path.

Note that you don't need to publish your code to a remote repository before you can build it. It's just a good habit to organize your code as if you will publish it someday. In practice you can choose any arbitrary path name, as long as it is unique to the standard library and greater Go ecosystem.

You should use github.com/user as our base path. Create a directory inside your workspace in which to keep source code:

$ mkdir -p $GOPATH/src/github.com/user

You can look at How to Write Go Code for more details.