[go-nuts] calling file.Write() concurrently

2016-07-05 Thread Pierre Durand
Hello! My code: https://play.golang.org/p/pg-p17UuEW I'm trying to append lines to a file concurrently. My first write() function is buggy, because WriteString() are called by several goroutines in unexpected order. So, I've written writeMutex(), that uses a mutex. It works as expected, but in

Re: [go-nuts] calling file.Write() concurrently

2016-07-05 Thread Pierre Durand
is: is there a problem in the *writeBuffer()* function ? It is very simple, and it looks that it works. Le mardi 5 juillet 2016 13:46:38 UTC+2, Alex Bligh a écrit : > > > > On 5 Jul 2016, at 10:38, Pierre Durand <pierre...@gmail.com > > wrote: > > > > So, I've written writeMutex(),

Re: [go-nuts] calling file.Write() concurrently

2016-07-06 Thread Pierre Durand
Ooops, fixed my code: https://play.golang.org/p/vdwDT9WMVr Le mercredi 6 juillet 2016 11:44:33 UTC+2, Pierre Durand a écrit : > > My solution: https://play.golang.org/p/f5H0svLFE0 > What do you think ? > > Le mardi 5 juillet 2016 15:30:38 UTC+2, Jan Mercl a écrit : >> >

Re: [go-nuts] Is it a compiler bug?

2016-11-12 Thread Pierre Durand
https://golang.org/ref/spec#Comments Le samedi 12 novembre 2016 19:20:10 UTC+1, John Souvestre a écrit : > > Ø Also, prefixing all of the need-to-be-commented-out lines with // is > always safe: https://play.golang.org/p/8Cot8lssO3 > > > > Except for perhaps:

[go-nuts] Re: Explosion in memory usage when compiling a big file

2017-01-08 Thread Pierre Durand
This option ? https://github.com/jteeuwen/go-bindata#lower-memory-footprint Le dimanche 8 janvier 2017 21:46:15 UTC+1, Dave Cheney a écrit : > > This is a somewhat known issue. Each token in a parsered .go file is > represented by a Node structure inside the program. The Node structure is >

[go-nuts] Stop HTTP Server with Context cancel

2017-04-04 Thread Pierre Durand
Hello I wrote a small helper to stop an HTTP Server when a Context is canceled. https://play.golang.org/p/Gl8APynVdh What do you think ? Is it OK to use context cancellation for stopping long running functions ? -- You received this message because you are subscribed to the Google Groups

[go-nuts] Re: Stop HTTP Server with Context cancel

2017-04-06 Thread Pierre Durand
<- err: > default: > select { > case <-ctx.Done(): > } > } > > Again, take this with a grain of salt. I didn't check the spec or code, > just off the top of my head. > > > Best, > > On Thursday, April 6, 2017 at 11:29:58 AM UTC+3, Pierre Durand wr

[go-nuts] Re: Stop HTTP Server with Context cancel

2017-04-06 Thread Pierre Durand
t; > > On Wednesday, April 5, 2017 at 4:02:16 AM UTC+10, Pierre Durand wrote: >> >> Hello >> >> I wrote a small helper to stop an HTTP Server when a Context is canceled. >> https://play.golang.org/p/Gl8APynVdh >> >> What do you think ? >> Is it OK

[go-nuts] Re: Do I need to unset variables in a for loop?

2017-05-09 Thread Pierre Durand
> > I "believe" in PHP a for loop keeps the variable in memory until the end > of the script and if you want to remove the variable from memory you need > to unset the variable to help conserve memory. https://en.wikipedia.org/wiki/Cargo_cult Le mardi 9 mai 2017 00:29:14 UTC+2,

[go-nuts] Re: To panic or not to panic, that's the question

2017-05-31 Thread Pierre Durand
I use these functions in init(): https://golang.org/pkg/html/template/#Must https://golang.org/pkg/regexp/#MustCompile Le mercredi 31 mai 2017 21:24:58 UTC+2, Peter Kleiweg a écrit : > > If a package can't be used because some precondition can't be fulfilled, > you can use a panic. Then the

[go-nuts] Re: Go 1.9 introduced error on UDP Multicast JoinGroup

2017-08-27 Thread Pierre Durand
Did you test Go 1.9 betas or RCs ? Le lundi 28 août 2017 01:14:20 UTC+2, oldCoderException a écrit : > > Hi all, > > I upgraded to Go 1.9 and since then UDP multicast code that has been > running fine for over a year is now failing on JoinGroup. I run this > program on linux Mint 18 as root

[go-nuts] Re: when to switch a goroutine to be executed

2017-08-20 Thread Pierre Durand
Goroutine execution is not deterministic. -- 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

[go-nuts] Is it needed to close a HTTP request body ?

2018-09-10 Thread Pierre Durand
When I learned Go a few years ago, I was told to always defer/close the HTTP request body, otherwise it will cause a resource leak. But today I read this: https://golang.org/pkg/net/http/#Request.Body // The Server will close the request body. The ServeHTTP // Handler does not

Re: [go-nuts] Is it needed to close a HTTP request body ?

