dream12001 2019-06-14 05:32
浏览 66

1.12模块:非本地导入中的本地导入

I'm currently using Go 1.12 modules and really tired about importing.

I'm making the rest-api using gin(web microservices) and gorm(golang orm). Everything still ok while working in golang modules. But getting trouble with local packages importing

The directory tree:

project tree

The go.mod:

module github.com/Aragami1408/go-gorm

go 1.12

require (
    github.com/gin-gonic/gin v1.4.0
    github.com/jinzhu/gorm v1.9.9
    github.com/lib/pq v1.1.1
    github.com/satori/go.uuid v1.2.0
)

The db.go:

package db

//code below...

The tasks.go:

package task

import (
    "../db"
)

But when I run and still get this error:

local import "../db" in non-local package

I've searched a lot on google and nothing helps

  • 写回答

1条回答 默认 最新

  • duanliao6789 2019-06-14 05:36
    关注

    From "Do modules work with relative imports like import "./subdir"?"

    In modules, there finally is a name for the subdirectory.

    If the parent directory says "module m" then the subdirectory is imported as "m/subdir", no longer "./subdir".

    In your case:

    import "github.com/Aragami1408/go-gorm/db"
    # or maybe
    import "go-gorm/db"
    

    This assumes, as commented below by Silvio Lucas, that you have set GO111MODULE=on.

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口