[go-nuts] Building a Package With Multiple Subdirectories?

2022-11-21 Thread jlfo...@berkeley.edu
Back in June I asked why Go requires all the files in a package to be in 
the same 
directory. I learned that this is an implementation-specific decision. I 
was also referred to

https://stackoverflow.com/questions/45899203/can-i-develop-a-go-package-in-multiple-source-directories

which discusses this. Someone named "Volker" in this posting said

"Yes, this is doable without any problems, just invoke the Go compiler by 
hand, that is not 
via the go tool."

I'm wondering how to actually do this. Suppose I have a directory, which 
contains several
subdirectories. There are .go files in all these directories that I'd like 
to use to make a
single package. How could I invoke to Go compiler by hand to make this 
happen?
(I've tried adding the "-x" flag to "go build" but I don't see which 
arguments I'd need to 
change to do what I'm trying to accomplish). Volker says "It's complicated".

Also, let's say I was able to figure this out. Would using such a package 
confuse any of
the other commands in the Go tool chain or the dlv debugger?

Cordially,
Jon Forrest


-- 
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/1ab5ad60-6991-4cd3-aea3-99629f4a375cn%40googlegroups.com.


[go-nuts] Go Devroom at FOSDEM 2023

2022-11-21 Thread Maartje Eyskens
Hi gophers!

We have good news: the Go Devroom will be happening again at FOSDEM 2023 in 
Brussels! And this time it will be in person again! We really hope to se 
you all again on 4 February 2023 for a day of Go-related talks and fun.

Like always we're looking for speakers who want to deliver a talk as well 
as volunteers to help us run the conference.

If you'd like to join us please follow the instructions here: 
https://github.com/go-devroom/cfp

See you all in Brussels!
Maartje Eyskens

-- 
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/6f03e5a1-99ed-483b-bf73-4e5362d4b53en%40googlegroups.com.


[go-nuts] Re: How to read struct field names from an empty slice of structs

2022-11-21 Thread 'Mark' via golang-nuts
After struggling, I finally solved it; playground 


On Monday, November 21, 2022 at 10:55:06 AM UTC Mark wrote:

> I have a two level general-purpose data structure: a struct containing one 
> or more slices of structs.
> I want to be able to use reflection to populate this, but as a first step 
> I want to extract the 
> "table names" (i.e., the names of the fields of the outer struct), and the 
> "field names" (the names of each field in each of the inner structs).
> Below is as far as I've got: it correctly finds the table names (including 
> their tag alternatives), but I can't work out how to access the field 
> names...
>
> playground 

-- 
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/e2a46498-7f57-418f-a258-0868fa93f7a5n%40googlegroups.com.


[go-nuts] How to read struct field names from an empty slice of structs

2022-11-21 Thread 'Mark' via golang-nuts
I have a two level general-purpose data structure: a struct containing one 
or more slices of structs.
I want to be able to use reflection to populate this, but as a first step I 
want to extract the 
"table names" (i.e., the names of the fields of the outer struct), and the 
"field names" (the names of each field in each of the inner structs).
Below is as far as I've got: it correctly finds the table names (including 
their tag alternatives), but I can't work out how to access the field 
names...

playground 

-- 
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/c1f828b3-119d-4f78-bd4a-1d0be71d9c1an%40googlegroups.com.


Re: [go-nuts] Int64 to []byte and vice-versa

2022-11-21 Thread 'Axel Wagner' via golang-nuts
Use `encoding/binary`. Yes, you have to care about byte order. But that's
inherent to the question. There is no canonical way in which an integer
correspond to a slice of bytes, you actually have to say how to encode it.
That also doesn't cause any problems - on the contrary, being explicit
about that means you *don't* get into issues (for not knowing what byte
order data is in). See also:
https://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html

So, you probably want to do
b := make([]byte, 8)
binary.BigEndian.PutUint64(b, uint64(v))
and
v := int64(binary.BigEndian.Uint64(b))

On Mon, Nov 21, 2022 at 9:57 AM Nikhilesh Susarla 
wrote:

> Hi,
>
> I have an int64 value say 12
> I want to convert that to []byte array.
> How do we do that. There were lot of ways on the internet. Nothing which
> golang specifies or has a built-package for direct conversions. Lot of them
> dealt with Endiean's, but that might cause issues to I believe.
>
> So, is there any one recommended and safe way?
> Thank you
>
> --
> 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/dffa4b81-9c7b-48d8-8b8b-262804756606n%40googlegroups.com
> 
> .
>

-- 
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/CAEkBMfEfhYYOvLdvZri1_jJ%3DVYeGGyYB9UjXJX3Ud%2BKya%2BiUpg%40mail.gmail.com.


Re: [go-nuts] Int64 to []byte and vice-versa

2022-11-21 Thread Jan Mercl
On Mon, Nov 21, 2022 at 9:57 AM Nikhilesh Susarla
 wrote:

