简体   繁体   中英

Cannot find nested package

I have a project with the following structure:

myapp/
  -services/
     -services/
         -exch.go
     -services.go
  -server.go

Having $GOPATH set to /home/dev/dev/go this is how server.go names it's package and imports:

//server.go
package main

import (
  "net/http"
  "github.com/labstack/echo"
  "myapp/services"
)

this is services.go :

//services.go
package services

import (
  "fmt"
  "myapp/services/exch"
)

and this is exch.go :

//exch.go
package exch

import (
  "net/http"
  "fmt"
  "io/ioutil"
  "encoding/json
)

Now, server.go imports package services fine, but services.go cannot find package exch . I tried changing the imports path several ways but cannot make it work. Am I missing something?

Might be useful to know that /myapp is located here: /home/dev/dev/go/src

One directory per package, one package per directory. If exch.go is supposed to be imported as services/exch , it needs to be in a directory services/exch , not in directory services/services .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM