[go-nuts] How to mock things without having too big an impact on the source code?

2017-11-14 Thread Glen Huang
I find that to be able to unit test things in golang, I need to restructure them in an uncomfortable way in order to be able to mock their dependencies. For example, say I want to test this simple http handler: func handleLogIn(w http.ResponseWriter, r *http.Request) { svc :=

[go-nuts] Re: Who are the https://gophers.slack.com/ admins?

2017-11-14 Thread Florin Pățan
Please send a mail to florinpa...@gmail.com from the e-mail account you created your account I'll be happy to help you. On Monday, November 13, 2017 at 6:41:13 PM UTC, Vlad Didenko wrote: > > My phone got stolen, so I am locked out of the https://gophers.slack.com/ > 2FA. > > Slack tells to ask

[go-nuts] Can someone explain this behavior with interfaces/points?

2017-11-14 Thread Travis Beauvais
https://play.golang.org/p/76gIgzXgcS Why is err not nil when a is? Our theory is that err is a pointer to a nil pointer so technically not nil. We would have assumed that a pointer to a nil pointer would be nil though. Why is that that not the case? By the way, we don't need help with this.

[go-nuts] Re: Who are the https://gophers.slack.com/ admins?

2017-11-14 Thread Vlad Didenko
Florin, Thank you! On Tuesday, November 14, 2017 at 5:28:09 PM UTC-6, Florin Pățan wrote: > > Please send a mail to fl..@gmail.com from the e-mail account you > created your account I'll be happy to help you. > > On Monday, November 13, 2017 at 6:41:13 PM UTC, Vlad Didenko wrote: >> >> My

Re: [go-nuts] Is there a way or lib to read a binary into a sturct{len int32;data [len]int32}

2017-11-14 Thread hui zhang
I found what I want https://github.com/lunixbochs/struc https://github.com/go-restruct/restruct 2017-11-07 18:33 GMT+08:00 Konstantin Khomoutov : > On Tue, Oct 31, 2017 at 04:36:20PM +0800, hui zhang wrote: > > [...] > > > > Is there a way or lib to read a binary into a this

Re: [go-nuts] What release is projected to contain change 60910

2017-11-14 Thread Ian Lance Taylor
On Tue, Nov 14, 2017 at 7:04 PM, wrote: > > I have the challenge reported by https://github.com/golang/go/issues/20376 > and 21386, apparently fixed by > https://go-review.googlesource.com/c/go/+/60910. I'm attempting to load > multiple plugins which implement the same

Re: [go-nuts] Can someone explain this behavior with interfaces/points?

2017-11-14 Thread Dan Kortschak
This is explained in the FAQ: https://golang.org/doc/faq#nil_error On Tue, 2017-11-14 at 16:37 -0800, Travis Beauvais wrote: > https://play.golang.org/p/76gIgzXgcS > > Why is err not nil when a is? > > Our theory is that err is a pointer to a nil pointer so technically > not  > nil. We would

[go-nuts] What release is projected to contain change 60910

2017-11-14 Thread bruceesmith
Hi I have the challenge reported by https://github.com/golang/go/issues/20376 and 21386, apparently fixed by https://go-review.googlesource.com/c/go/+/60910. I'm attempting to load multiple plugins which implement the same interface & then choose between them at runtime. I've tested with Go

[go-nuts] Re: How to mock things without having too big an impact on the source code?

2017-11-14 Thread prades . marq
Since functions are values you can just do that: var NewExternalService func()Service = pkg.NewExternalService and then mock NewExternalService or explicitely inject dependencies in your http.HandlerFunc func(Service) http.HandlerFunc{ return func(w http.ResponseWriter, r *http.Request){

[go-nuts] Re: How do I find the origin IP Address from a http request?

2017-11-14 Thread Tamás Gulácsi
On Jan 2, 7:43 pm, gary b wrote: > You can get the IP address using RemoteAddr() in ResponseWriter. > Seehttp://golang.org/pkg/http/#ResponseWriterfor the documentation. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To

[go-nuts] Re: Will a running GC task stop immediately once debug.SetGCPercent(-1) is called?

2017-11-14 Thread T L
Thanks for the confirmation. On Monday, November 13, 2017 at 6:38:21 PM UTC-5, Keith Randall wrote: > > The runtime will still finish any in-progress garbage collection. > debug.SetGCPercent only affects the trigger point (when to start) and the > pacing (at what rate to mark the heap). > > > On

[go-nuts] Re: How to convert from []byte to []uint32?

2017-11-14 Thread Christian LeMoussel
.Thank you Peter & Bryan for your help, it's very instructive. I realized a Bench with all your solutions: https://play.golang.org/p/ePKkHNqTot BenchmarkCharToInt32_0 : my original solution BenchmarkCharToInt32_1 : Bryan "code golf" solution. https://play.golang.org/p/Jxkf2Vheml

Re: [go-nuts] Understanding panic at addr=0x38 when calling a method on a nil interface

2017-11-14 Thread Konstantin Khomoutov
On Mon, Nov 13, 2017 at 03:58:35PM -0800, keith.rand...@gmail.com wrote: [...] What puzzles me, is that the address it panics is not 0x0 (which I would expect from an x86/amd64 H/W platform to stand for nil) but 0x38: [...] >> Konstantin, your description is correct. The code is trying

[go-nuts] Re: How to returns the index of the first instance in uint32 slice?

2017-11-14 Thread howardcshaw
You certainly can implement such a thing. The source to the bytes Index function is in the bytes_platform.go files, as it is optimized per platform: https://golang.org/src/bytes/bytes_amd64.go is the amd64 one, for example. Looking at it is a good way to see how such a thing is implemented. A

[go-nuts] How to returns the index of the first instance in uint32 slice?

2017-11-14 Thread Christian LeMoussel
bytes package implements Index function (func Index(s, sep []byte) int) that returns the index of the first instance of sep in s, or -1 if sep is not present in s. Do you think it's possible to do the same thing with uint32 slice (func Index(s, sep

Re: [go-nuts] net/http: Server closeIdleConns does not close StateNew connections

2017-11-14 Thread Peter Mogensen
On 2017-11-13 21:16, André Carvalho wrote: > I also ran into this issue recently. I think this is a dup > of https://github.com/golang/go/issues/21204. This issue can be > mitigated if you set some reasonable ReadTimeout on the http.Server, > which causes the http.StateNew connection to timeout

[go-nuts] Re: Golang crashes windows console

2017-11-14 Thread Patrick Hadlaw
Thanks a ton for the help I figured out that Cygwin has git installed and I had it in path in windows called the wrong version of git. On Tuesday, November 14, 2017 at 12:18:02 AM UTC-5, Dave Cheney wrote: > > This has been reported previously and appears to be a bug in git which > causes

Re: [go-nuts] Can someone explain this behavior with interfaces/points?

2017-11-14 Thread Francesc Campoy
Also, you might enjoy my GopherCon talk on nil https://www.youtube.com/watch?v=ynoY2xz-F8s On Tue, Nov 14, 2017 at 4:52 PM Dan Kortschak wrote: > This is explained in the FAQ: https://golang.org/doc/faq#nil_error > > On Tue, 2017-11-14 at 16:37 -0800, Travis

[go-nuts] golang and http2

2017-11-14 Thread Albert Tedja
I am reading Golang's support for HTTP2, and it seems it is only enabled by default if you use https https://go-review.googlesource.com/c/go/+/15828 My questions are: 1. Does this mean I have to use ListenAndServeTLS() to enable http2 and if not, it will fallback to HTTP1.1? 2. Can I