> I have an int64 value say 12
> I want to convert that to []byte array.

Such conversion is not supported. Also, []byte is a slice.

However, the desired result can be computed in code. You can use the
encoding/binary package for that. Endianness matters, you cannot avoid
choosing one or another as that selects different results. In some
contexts the right endianness is platform independent, like in many
network/serialization protocols. In some other cases one has to follow
the platform endianness.

HTH.

-- 
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/CAA40n-WOn0gNK3N9Y93-7VictwAtRQuuQZ7bdBbhb8MjngZaGg%40mail.gmail.com.


[go-nuts] Int64 to []byte and vice-versa

2022-11-21 Thread Nikhilesh Susarla
Hi, 

I have an int64 value say 12
I want to convert that to []byte array. 
How do we do that. There were lot of ways on the internet. Nothing which 
golang specifies or has a built-package for direct conversions. Lot of them 
dealt with Endiean's, but that might cause issues to I believe.

So, is there any one recommended and safe way? 
Thank you

-- 
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/dffa4b81-9c7b-48d8-8b8b-262804756606n%40googlegroups.com.


Re: [go-nuts] where is GOROOT set?

2022-11-21 Thread Brian Candler
On Monday, 21 November 2022 at 04:11:26 UTC pat2...@gmail.com wrote:

>
> Incidentally, there is no need to have github.com in the directory path 
>> on your local filesystem.  You could just use
>> ~/projects/cmd
>>
>
> Doesn't this contradict putting the github path in the name for easy 
> automatic use?
> Or am I confusing two issues?
>
>
You are confusing two issues, although this probably comes from your 
experience with go before GOMODULES, where you did have an 
automatically-created hierarchy under $GOPATH/src.  I came to go just as 
the transition was taking place.

There are two separate concepts now:

(1) The *name* of your module.  This conventionally looks like 
github.com/pfarrell51/cmd to allow automatic fetching from github (but 
doesn't have to).

(2) The *directory* on your local filesystem where your code lives.  This 
can be anywhere and does not have to look anything like your module name.  
This is because the "go.mod" file provides the binding between the module 
name and filesystem location.

- if the current directory contains go.mod, then go.mod names the package 
in this directory
- if the current directory doesn't contain go.mod, then go walks up the 
filesystem to find one.  Then the name of the package in the current 
directory is the name of the module in go.mod, concatenated with the 
subdirectory path needed to get from go.mod's directory to this one.

That is: if ~/projects/misc contains a go.mod with name example.com/test, 
then ~/project/misc/foo has name example.com/test/foo implicitly (as long 
as it doesn't have its own go.mod file).

 
>
>> Note that import "github.com/pfarrell51/cmd" doesn't mean "fetch this 
>> code from github".  It just refers to the module's name.  By walking up the 
>> parent directories and finding go.mod, Go realises that the named module 
>> you are referring to is already on your filesystem as part of your project, 
>> and uses that directly.  This is why it works to use random module names 
>> like example.com/test
>>
>
> I'm not following this, I thought that was exactly why I put in the "
> github.com/pfarrell51/< modulename>"
> in the source directory structure, and therefor in the github 
> https://github.com/pfarrell51/gows repository
> so if someone wanted to use my PID code or my quaternion code, it would be 
> easy and automatic
>
>
For somebody on a remote system, yes.

On your own system, let's say you have the following tree:

~/projects/cmd  # contains go.mod with name github.com/pfarrell51/cmd
~/projects/cmd/foo
~/projects/cmd/bar

In the "foo" subdirectory, there is some code which says

import "github.com/pfarrell51/cmd/bar"

When you compile this code, go finds the go.mod file *in your own 
filesystem* (in the enclosing directory).  It knows that ~/projects/cmd is 
github.com/pfarrell51/cmd.  Therefore, github.com/pfarrell51/cmd/bar can be 
found at ~/projects/cmd/bar (as long as that subdirectory doesn't have its 
own go.mod file).

Hence it doesn't go off to github to fetch github.com/pfarrell51/cmd/bar - 
which would be very confusing, since this is a package inside the module 
you're actively developing, and may not even have been published to github 
at all yet.  It uses the local copy.

Now suppose you've finished it, and you push it to github.  A different 
person writes some code with

import "github.com/pfarrell51/cmd/bar"

For their own code, they need to have their own go.mod file with their own 
module name.  The system can see easily that the module they're writing is 
not the same as the one they're importing.  In this case, "go mod tidy" 
will go off to github and fetch the code, i.e. *your* code which *their* 
code depends on, and drop it into $GOMODCACHE

I hope this makes a bit more sense!  There is a nice series of blog 
articles starting at https://go.dev/blog/using-go-modules, although this 
assumes you know the old behaviour whereas really this is historic now.

Regards,

Brian.

-- 
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/61ce3bdd-1028-4dd1-8af5-b0552b498e7fn%40googlegroups.com.