V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
creedowl
V2EX  ›  Go 编程语言

goland 中 scratch file 的使用问题

  •  
  •   creedowl · 2020-05-14 16:20:18 +08:00 · 2554 次点击
    这是一个创建于 1433 天前的主题,其中的信息可能已经有所发展或是发生改变。

    今天研究了一下 goland 的 scratch file,发现真是一个很好用的功能,但遇到了一个依赖上的问题

    scratch file 可以使用 module 的上下文( using context of module ),我选择了当前在开发的 module (采用 go mod ),就遇到了依赖的问题,但 ide 的补全等功能都可以正常使用

    go.mod中 module 名不是一个单词时(包含 . / _ 等符号时),编译运行 scratch file 就会找不到依赖

    scratch_4.go:3:8: cannot find package "tttt-" in any of:
    	/usr/local/Cellar/go/1.14.2_1/libexec/src/tttt- (from $GOROOT)
    	/Users/creedowl/go/src/tttt- (from $GOPATH)
    

    只有在 module 名是一个单词的时候才能正常编译运行,但使用项目的 github 地址等作为 module 名是很普遍的操作,也是官方支持的,所以是否有办法在 module 名不为单个单词时解决 scratch file 的依赖问题?

    PS 我测试了项目在 go path 内外,都会有这个问题

    3 条回复    2022-01-04 17:38:17 +08:00
    YakuMioto
        1
    YakuMioto  
       2020-05-14 23:45:53 +08:00
    同样困扰

    但是没有好的解决方法(可能我不知道), scratch file 用来写一些不引入第三方的东西还可以

    我目前的做法就是创建一个项目,然后把所有临时验证逻辑也好等等的代码都写在那个项目里.
    creedowl
        2
    creedowl  
    OP
       2020-05-15 10:03:24 +08:00
    @YakuMioto #1 有一个相关 issue 讨论了这个问题

    [issue]( https://youtrack.jetbrains.com/issue/GO-9330)

    但也没有很好的解决方案。这应该是 go compiler 的历史问题,scratch file 是单个文件,不属于 go module,所以编译时采用传统的 go path,会到 go path 中找依赖,不知道有没有解决方案
    hijoker
        3
    hijoker  
       2022-01-04 17:38:17 +08:00
    现在用 go mod 还是不行么?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5078 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 09:46 · PVG 17:46 · LAX 02:46 · JFK 05:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.