Re: [go-nuts] how to pass analyzer's flag with 'go vet -vettool'

2021-04-13 Thread Xiangdong Ji
Thanks Wagner.

I concur that there might be a bug, or at least the documentation could 
CLARIFY whether analyzer's option is not supported or not,
referring to the usage of 'go vet' I assume the answer would be 'no'.

I tried to modify fieldalignment to turn its '-fix' option on by default, 
change worked as expected if running fieldalignment as a standalone
utility, but no rewriting is applied when running it as a tool of 'go vet', 
could any expert here shed a light? Thanks.  

On Tuesday, April 13, 2021 at 9:50:16 AM UTC+8 wagner riffel wrote:

> On Mon Apr 12, 2021 at 10:23 AM -03, Xiangdong Ji wrote:
> > Hi,
> >
> > I'm trying to run "go vet -vettool=$(which fieldalignment) ./..." for a
> > large project, and wish to turn its '-fix' option on, wondering how to
> > pass
> > that option?
>
> Hi Xiangdong, I found that surprising that even docs didn't mention
> this anywhere, I also got confused by how go vet -vettool works but I
> think I understood after reading the source code, after a -vettool is
> specified, all flags that are not build flags should be sent to the
> vettool, apparently those old tools like fieldalignemnt are broken
> with the new "vet command line protocol" mentioned in the source code,
> even some flags for those tools is broken, it's clear to me that
> there's a bug going on here. Please also consider that possible that I
> just think I understood the problem. :)
>
> BR.
>
> --wagner
>
>

-- 
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/ddc5863d-cf77-4015-91f1-b1cae4863ed8n%40googlegroups.com.


Re: [go-nuts] Why does Go ignore HTTP_PROXY and HTTPS_PROXY if the proxy address is localhost

2021-04-13 Thread Adrian Ho

On 14/4/21 6:39 am, Orson Cart wrote:

So, to clarify:

1/ I have a proxy (Fiddler) running locally on port 
2/ my /etc/hosts file has an entry as follows: 127.0.0.1 fiddler
3/ My HTTP_PROXY and HTTPS_PROXY environment variables are set to 
http://fiddler:  and https://fiddler: 
 respectively


if I then issue a request via curl then that request is picked up by 
the proxy.
However if I make the same request from my go application, the request 
appears to bypass the proxy and is sent directly. I'm perplexed.


The "Name Resolution" section of https://golang.org/pkg/net/ says:

On Unix systems, the resolver has two options for resolving names. It 
can use a pure Go resolver that sends DNS requests directly to the 
servers listed in /etc/resolv.conf, or it can use a cgo-based resolver 
that calls C library routines such as getaddrinfo and getnameinfo.


By default the pure Go resolver is used, because a blocked DNS request 
consumes only a goroutine, while a blocked C call consumes an operating 
system thread.


That might have some bearing on your problem. To see if it's the case, 
as the page suggests:


export GODEBUG=netdns=cgo   # force cgo resolver


Best Regards,
Adrian

--
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/7c2a779f-90c7-a018-953f-221332e1fec3%4003s.net.


Re: [go-nuts] Building gollvm fails on the latest commit

2021-04-13 Thread 'Than McIntosh' via golang-nuts
Thanks for reporting. I'll look into sending a CL.

Cheers, Than


On Tue, Apr 13, 2021 at 6:09 PM Khanh TN  wrote:

> Hi, I'm building gollvm with both gollvm and LLVM on the latest commit.
> It fails and the error reads:
> [..]/llvm-project/llvm/tools/gollvm/passes/GoNilChecks.cpp:363:23: error:
> ‘NoAlias’ was not declared in this scope
>if (AAResult != NoAlias)
>^~~
> [..]/llvm-project/llvm/tools/gollvm/passes/GoNilChecks.cpp:363:23: note:
> suggested alternative: ‘AR_NoAlias’
>
> Can you guys check? Sorry if I'm spamming about gollvm lately.
> Thanks!
> Khanh
>
> --
> 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/de629758-4d44-4348-a506-1f2f6404b5b0n%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/CA%2BUr55EGVTM6Vi612%3DaVX1rgHbidJipm2campe%3DCtVYY61V7zA%40mail.gmail.com.


