drruhc4944 2019-07-25 14:15
浏览 36

从另一个本地包导入本地包

My project structure is like this:

MicroService-Server (project name and folder) 
    main.go
    ---model(folder name)
    ------ package model
    ---logics (folder name)
    -----campaigncreation (folder name)
    --------package campaigncreation
    -----utilities (folder name)
    --------package utilities
    ---controller (folder name)

I want to use "model" package in "campaigncreation", I tried various import statements but I get error for all of them:

import (
    model "././model"
)

import (
    model "./model"
)

import (
    model "MicroService-Server/model"
)

import (
    model "./model"
)
  • 写回答

1条回答 默认 最新

  • dongsheng66783619 2019-07-25 18:43
    关注

    Relative imports are highly discouraged in Go community. It makes the code vague and error prone.

    You should import any custom package starting from the $GOPATH/src/.... So, if your MicroService-Server resides like $GOPATH/src/MicroService-Server/, then you can import model package in campaigncreation easily like this:

    import "MicroService-Server/model"
    

    Here's a catch, if your MicroService-Server folder is not inside the $GOPATH, you can not import it. For this purpose of portability, you should use vendoring tools like the official "go mod" or third party glide.

    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)