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

2022-11-28 Thread thepud...@gmail.com
Hi Pat,

FWIW, I pulled together a TLDR on modules some time ago that I think hits 
upon each of the different issues you encountered in this thread. It also 
tries to summarize the core modules concepts, along with a bit of advice on 
how to stay on the "happy path" when starting out with Go modules. It is 
located here:

  https://stackoverflow.com/a/57314494/11210494

That might be worth a quick read, especially if you found anything puzzling 
so far.

It is likely also worthwhile to go through the official Go modules tutorial 
from the Go project:

  https://go.dev/doc/tutorial/create-module

Finally, looking over the thread, it seems you started by chasing how to 
set GOROOT, which makes sense given the main error message you first saw 
mentions GOROOT. 

GOROOT was a bit of a red herring, and I opened an issue suggesting that 
error message be modified to something more helpful:

  #56965 -- cmd/go: consider reducing use of the word 'GOROOT' in error 
messages
  https://github.com/golang/go/issues/56965
  
Feel free to comment there or here if you have any additional thoughts on 
what would have made your journey simpler.

Best regards,
thepudds

On Friday, November 25, 2022 at 10:48:40 PM UTC-5 pat2...@gmail.com wrote:

> Thanks
> That seems to be the solution
>

-- 
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/c3c5c0ea-4d01-4bbb-9aa8-4442abfd459bn%40googlegroups.com.


Re: [go-nuts] How to cast *interface{} into *T ?

2022-11-28 Thread Denis P
Thanks guys. I have finished my homework thanks to you: 
https://pkg.go.dev/github.com/fairking/di_plus

On Friday, 25 November 2022 at 16:35:50 UTC pattnaik...@gmail.com wrote:

> If you create a wrapper interface type and create *generic constraints* with 
> the *MyWrapper* struct then it'll type cast with *interface* with *(T)*.
>
> https://go.dev/play/p/-VnQxG77sDL
>
>
> On Fri, Nov 25, 2022 at 3:38 PM 'Axel Wagner' via golang-nuts <
> golan...@googlegroups.com> wrote:
>
>> If you assign a value to an interface, it will get copied. That's the 
>> same as if you assign an int to another int - it will get copied. If you 
>> want the interface to contain a reference, you have to assign a pointer to 
>> it: https://go.dev/play/p/nLw51pjWh4u
>>
>> Side note: Go doesn't have "instances". It has "variables", which is 
>> *probably* what you mean.
>>
>> On Fri, Nov 25, 2022 at 10:55 AM Denis P  wrote:
>>
>>> Thank you everyone for your help.
>>> The problem still exists.
>>> I am looking for a solution where s and s2 point to the same instance. 
>>> The current example proves they are different instances.
>>> https://go.dev/play/p/_JyfJelhIy4
>>>
>>> The main goal is to store any type in a wrapper and then get the 
>>> reference of the actual struct.
>>> Also it must be the same instance, so the println should print 2, 2, 2
>>>
>>> But look like there is no obvious solution. :-(
>>>
>>> On Friday, 25 November 2022 at 08:19:17 UTC Brian Candler wrote:
>>>
 To give a real-world example:

 https://pkg.go.dev/github.com/prometheus/client_golang/prometheus

 type metrics struct {
 cpuTempprometheus.Gauge
 hdFailures *prometheus.CounterVec
 }

 Question: why is prometheus.Gauge not a pointer, but 
 *prometheus.CounterVec is a pointer?

 Answer: because prometheus.Gauge is an interface, whereas 
 prometheus.CounterVec is a struct.

 An interface essentially already *contains* a pointer to a data value - 
 in fact, a tuple of (type, pointer).  So you should never take a pointer 
 to 
 an interface.  Just pass the interface value, and it will copy the (type, 
 pointer) pair.

 However, when you extract a value from an interface, it *will* always 
 copy the internal value.  This avoids aliasing issues: someone who passes 
 an interface value to someone else, won't expect the recipient to be able 
 to change the sender's copy.

 e.g.
 https://go.dev/play/p/u5y3Kwm9Ydz

 Of course, if your interface *contains* a pointer, then the recipient 
 of the interface can modify the thing being pointed to.
 https://go.dev/play/p/o_XAJtNuyGF

 But they can't modify the pointer itself held within the interface, to 
 make it point to something else.

 The short version is: avoid pointers to interfaces, as the FAQ says.  
 Instead, let a concrete pointer value satisfy an interface.

 On Friday, 25 November 2022 at 07:40:59 UTC Nigel Tao wrote:

> Possibly relevant:
> https://go.dev/doc/faq#pointer_to_interface
>
 -- 
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/948dc8f3-385e-4f50-a44b-ddf4792e6362n%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...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/CAEkBMfE7XX%2BnHJTW36GaoLjQWidY7GCjpHP1zyOJJzMcSq13JA%40mail.gmail.com
>>  
>> 
>> .
>>
>
>
> -- 
>  
>
> Thanks & Regards
> Deeptiman Pattnaik
>

-- 
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/b09312e7-c52e-4517-bed1-1ff0352cabf5n%40googlegroups.com.


Re: [go-nuts] Tool showing all assignemnts to the blank identifier

2022-11-28 Thread Jan Mercl
On Mon, Nov 28, 2022 at 1:44 PM Wojciech Muła  wrote:

> Is there any tool that would point out places with
> an assignment to the blank identifier?
>
> I'd like to spot possible refactoring/debug leftovers,
> like `_ := func() {}` or unused imports.
>
> I went through the staticcheck list of checks, but
> didn't find anything similar.

$ grep -n '\b_\b :\?= ' *.go

-- 
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-UB%3DWBsK4FJWDDyaZd1q8Ew7iTC%2ByUFwbGXMROOL_0_dg%40mail.gmail.com.


[go-nuts] Tool showing all assignemnts to the blank identifier

2022-11-28 Thread Wojciech Muła
Hi!

Is there any tool that would point out places with
an assignment to the blank identifier?

I'd like to spot possible refactoring/debug leftovers,
like `_ := func() {}` or unused imports.

I went through the staticcheck list of checks, but
didn't find anything similar.

cheers
Wojciech

-- 
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/f82cdf4a-2032-483f-a125-bddc4f5a2e52n%40googlegroups.com.