Re: [go-nuts] Why does Go ignore HTTP_PROXY and HTTPS_PROXY if the proxy address is localhost

2021-04-13 Thread Orson Cart
So, to clarify: 

1/ I have a proxy (Fiddler) running locally on port 
2/ my /etc/hosts file has an entry as follows: 127.0.0.1 fiddler
3/ My HTTP_PROXY and HTTPS_PROXY environment variables are set to 
http://fiddler:  and  https://fiddler: 
 respectively

if I then issue a request via curl then that request is picked up by the 
proxy.
However if I make the same request from my go application, the request 
appears to bypass the proxy and is sent directly. I'm perplexed.

Any advice would be appreciated.



On Tuesday, 13 April 2021 at 22:26:06 UTC+1 Orson Cart wrote:

> Thanks for the reply. 
>
> Yes I did add an alias to the /etc/hosts file and it makes no difference. 
> The requests still bypass the proxy.
>
> As you point out it's possible to achieve the goal in code but I'd really 
> like to do it without changing the code if at all possible.
>
> I'm also just really curious now as to why the go libraries aren't 
> honouring the environment variables.
>
> Thanks for the input.
>
> On Tuesday, 13 April 2021 at 21:36:48 UTC+1 wagner riffel wrote:
>
>> On Tue Apr 13, 2021 at 7:07 PM UTC, Orson Cart wrote:
>> > I'm perplexed :(
>> >
>>
>> Did you tried the /etc/hosts? I think that would do it, if not,
>> something like this may do the trick:
>>
>> if debug {
>> t := http.DefaultTransport.(*http.Transport)
>> t.Proxy = func(r *http.Request) (*url.URL, error) {
>> return url.Parse("http://localhost:;)
>> }
>> }
>>
>> note: i did not tested, just shooting.
>>
>> --wagner
>>
>

-- 
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/708a6171-66bc-42bc-9284-0d46c7942d9dn%40googlegroups.com.


Re: [go-nuts] Why does Go ignore HTTP_PROXY and HTTPS_PROXY if the proxy address is localhost

2021-04-13 Thread Orson Cart
So, to clarify: With my HTTP_PROXY and HTTPS_PROXY environment variables 
set to http://localhost: and  https://localhost:  respectively, if 
I issue a request via curl then that request is picked up by the proxy.
However if I make the same request from my go application, the request 
appears to bypass the proxy and is sent directly.

Any advice would be appreciated.

On Tuesday, 13 April 2021 at 22:26:06 UTC+1 Orson Cart wrote:

> Thanks for the reply. 
>
> Yes I did add an alias to the /etc/hosts file and it makes no difference. 
> The requests still bypass the proxy.
>
> As you point out it's possible to achieve the goal in code but I'd really 
> like to do it without changing the code if at all possible.
>
> I'm also just really curious now as to why the go libraries aren't 
> honouring the environment variables.
>
> Thanks for the input.
>
> On Tuesday, 13 April 2021 at 21:36:48 UTC+1 wagner riffel wrote:
>
>> On Tue Apr 13, 2021 at 7:07 PM UTC, Orson Cart wrote:
>> > I'm perplexed :(
>> >
>>
>> Did you tried the /etc/hosts? I think that would do it, if not,
>> something like this may do the trick:
>>
>> if debug {
>> t := http.DefaultTransport.(*http.Transport)
>> t.Proxy = func(r *http.Request) (*url.URL, error) {
>> return url.Parse("http://localhost:;)
>> }
>> }
>>
>> note: i did not tested, just shooting.
>>
>> --wagner
>>
>

-- 
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/d6bd8344-59bb-4cd4-a9c5-3c1986d93724n%40googlegroups.com.


[go-nuts] Building gollvm fails on the latest commit

2021-04-13 Thread Khanh TN
Hi, I'm building gollvm with both gollvm and LLVM on the latest commit.
It fails and the error reads:
[..]/llvm-project/llvm/tools/gollvm/passes/GoNilChecks.cpp:363:23: error: 
‘NoAlias’ was not declared in this scope
   if (AAResult != NoAlias)
   ^~~
[..]/llvm-project/llvm/tools/gollvm/passes/GoNilChecks.cpp:363:23: note: 
suggested alternative: ‘AR_NoAlias’

Can you guys check? Sorry if I'm spamming about gollvm lately.
Thanks!
Khanh

-- 
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/de629758-4d44-4348-a506-1f2f6404b5b0n%40googlegroups.com.


Re: [go-nuts] Why does Go ignore HTTP_PROXY and HTTPS_PROXY if the proxy address is localhost

2021-04-13 Thread Orson Cart
Thanks for the reply. 

Yes I did add an alias to the /etc/hosts file and it makes no difference. 
The requests still bypass the proxy.

As you point out it's possible to achieve the goal in code but I'd really 
like to do it without changing the code if at all possible.

I'm also just really curious now as to why the go libraries aren't 
honouring the environment variables.

Thanks for the input.

On Tuesday, 13 April 2021 at 21:36:48 UTC+1 wagner riffel wrote:

> On Tue Apr 13, 2021 at 7:07 PM UTC, Orson Cart wrote:
> > I'm perplexed :(
> >
>
> Did you tried the /etc/hosts? I think that would do it, if not,
> something like this may do the trick:
>
> if debug {
> t := http.DefaultTransport.(*http.Transport)
> t.Proxy = func(r *http.Request) (*url.URL, error) {
> return url.Parse("http://localhost:;)
> }
> }
>
> note: i did not tested, just shooting.
>
> --wagner
>

-- 
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/91dd7a03-4455-4fd6-854c-a588bd439925n%40googlegroups.com.


Re: [go-nuts] Why does Go ignore HTTP_PROXY and HTTPS_PROXY if the proxy address is localhost

2021-04-13 Thread 'wagner riffel' via golang-nuts
On Tue Apr 13, 2021 at 7:07 PM UTC, Orson Cart wrote:
> I'm perplexed :(
>

Did you tried the /etc/hosts? I think that would do it, if not,
something like this may do the trick:

if debug {
t := http.DefaultTransport.(*http.Transport)
t.Proxy = func(r *http.Request) (*url.URL, error) {
return url.Parse("http://localhost:;)
}
}

note: i did not tested, just shooting.

--wagner

-- 
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/CAMVU7SLM2E5.16SWWYLIRF8HD%40pampas.


Re: [go-nuts] Why does Go ignore HTTP_PROXY and HTTPS_PROXY if the proxy address is localhost

2021-04-13 Thread Orson Cart
Please accept my ay apologies. I'd misunderstood the documentation.

I was looking for a reason why my go application's requests aren't being 
sent to the proxy that I've specified using HTTP_PROXY and HTTPS_PROXY. 
When I saw the comment in the documentation I thought I'd found an 
explanation even if I didn't understand the reason for it being that way.

So now I'm left with my original problem: I have HTTP_PROXY set to 
http://localhost: and HTTPS_PROXY set to https://localhost:. I also 
have a proxy (Fiddler) running on localhost: but requests from my 
application appear to go direct, bypassing the proxy.

I'm perplexed :(

On Tuesday, 13 April 2021 at 19:17:10 UTC+1 wagner riffel wrote:

> On Tue Apr 13, 2021 at 2:14 PM -03, Orson Cart wrote:
> > Can anyone explain the reasoning behind this? It rather interferes with
> > debugging traffic using a local proxy like Fiddler.
> >
>
> My guess here it's for preventing the remote from tricking the proxy to
> make request to internal services that couldn't be reached otherwise.
>
> > I've seen suggestions to define an alternative hostname in /etc/hosts
> > but as far as I can tell this doesn't work either.
> >
>
> The code you linked doesn't seen to try that hard to block loopback
> requests, I do think that an /etc/hosts entry to 127.0.0.1 should
> bypass the proxy, if not I don't see any other way around other than
> implementing the RoundTripper yourself, which shouldn't be hard for
> such simple use.
>
> --wagner
>

-- 
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/ac6c1bae-2153-41b3-9037-110fc0eb12cfn%40googlegroups.com.


Re: [go-nuts] Why does Go ignore HTTP_PROXY and HTTPS_PROXY if the proxy address is localhost

2021-04-13 Thread 'wagner riffel' via golang-nuts
On Tue Apr 13, 2021 at 2:14 PM -03, Orson Cart wrote:
> Can anyone explain the reasoning behind this? It rather interferes with
> debugging traffic using a local proxy like Fiddler.
>

My guess here it's for preventing the remote from tricking the proxy to
make request to internal services that couldn't be reached otherwise.

> I've seen suggestions to define an alternative hostname in /etc/hosts
> but as far as I can tell this doesn't work either.
>

The code you linked doesn't seen to try that hard to block loopback
requests, I do think that an /etc/hosts entry to 127.0.0.1 should
bypass the proxy, if not I don't see any other way around other than
implementing the RoundTripper yourself, which shouldn't be hard for
such simple use.

--wagner

-- 
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/CAMSV7PV770P.3NLGXICF3GS3S%40pampas.


[go-nuts] Why does Go ignore HTTP_PROXY and HTTPS_PROXY if the proxy address is localhost

2021-04-13 Thread Orson Cart
>From the documentation for ProxyFromEnvironment 
:
"As a special case, if req.URL.Host is "localhost" (with or without a port 
number), then a nil URL and nil error will be returned."

Can anyone explain the reasoning behind this? It rather interferes with 
debugging traffic using a local proxy like Fiddler.

I've seen suggestions to define an alternative hostname in /etc/hosts but 
as far as I can tell this doesn't work either.

-- 
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/499a922f-2298-4cef-ba3d-c16e38e6e548n%40googlegroups.com.


[go-nuts] Why is go ignoring my HTTP_PROXY environment variable

2021-04-13 Thread Orson Cart
I am trying to use Fiddler to debug some issues in a go application. To do 
this I need to make the application use Fiddler's proxy endpoint 
(127.0.0.1:).

I can do this in code but I'd rather not as it would mean updating the code 
just for the purpose of this debugging session.

As I understand it, go will use the HTTP_PROXY environment variable if it's 
set so I have set it as follows:
export HTTP_PROXY=https://127.0.0.1:

However I am seeing nothing in Fiddler.

I read somewhere that go purposely ignores proxies set to 127.0.0.1, 
localhost or anything that evaluates to localhost. Can anyone confirm this 
and if possible explain why this is?

Thanks
 

-- 
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/c5b782a8-9c6f-49ad-944e-cdfba0b58b97n%40googlegroups.com.


Re: [go-nuts] Case for Cond.WaitTimeout()

2021-04-13 Thread Robert Engels
Have the channel hold a slice of objects and process them as a batch. Batch in 
- batch out. 

Typically unless your traffic is bursty - a faster producer than consumer will 
either cause blocking, data loss (drops) or failure (oom). 

> On Apr 13, 2021, at 8:00 AM, Roman Leventov  wrote:
> 
> 
> Jesper, a single channel works if I provision it with big enough capacity 
> (1000), but this feels like an antipattern which can break. Still, this is 
> probably the most practical option.
> 
> Brian, thanks for sharing, yes this pattern solves my problem much simpler 
> than I have. Although it doesn't feel right that achieving something that 
> feels like basic concurrent programming turns into Koan solving.
> 
>> On Tue, 13 Apr 2021 at 14:43, Brian Candler  wrote:
>> Bryan Mill's presentation on go concurrency patterns is well worth watching 
>> all the way through:
>> https://www.youtube.com/watch?v=5zXAHh5tJqQ
>> 
>> There are lots of code snippets which are directly relevant to what you're 
>> trying to do, e.g. from 20:48 is a queue with Get, and 21:59 a queue with 
>> GetMany.  He starts with the traditional semaphore approach and then shows a 
>> much cleaner and simpler way of doing it.
>> 
>> The biggest revelation I got was: instead of having a data structure 
>> protected by a mutex, you can stuff a data structure into a one-element 
>> buffered channel.  When you need to use it: pop it out, modify it, push it 
>> back in.  Very easy to reason about.
>> -- 
>> 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/bNF_KXUiKHs/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/7b198a7b-daaf-435b-930f-bb318dd838e3n%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/CAAMLo%3DYqkBjgz7tL13GE9_hetP79JG-q-PW5ze6UmXVE%3DYU%3DQQ%40mail.gmail.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/9FDCE76E-68C6-4F70-ACAA-A53E9FC4ED19%40ix.netcom.com.


Re: [go-nuts] Case for Cond.WaitTimeout()

2021-04-13 Thread Roman Leventov
Jesper, a single channel works if I provision it with big enough capacity
(1000), but this feels like an antipattern which can break. Still, this is
probably the most practical option.

Brian, thanks for sharing, yes this pattern solves my problem much simpler
than I have. Although it doesn't feel right that achieving something that
feels like basic concurrent programming turns into Koan solving.

On Tue, 13 Apr 2021 at 14:43, Brian Candler  wrote:

> Bryan Mill's presentation on go concurrency patterns is well worth
> watching all the way through:
> https://www.youtube.com/watch?v=5zXAHh5tJqQ
>
> There are lots of code snippets which are directly relevant to what you're
> trying to do, e.g. from 20:48 is a queue with Get, and 21:59 a queue with
> GetMany.  He starts with the traditional semaphore approach and then shows
> a much cleaner and simpler way of doing it.
>
> The biggest revelation I got was: instead of having a data structure
> protected by a mutex, you can stuff a data structure into a one-element
> buffered channel.  When you need to use it: pop it out, modify it, push it
> back in.  Very easy to reason about.
>
> --
> 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/bNF_KXUiKHs/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/7b198a7b-daaf-435b-930f-bb318dd838e3n%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/CAAMLo%3DYqkBjgz7tL13GE9_hetP79JG-q-PW5ze6UmXVE%3DYU%3DQQ%40mail.gmail.com.


Re: [go-nuts] Case for Cond.WaitTimeout()

2021-04-13 Thread Brian Candler
Bryan Mill's presentation on go concurrency patterns is well worth watching 
all the way through:
https://www.youtube.com/watch?v=5zXAHh5tJqQ

There are lots of code snippets which are directly relevant to what you're 
trying to do, e.g. from 20:48 is a queue with Get, and 21:59 a queue with 
GetMany.  He starts with the traditional semaphore approach and then shows 
a much cleaner and simpler way of doing it.

The biggest revelation I got was: instead of having a data structure 
protected by a mutex, you can stuff a data structure into a one-element 
buffered channel.  When you need to use it: pop it out, modify it, push it 
back in.  Very easy to reason about.

-- 
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/7b198a7b-daaf-435b-930f-bb318dd838e3n%40googlegroups.com.


Re: [go-nuts] Case for Cond.WaitTimeout()

2021-04-13 Thread Jesper Louis Andersen
On Tue, Apr 13, 2021 at 12:53 PM Roman Leventov 
wrote:

> type Frame struct{}
>
> type Connection struct {
> sem*semaphore.Weighted // from http://golang.org/x/sync/semaphore
> mu sync.Mutex
> frames []*Frame
> }
>
>
My immediate hunch when reading your code was:

type Connection struct {
frames chan *Frame
}

However, I'm also pretty sure it breaks down in your case. But it might be
good as an exploratory naive question: why wouldn't a channel work in your
case? A Put is to send to the channel. A read is to receive from the
channel. The timeout is handled by a select { ... }, like in your code,
more or less. Granted, you'll have to drain the channel etc, but you
explicitly said the efficiency wasn't that important. And channels tend to
be easier to reason about. My hunch is also this is easier to get a good
semantics for when there are more than 2 goroutines involved.

-- 
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/CAGrdgiWh4%3DjZn9KauSNnTQBaxE3HFLs0h6fRbEhvrH%3D%3Drgj7jQ%40mail.gmail.com.


Re: [go-nuts] Give us const arrays please :)

2021-04-13 Thread tapi...@gmail.com
More immutable value proposals: 
https://github.com/go101/go101/wiki/Go-immutable-value-proposal-list

On Sunday, April 11, 2021 at 8:47:31 PM UTC-4 Kurtis Rader wrote:

> This has been formally requested several times. For example:
>
> https://github.com/golang/go/issues/20443
> https://github.com/golang/go/issues/22876
>
> I'm also willing to bet you are basing your request on experience with a 
> language such as C. Adopting ideas from other languages is fine but 
> blindly, and simplistically, shoehorning a feature from another language 
> almost never has a satisfying result.
>
> On Sun, Apr 11, 2021 at 4:33 PM 'Vladimir Efanov' via golang-nuts <
> golan...@googlegroups.com> wrote:
>
>> Hi Go-Masters
>>
>> It will be very useful to get constant arrays in Golang.
>> Programmers asked about it for years .
>>
>> For now we all should write not exported array definitions 
>> and exported functions to get read access to it.
>>
>> *What we need*
>> const *M*yArray = [n]T = {...} or initMyArrayFunc()
>>
>> *What we have*
>> // ---
>> var ws = [256]bool{' ': true, '\t': true, '\n\: true, '\r\: true}
>> // IsWhitespace checks 
>> func IsWhitespace(c byte) bool {
>> return whitespace[c]
>> }
>> // ---
>> var letter = [256]bool{
>> 'A': true, 'B': true, 'C': true, 'D': true, 'E': true, 'F': true, 
>> ...
>> }
>> //  IsLetterASCII checks a start of an ASCII identifier
>> func  IsLetterASCII(c byte) bool {
>> return letter[c] // 'A'-'Z', 'a'-'z', '_'
>> }
>>  and so on ...
>>
>>
>>
>> -- 
>> 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/01f4a524-9463-4770-8f9d-a17962cd5ba7n%40googlegroups.com
>>  
>> 
>> .
>>
>
>
> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
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/cd8265e6-c87b-417d-90ef-5c5a9eecc958n%40googlegroups.com.


[go-nuts] Case for Cond.WaitTimeout()

2021-04-13 Thread Roman Leventov
I'm trying to implement a simple Connection type:

type Connection {
  // Puts a batch of frames into a queue which can later be read.
  // This method is called only from a single goroutine.
  PutFrames(frames []*Frame)
  // Returns a frame from the queue if present, with timeout.
  // This method is called only from a single goroutine.
  Read(timeout time.Duration) *Frame
}

I cannot change this interface.

The simplest solution that I've come up with is the following:

```
type Frame struct{}

type Connection struct {
sem*semaphore.Weighted // from http://golang.org/x/sync/semaphore
mu sync.Mutex
frames []*Frame
}

func NewConnection() *Connection {
return {
sem: semaphore.NewWeighted(1),
}
}

func (c *Connection) getFrames() []*Frame {
c.mu.Lock()
defer c.mu.Unlock()
return c.frames
}

// Can be called only from one goroutine.
func (c *Connection) Read(timeout time.Duration) *Frame {
if timeout < 0 {
return nil
}
start := time.Now()
c.mu.Lock()
if len(c.frames) > 0 {
f := c.frames[0]
c.frames = c.frames[1:]
if len(c.frames) == 0 {
// Drain the permit if present.
_ = c.sem.TryAcquire(1)
}
c.mu.Unlock()
return f
}
c.mu.Unlock()
if !c.awaitFrames(timeout) {
return nil
}
return c.Read(timeout - time.Since(start))
}

func (c *Connection) awaitFrames(timeout time.Duration) bool {
done := make(chan struct{})
go func() {
_ = c.sem.Acquire(context.Background(), 1)
close(done)
}()
select {
case <-time.After(timeout):
return false
case <-done:
return true
}
}

// Can be called only from one goroutine.
func (c *Connection) PutFrames(frames []*Frame) {
c.mu.Lock()
defer c.mu.Unlock()
if len(c.frames) == 0 {
c.sem.Release(1)
}
c.frames = append(c.frames, frames...)
}
```

The problem with this solution is that it's very complex (let alone 
inefficient, but I don't care about performance in this case). Also, note 
that this solution only works because PutFrames() and Read() are only ever 
called from single goroutines. I'm afraid I would need to hack into 
Semaphore implementation to make it work for more concurrent callers. 

If sync.Cond.WaitTimeout() method existed, the code could be made much 
simpler.

I don't understand what Andrew Gerrard suggested in this 
comment: https://github.com/golang/go/issues/9578#issuecomment-69700942 and 
how it is supposed to work. In his snippet, cond.Wait() is called when the 
mutex is not locked.

Questions:
 - Are there any bugs in my solution?
 - Are there are ways to make my solution simpler?
 - Is it a good case for justifying adding Cond.WaitTimeout()?

-- 
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/c8bc5310-2ca2-498a-99a1-9b944692b150n%40googlegroups.com.


Re: [go-nuts] Why can I not install external packages?

2021-04-13 Thread Tenjin
There we go!
It is now working thanks alot guys.

On Tuesday, April 13, 2021 at 10:57:22 AM UTC+1 Jan Mercl wrote:

> On Tue, Apr 13, 2021 at 11:40 AM Tenjin  wrote:
>
> > So I am using WSL2 to develop using golang but for some reason I am 
> unable to use other peoples packages.
> > For example: I am wanting to use the sql driver 
> https://github.com/go-sql-driver/mysql I am able to go get it and it says 
> it is downloading then it downloads but when I go to use it in my project 
> it just says there is no go mod file, so I was going to use that to manage 
> packages but when I run "go init" it just says initializing git repo and 
> then does not create a go mod file.
> > I do not mind which way I have to use to get the driver working I just 
> need to get it working. One more thing, I cannot install any packages its 
> not just the sql driver.
>
> In your module directory:
>
> $ go mod init example.com/foo/bar
> $ go mod tidy
> $ GO111MODULE=on go build -v -x
>
> The last line just verifies if it works and should possibly reveal why, if 
> not.
>
> > Here is my gopath: /home//go
>
> In your setup the value of $GOPATH should not matter.
>

-- 
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/04f69743-8cfa-4e05-bd9d-eeb284d412e0n%40googlegroups.com.


Re: [go-nuts] Why can I not install external packages?

2021-04-13 Thread Jan Mercl
On Tue, Apr 13, 2021 at 11:40 AM Tenjin  wrote:

> So I am using WSL2 to develop using golang but for some reason I am unable to 
> use other peoples packages.
> For example: I am wanting to use the sql driver 
> https://github.com/go-sql-driver/mysql I am able to go get it and it says it 
> is downloading then it downloads but when I go to use it in my project it 
> just says there is no go mod file, so I was going to use that to manage 
> packages but when I run "go init" it just says initializing git repo and then 
> does not create a go mod file.
> I do not mind which way I have to use to get the driver working I just need 
> to get it working. One more thing, I cannot install any packages its not just 
> the sql driver.

In your module directory:

$ go mod init example.com/foo/bar
$ go mod tidy
$ GO111MODULE=on go build -v -x

The last line just verifies if it works and should possibly reveal why, if not.

> Here is my gopath: /home//go

In your setup the value of $GOPATH should not matter.

-- 
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-U5ZcVFY0LY7QxA1TFYpMuz5btaDxO2iKc_6jf4aW-Jxw%40mail.gmail.com.


[go-nuts] Re: Why can I not install external packages?

2021-04-13 Thread Brian Candler
... Try the following:

mkdir myprog
cd myprog
go mod init myprog
... now use your editor to create main.go which references some third-party 
package, here is a minimal example:
--
package main
import _ "github.com/go-sql-driver/mysql"

func main() {
}
--
... then:

go mod tidy
go build .

-- 
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/66e21ffd-5878-46a1-9127-0393b90c35f3n%40googlegroups.com.


[go-nuts] Why can I not install external packages?

2021-04-13 Thread Tenjin
So I am using WSL2 to develop using golang but for some reason I am unable 
to use other peoples packages.
For example: I am wanting to use the sql 
driver https://github.com/go-sql-driver/mysql I am able to go get it and it 
says it is downloading then it downloads but when I go to use it in my 
project it just says there is no go mod file, so I was going to use that to 
manage packages but when I run "go init" it just says initializing git repo 
and then does not create a go mod file.
I do not mind which way I have to use to get the driver working I just need 
to get it working. One more thing, I cannot install any packages its not 
just the sql driver.

Here is my gopath: /home//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/6fc5372b-9c98-4a81-b11a-95ad50e32d69n%40googlegroups.com.