> tester.go:8:2: package github/me/mylib is not in GOROOT That looks like a typo: "github" instead of "github.com"
You definitely don't need a second go.mod, nor do you need any "replace" statements. The following works (literally "github.com/me/mylib" is fine too) -- mylib/go.mod -- module github.com/me/mylib go 1.18 -- mylib/mylib.go -- package mylib import "fmt" func Flurble() { fmt.Println("Flurble") } -- mylib/tester/tester.go -- package main import ( "github.com/me/mylib" ) func main() { mylib.Flurble() } $ cd tester/ $ go run . Flurble $ On Wednesday, 2 November 2022 at 11:50:54 UTC Mark wrote: > I solved this problem by adding an extra go.mod file: > ``` > mylib/ > mylib/go.mod # module github.com/me/mylib > mylib/mylib.go > mylib/mylib_test.go > mylib/tester/tester.go > mylib/tester/go.mod > ``` > This allowed me to change the import in tester.go to `import "mylib"`. > The text of tester/go.mod is: > ``` > module tester > go 1.19 > require mylib v0.3.0 > replace mylib v0.3.0 => ../../mylib > ``` > > On Wednesday, November 2, 2022 at 9:38:01 AM UTC Mark wrote: > >> I suppose what I'm really asking is this: >> >> Given that I have a local pkg, mylib, whose module name is >> github.com/me/mylib, how can I create a local Go application that uses >> mylib from the local folder it is in rather than actually downloading it >> from github. (I do do the latter, but for quick testing & development >> that's too slow; I need to save an edit to mylib in one window & run myapp >> using the just edited mylib in another). >> >> On Wednesday, November 2, 2022 at 9:34:31 AM UTC Mark wrote: >> >>> That doesn't work either (obviously I used my real github a/c name) >>> tester.go:8:2: package github/me/mylib is not in GOROOT >>> >>> On Wednesday, November 2, 2022 at 9:26:35 AM UTC Brian Candler wrote: >>> >>>> In mylib/tester/tester.go: >>>> >>>> import ( >>>> "fmt >>>> "github.com/me/mylib" >>>> ) >>>> >>>> On Wednesday, 2 November 2022 at 08:41:24 UTC Mark wrote: >>>> >>>>> I have this layout: >>>>> ``` >>>>> mylib/ >>>>> mylib/go.mod # module github.com/me/mylib >>>>> mylib/mylib.go >>>>> mylib/mylib_test.go >>>>> ``` >>>>> All this works fine, with both .go files being in the same pkg: mylib. >>>>> >>>>> However, there are some tests that I can't really do using the test >>>>> module because they write to stdout. So I want to create an exe for >>>>> regression testing. >>>>> >>>>> In particular I want the regression tester to be in package main (just >>>>> like an app that uses mylib). >>>>> >>>>> I've tried this layout: >>>>> ``` >>>>> mylib/ >>>>> mylib/go.mod # module github.com/me/mylib >>>>> mylib/mylib.go >>>>> mylib/mylib_test.go >>>>> mylib/tester/tester.go >>>>> ``` >>>>> But I can't get the import to work: >>>>> ```go >>>>> package main >>>>> >>>>> import ( >>>>> "fmt" >>>>> "mylib" >>>>> ) >>>>> >>>>> func main() { >>>>> parser := mylib.Parser() >>>>> fmt.Println(parser.AppName(), parser.Version()) >>>>> } >>>>> ``` >>>>> The error I get is `tester/tester.go:8:2: package garg is not in >>>>> GOROOT`, which is perfectly correct. >>>>> So then I tried to change the import to `../mylib`, but that also >>>>> produces an error, `tester/tester.go:8:2: "../mylib" is relative, but >>>>> relative import paths are not supported in module mode` >>>>> >>>>> Is what I'm trying to do possible? If so, how? If not, what d'you >>>>> recommend? >>>>> >>>>> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/db872007-dd11-4e16-9324-b9fb4d8e4b42n%40googlegroups.com.