2018-09-10 Thread Pierre Durand
OK ! thanks. Le lundi 10 septembre 2018 16:39:28 UTC+2, Sam Whited a écrit : > > > > On Mon, Sep 10, 2018, at 09:27, Pierre Durand wrote: > > When I learned Go a few years ago, I was told to always defer/close the > > HTTP request body, otherwise it wi

[go-nuts] "go vet -shadow" and named return variable

2018-10-01 Thread Pierre Durand
My code: package main func main() { a := 1 _ = func() { a := 2 _ = a } _ = func() (a int) { a = 2 return a } _ = a } "go vet -shadow" reports a problem with the first function/closure, but nothing for the second one. Why ? If I understand correctly, it doesn't consider variable declaration in

Re: [go-nuts] "go vet -shadow" and named return variable

2018-10-01 Thread Pierre Durand
ok, thank you ! Le lundi 1 octobre 2018 19:31:58 UTC+2, Ian Lance Taylor a écrit : > > On Mon, Oct 1, 2018 at 7:56 AM, Pierre Durand > wrote: > > > > My code: > > package main > > > > func main() { > > a := 1 > > _ = func() {

[go-nuts] go/types: check if *ast.Ident is a function parameter

2019-01-14 Thread Pierre Durand
Hello ! I'm trying to write a tool that will: - parse my code, and find variable assignment - check if the assigned variable is a parameter in the current function (or a function parameter in the current scope) func myFunc(a *A){ a.foo = "bar" } In the code above, I want to detect that "a"

[go-nuts] Re: Go string and UTF-8

2019-08-20 Thread Pierre Durand
OK, thank you ! Le mardi 20 août 2019 10:34:55 UTC+2, djeg...@gmail.com a écrit : > > On Tue, Aug 20, 2019 at 10:12 AM Pierre Durand wrote: > > > > I know that by convention Go string contain UTF-8 encoded text. > > To my understanding this is not entirely true -- see &

[go-nuts] Go string and UTF-8

2019-08-20 Thread Pierre Durand
I know that by convention Go string contain UTF-8 encoded text. Is it recommended/a good practice to store invalid bytes in a string ? The use case: - compute a hash => get a []byte - convert the []byte to string (this string is not UTF-8 valid) - use the string as a map key In my case, the

Re: [go-nuts] Go string and UTF-8

2019-08-20 Thread Pierre Durand
Well, in my case I don't want to convert the []byte to hexadecimal string, because it uses 2x more memory. The code contains a huge map where the key is an MD5 hash. Please note that I'm not personally working on this. I was reviewing the code written by a coworker, and I noticed that there was

Re: [go-nuts] http.client.Do(request) panics in highly concurrent apps (Go 1.14.1)

2020-04-02 Thread Pierre Durand
The stack trace is identical to https://github.com/golang/go/issues/3 Le jeudi 2 avril 2020 23:23:02 UTC+2, Robert Engels a écrit : > > Does your code use any unsafe or cgo? > > On Apr 2, 2020, at 11:38 AM, 'hamid...@live.com ' via > golang-nuts > wrote: > >  > Hi folks, > > An issue with

[go-nuts] Re: Why does race detector only throw out warning rather than fatal error?

2020-09-09 Thread Pierre Durand
See "halt_on_error" https://golang.org/doc/articles/race_detector.html#Options Le mardi 8 septembre 2020 à 14:47:11 UTC+2, chole...@gmail.com a écrit : > Code with data races is invalid code, we shouldn't let it run once we find > a data race. Actually, since Go 1.5, when runtime finds

[go-nuts] Generic "nillable" constraint

2022-12-22 Thread Pierre Durand
Is there a way to declare a "nillable" constraint that matches all types that can be nil (pointer, slice, map, etc.) ? I would like to write a function, that receives a parameter (with a generic type), and check if this parameter is nil. I found a very ugly way to write it:

[go-nuts] Re: Generic "nillable" constraint

2022-12-22 Thread Pierre Durand
Same question for `len()`: is there a way to declare a constraint that matches types that support `len()` ? Le jeudi 22 décembre 2022 à 14:23:22 UTC+1, Pierre Durand a écrit : > Is there a way to declare a "nillable" constraint that matches all types > that can be nil (pointer,

Re: [go-nuts] Re: Generic "nillable" constraint

2022-12-22 Thread Pierre Durand
43:51 UTC+1, axel.wa...@googlemail.com a écrit : > On Thu, Dec 22, 2022 at 2:24 PM Pierre Durand wrote: > >> Same question for `len()`: is there a way to declare a constraint that >> matches types that support `len()` ? > > > For this, the workaround you posted works

[go-nuts] testing: add a global cleanup function.

2023-06-14 Thread Pierre Durand
Currently we can register a cleanup function on a single test. This function is executed when the test finishes. But there is no way to execute a cleanup function after all the tests of a package are executed. Use case: let's say I want to build a "test helper" library that is used by other

Re: [go-nuts] Re: assert library with generics?

2024-02-23 Thread Pierre Durand
https://pkg.go.dev/github.com/pierrre/assert#section-readme Le vendredi 23 février 2024 à 09:34:43 UTC+1, Harmen a écrit : > On Thu, Feb 22, 2024 at 04:41:53PM -0800, Seth Hoenig wrote: > > https://github.com/shoenig/test > > > > We've been using this for a couple years now, and it's been