douju6542 2019-01-08 16:45
浏览 17
已采纳

找不到嵌套包

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

  • 写回答

1条回答 默认 最新

  • dongwei3172 2019-01-08 17:22
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?
  • ¥15 (SQL语句|查询结果翻了4倍)
  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用
  • ¥15 用verilog实现tanh函数和softplus函数