Yes Brian, this the way it is done in the "How to write Go code" article,
and it indeed works. At least, when package
morestrings is imported in the hello module where it is part of. I did get
that to work, but... i wanted to take the next
step and import that package morestrings in a whole new module, let's call
it hello2. I can't get that to work without
actually creating a real repository and getting it from there. Or, i am now
finding out, after editing my .mod file to use
replace. I had hoped there would be a way to not have to manually edit the
.mod files. Go development used to be
so beautifully simple!



On Sun, 7 Jun 2020 at 16:07, Brian Candler <b.cand...@pobox.com> wrote:

> On Sunday, 7 June 2020 14:20:40 UTC+1, Erwin Driessens wrote:
>>
>>
>> However, my next quest was to import the hello/morestrings package in
>> another module and use it there. I can['t] get it to work :(
>> Does anyone know of a good document/wiki/tutorial about developing go
>> code that is not on remote repositories?  Go was great but now i feel
>> totally handicapped...
>>
>>
> If you used "github.com/me/hello" as the base project, then use "
> github.com/me/hello/morestrings" for the sub-package in the "morestrings"
> subdirectory.
>
> ==> go.mod <==
> module github.com/me/hello
>
> go 1.14
>
> ==> main.go <==
> package main
>
> import (
>     "fmt"
>     "github.com/me/hello/morestrings"
> )
>
> func main() {
>     fmt.Println(morestrings.Greeting)
> }
>
> ==> morestrings/strings.go <==
> package morestrings
>
> const Greeting = "Hello, world!"
>
> Result:
>
> $ go build
> $ ./hello
> Hello, world!
> $
>
> Note: you don't need to use "package morestrings" inside the "morestrings"
> directory - this is just a convention. The "import" statement points to the
> directory, but the package defined in that directory can have any name.
> The following also works:
>
> ==> go.mod <==
> module github.com/me/hello
>
> go 1.14
>
> ==> main.go <==
> package main
>
> import (
>     "fmt"
>     "github.com/me/hello/morestrings"
> )
>
> func main() {
>     fmt.Println(wibble.Greeting)
> }
>
> ==> morestrings/strings.go <==
> package wibble
>
> const Greeting = "Hello, world!"
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/9-5aDopSGvo/unsubscribe.
> To unsubscribe from this group and all its topics, 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/7627c8fd-9b17-4863-88aa-d278c70d8106o%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/7627c8fd-9b17-4863-88aa-d278c70d8106o%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CA%2BJLj4znXG6aP6gTP04upeRXp4wMF7y2nNgGY93N6BcNKD7Hgg%40mail.gmail.com.

Reply via email to