[go-nuts] Go 1.9 poller, close os.File used by another goroutine

2017-08-24 Thread Dave Cheney
If that file is a pipe, yes. If that file is not a pipe, no, it's still not possible because POSIX doesn't give those guarnetees without using non blocking IO. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and

[go-nuts] Re: can't open file if its name was read from stdin

2017-08-24 Thread Uli Kunitz
ReadString returns the line including the terminating newline ('\n'). You can check it with fmt.Printf("filename: %q\n", filename). One option to fix it is using function strings.TrimSpace. It will remove all space characters at the start and the end of the string. -- You received this

[go-nuts] Should we stop using a global logger?

2017-08-24 Thread Tamás Gulácsi
Yes[1]: your logger is a concrete dependency which should be passed explicitly to the function which logs! And as the common idiom is to not include Context in struct but pass as the first argument, the logger should be inserted into that Context. [1]

[go-nuts] can't open file if its name was read from stdin

2017-08-24 Thread Dave Cheney
Check the error from ReadString to find out why it's returning a empty string. -- 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

[go-nuts] Re: Should we stop using a global logger?

2017-08-24 Thread buchanae . ohsu
Or, what if... type FunnelContext interface { context.Context logger.Logger } type RequestHandler struct { // No context specific fields here, instance stays reusable across requests } func (RequestHandler) Handle(ctx FunnelContext) {} On Thursday, August 24, 2017 at 8:58:15 PM

Re: [go-nuts] Re: [ANN] Gomail v2: sending emails faster

2017-08-24 Thread Antonio Sun
You should break that 40s up and see how long is spent on dial, and how long is spent on send. On Thu, Aug 24, 2017 at 9:41 PM, wrote: > Thank you very much for your reply. However, in my code, it spent 40s to > send email. > > Here is the code: > > now := time.Now() > msg :=

[go-nuts] Re: Should we stop using a global logger?

2017-08-24 Thread Dave Cheney
> Should we stop using a global logger? Yes[1] 1. https://dave.cheney.net/2017/01/26/context-is-for-cancelation On Friday, 25 August 2017 13:38:48 UTC+10, buchan...@gmail.com wrote: > > In Funnel [1], we've been using a global logger, based on logrus [2]. This > has worked fine through the

[go-nuts] Should we stop using a global logger?

2017-08-24 Thread buchanae . ohsu
In Funnel [1], we've been using a global logger, based on logrus [2]. This has worked fine through the early stages of the project, but it's starting to show a few cracks. In particular, we need to ensure that a request (task) ID is present in all log messages. Solutions to this have grown to

[go-nuts] can't open file if its name was read from stdin

2017-08-24 Thread buzzersdad
Does anyone know why Google Go program 1 works, below, and program 2 doesn't? The only difference - I read in the filename from the console in the one that doesn't work but it is a literal in the one that works... I tried typing in the full path for the file, and also "..sample.txt" instead of

[go-nuts] Re: [ANN] Gomail v2: sending emails faster

2017-08-24 Thread yhj772709
Thank you very much for your reply. However, in my code, it spent 40s to send email. Here is the code: now := time.Now() msg := gomail.NewMessage() //the element of msg is abridged dial := gomail.Dialer{Host: "127.0.0.1", Port: 25} dial.TLSConfig = {InsecureSkipVerify: true} if err :=

Re: [go-nuts] Re: Go 1.9 is released

2017-08-24 Thread jimmy frasche
Thanks for all the great work—lots of exciting changes in this release! On Thu, Aug 24, 2017 at 3:52 PM, Nathan Kerr wrote: > Congrats! > > I updated my Go Release Timeline and When Should You Upgrade Go? pages. > > On Friday, August 25, 2017 at 12:44:25 AM UTC+2, Chris

[go-nuts] Re: Go 1.9 is released

2017-08-24 Thread Nathan Kerr
Congrats! I updated my Go Release Timeline and When Should You Upgrade Go? pages. On Friday, August 25, 2017 at 12:44:25 AM UTC+2, Chris Broadfoot wrote: > > Hello gophers, > > We just

[go-nuts] Go 1.9 is released

2017-08-24 Thread Chris Broadfoot
Hello gophers, We just released Go 1.9. You can read the announcement blog post here: https://blog.golang.org/go1.9 You can download binary and source distributions from our download page: https://golang.org/dl/ To compile from source using a Git checkout, update to the release with "git

Re: [go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Tom Payne
Ah, cool. So graceful shutdown can be achieved by calling Close() on the net.Listener. Nice! Thank you :) Tom On Thursday, August 24, 2017 at 8:20:34 PM UTC+2, Jan Mercl wrote: > > net.Listener has a Close method that will make Accept return an error. > net.Listener.Accept is not equal to

Re: [go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Jan Mercl
net.Listener has a Close method that will make Accept return an error. net.Listener.Accept is not equal to accept(2). On Thu, Aug 24, 2017, 20:13 Tom Payne wrote: > Thanks. Looking at the man page for Linux's accept(2) > http://man7.org/linux/man-pages/man2/accept.2.html it

Re: [go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Tom Payne
Thanks. Looking at the man page for Linux's accept(2) http://man7.org/linux/man-pages/man2/accept.2.html it seems that l.Accept is unlikely to ever return an error. accept(2) returns an error if either the connection is incorrectly set up somehow, or if a system call is interrupted by a

Re: [go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Jan Mercl
The wg.Wait will be executed after l.Accept returns an error. It's purpose is to wait for the completions of all handlers invoked in the go statement that did not finished already. On Thu, Aug 24, 2017, 19:49 Tom Payne wrote: > Awesome, thanks Jan for the fast and clear

[go-nuts] Re: [ANN] Gomail v2: sending emails faster

2017-08-24 Thread Tamás Gulácsi
It uses a constant 10s timeout for dial. What should time out? -- 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. For more

Re: [go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Tom Payne
Awesome, thanks Jan for the fast and clear response. In fact, the for {} is an infinite loop so wg.Wait() will never be reached and serve() will never terminate. Correct? I guess I over-read how much this prototypical code was representative of a real server loop. Sorry Dave! Tom On

Re: [go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Jan Mercl
No, wg.Add cannot "switch" to wg.Wait, they're both in the samr goroutine, the go statement will be always the next one to execute after wg.Add within serve(). On Thu, Aug 24, 2017, 19:29 Tom Payne wrote: > I'm not singling out Dave Cheney here, I'd just like to check my >

[go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Tom Payne
I'm not singling out Dave Cheney here, I'd just like to check my understanding of Go's resource handling and concurrency. In this blog post a "prototypical network server" is presented: https://dave.cheney.net/2017/08/20/context-isnt-for-cancellation Code: func serve(l net.Listener) error

[go-nuts] Re: Generics and readability

2017-08-24 Thread mhhcbon
Why would you put generics on a method ? The syntax you demonstrate is horrible, indeed. what if generics are type related type notFinal struct { p1 p2 } func (n notFinal) whatever(in ) string { return fmt.Sprintf(in) // anything to interface{}, works. } type Final notFinal

[go-nuts] Re: Generics and readability

2017-08-24 Thread gary . willoughby
Using D syntax: func (r MyType) foo(A, B)(x A, y B) (z B, err error) { ... } result, _ := MyType.foo!(int, int)(10, 20) Also, there's no reason why A and B can't be inferred: result, _ := MyType.foo(10, 20) It looks alright to me and very useful! On Thursday, 24

[go-nuts] Re: "go get -u" and branch behavior on go1.6

2017-08-24 Thread Tong Sun
On Thursday, March 3, 2016 at 2:47:55 PM UTC-5, Garrett Heel wrote: > > > Is there some alternative way of doing this which supports fetching > dependencies from a branch? > If you need to *go get from branch*, use http://gopkg.in -- You received this message because you are subscribed

Re: [go-nuts] Reading bytes into uint32

2017-08-24 Thread Christian von Kietzell
I've read that post and I agree. I can only speculate that they designed the API that way either because of premature optimisation - saving the underlying binary from potentially having to swap the byte order - or out of laziness and an assumption that it's easy to read four bytes into an int in

Re: [go-nuts] Re: Reading bytes into uint32

2017-08-24 Thread Christian von Kietzell
Thanks rob, that works, although I would have prefered a solution without unsafe. I found a thread from a few years back where someone proposed adding NativeEndian to encoding/binary which would always do the right thing. Too bad that never got anywhere. Chris On Thu, Aug 24, 2017 at

Re: [go-nuts] Simple url shortener service

2017-08-24 Thread Lutz Horn
Hi, Am 23.08.2017 um 23:12 schrieb doug...@cornershopapp.com: i have created a simple url shortener service, for practice and learn with go, what do you think ! https://github.com/douglasmakey/ursho It looks like implementing an URL shortener is a natural choice for wetting your toes with

[go-nuts] Golang TDD CRUD REST API

2017-08-24 Thread Derrick Katungi
Hello, I have been looking for tutorials on Golang TDD Rest API but I have not been finding any. Am not interested in using a framework. Am interested in a TDD CRUD REST API. The test I have written returns controllers/admin.go:18: undefined: a in a.DB This is what I have so far.

[go-nuts] Re: [ANN] Gomail v2: sending emails faster

2017-08-24 Thread yhj772709
Hi, Could you show me a method to set timeout when send a email? Regards. 在 2015年9月2日星期三 UTC+8下午7:55:26,Alexandre Cesaro写道: > > Hi, > > I just released the second version of Gomail > . > > There are quite a few backward-incompatible changes >

[go-nuts] Generics and readability

2017-08-24 Thread ojucie
A lot of people like Go because code is very readable even for beginners. func f(x, y int) f is a function that receives x and y as int parameters, returning nothing. Simple enough. func f(x, y int) int f is a function that receives x and y as int parameters, returning yet another int. Fine.

[go-nuts] Understanding "scheduler latency profile" charts

2017-08-24 Thread Konstantin Khomoutov
Hi! We're trying to investigate a case of pathological behaviour of one of one HTTP services (built with Go 1.8) under heavy load. The current hypothesis is that under the load being considered, the scheduler (or the set of available Ps) have hard time serving that load. We came to this

[go-nuts] Re: Next generation code generator for go

2017-08-24 Thread Walter Schulze
The concurrency promises have been delivered. The concurrency functions `applicative do` and `pipeline` have been pushed. On Wednesday, 23 August 2017 19:31:40 UTC+2, Walter Schulze wrote: > > https://news.ycombinator.com/item?id=15083381 > > On Wednesday, 23 August 2017 18:00:49 UTC+2, Walter

Re: [go-nuts] Why does assigning a function variable to a method value allocate memory?

2017-08-24 Thread Bakul Shah
On Thu, 24 Aug 2017 07:40:21 BST roger peppe wrote: > On 24 August 2017 at 06:39, Bakul Shah wrote: > > > > Finally, for better performance it may make sense to store the > > FSM as a vector of vectors or vector of maps so that a slice > > of inputs may

Re: [go-nuts] Why does assigning a function variable to a method value allocate memory?

2017-08-24 Thread Tamás Gulácsi
See ragel for an fsm generator! -- 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. For more options, visit

Re: [go-nuts] Why does assigning a function variable to a method value allocate memory?

2017-08-24 Thread roger peppe
On 24 August 2017 at 06:39, Bakul Shah wrote: > On Wed, 23 Aug 2017 12:11:41 BST roger peppe wrote: >> On 23 August 2017 at 11:20, Bakul Shah wrote: >> > >> > I find regular functions much cleaner (and a closer analog of >> > a

Re: [go-nuts] Re: Gathering Ideas for Go 2.

2017-08-24 Thread Henrik Johansson
Of course you are right Ian, there is nothing inherently wrong with experience reports. That's never what I meant to say and if that's how it came off I am sorry. It has been bugging me a little though that pre GopherCon it was "proposal or nothing" and post GopherCon it is "experience reports or