Re: [go-nuts] Re: custom type wrapping errors; what am i missing?

2020-09-03 Thread Jake Montgomery
On Wednesday, September 2, 2020 at 2:19:31 PM UTC-4, simon place wrote: > * fmt.Printf(%w) is just to add more text to an error, because errors are > immutable its needed.(unless you have custom error types and are local to > them, then you could just edit their state.) > There is more to fm

Re: [go-nuts] Re: custom type wrapping errors; what am i missing?

2020-09-02 Thread Jake Montgomery
I think you may be confused about fmt and error unwrapping. The fmt.Println() in your example code does *not *unwrap err1. When fmt.Errorf creates the error, the message is hard coded "fmt wrapping: error". The Println is just printing the result of err1.Error() On Wednesday, September 2, 20

[go-nuts] Re: [generics] Bugs + something else

2020-09-01 Thread Jake Montgomery
On Monday, August 31, 2020 at 8:49:00 PM UTC-4, p...@pjebs.com.au wrote: > > 1. > For this Go 2 snippet: https://go2goplay.golang.org/p/vbfBBmjxaMi > > Why can't I use square brackets when calling the constructor? > This seems to be fixed now: https://go2goplay.golang.org/p/cpKKg5qG5Ve -- Yo

[go-nuts] Re: Memory Leak in bytes.Buffer String() method

2020-08-30 Thread Jake Montgomery
Sorry if this is a bit obvious. I did not dive into your code. But I did notice that replacePositionalPlaceholders returns buf.String(). If you are certain that this is where the memory 'leak' is originating, then the most likely scenario is that the returned string is never being collected. Is

Re: [go-nuts] Re: How to know if interface{} data is nil w/o reflecting?

2020-08-27 Thread Jake Montgomery
On Thursday, August 27, 2020 at 10:45:52 AM UTC-4, burak serdar wrote: > > On Thu, Aug 27, 2020 at 6:12 AM 'Axel Wagner' via golang-nuts > > wrote: > > > > On Thu, Aug 27, 2020 at 12:53 PM targe...@gmail.com > wrote: > >> > >> Because you then must remember about this specific case every ti

Re: [go-nuts] Re: [generics] Fuzzer, Type Switches

2020-07-20 Thread Jake Montgomery
On Sunday, July 19, 2020 at 1:44:49 PM UTC-4, Steven Blenkinsop wrote: > > On Sun, Jul 19, 2020 at 11:43 AM, Jake Montgomery > wrote: > >> This seems to work: https://go2goplay.golang.org/p/8veymwXYCoZ >> >> >> I'm confused. It panics when I run it

[go-nuts] Re: [generics] Fuzzer, Type Switches

2020-07-19 Thread Jake Montgomery
> > This seems to work: https://go2goplay.golang.org/p/8veymwXYCoZ I'm confused. It panics when I run it now. > -- 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

Re: [go-nuts] the go archive size must be smaller?

2020-07-18 Thread Jake Montgomery
You are asking about the size of the archived go distributions, NOT about the size of programs built with go, correct? On Friday, July 17, 2020 at 5:33:31 PM UTC-4, yangw...@gmail.com wrote: > > This issue is only the binary file, I said is go archive size . > Such as go1.14.6.darwin-amd64.tar.gz

Re: [go-nuts] where is temp file created by http server

2020-07-17 Thread Jake Montgomery
On Thursday, July 16, 2020 at 10:32:32 PM UTC-4, hao dong wrote: > > thanks. I've noticed the code,too. And that's what I'm confused: when > there is a create, there is no delete, and I can not find the file under > os.TemDir() > Seems I have to debug the code to find the removing line. > I beli

Re: [go-nuts] Re: golang time.Now().Format with milliseconds without dot in string

2020-07-14 Thread Jake Montgomery
I agree, it seems like an unfortunate oversight. You can do it without the slice tricks: https://play.golang.org/p/tNAPOcQqApN It does take an additional Sprintf() though. On Tuesday, July 14, 2020 at 8:40:18 AM UTC-4, Vasiliy Tolstov wrote: > > вт, 14 июл. 2020 г. в 15:17, Jake Mont

[go-nuts] Re: golang time.Now().Format with milliseconds without dot in string

2020-07-14 Thread Jake Montgomery
Why not just remove the dot? You know where it is: https://play.golang.org/p/ZHqHTOeA7HQ Perhaps there is a better way, but this seems to work. On Tuesday, July 14, 2020 at 7:00:02 AM UTC-4, Vasiliy Tolstov wrote: > > Hi! I'm read several times godoc about the time package but have now > way to

Re: [go-nuts] [generic] Readibility of Multiple Parenthsis

2020-07-05 Thread Jake Montgomery
I understand Ian's position of wait and see. But for completeness, I will point out that this new 'ambiguity' is different from the current cases where there would be a "collision between a variable name and a type name." As far as I can tell, any such collision in Go 1 would fail to compile. H

Re: [go-nuts] Is it necessary to start function names within main package with capitalized letter?

2020-07-02 Thread Jake Montgomery
On Wednesday, June 24, 2020 at 12:46:42 PM UTC-4, Axel Wagner wrote: > > Personally, I tend to do it. Note that it doesn't actually make a > difference from a technical perspective - main can't be imported, so it > makes no real sense to export any identifiers. > There is a case where main can

[go-nuts] Re: Generic syntax idea

2020-06-29 Thread Jake Montgomery
I'm curious how you would propose rewriting: func Foo(type T comparable, B interface{})(a T, b B, c T) { On Friday, June 19, 2020 at 6:57:45 PM UTC-4, mit...@gmail.com wrote: > > Hello, Ian, > > Would it be possible to have a generic type annotation syntax like this: > > // Print prints the ele

Re: [go-nuts] Go has eliminated most of my off-by-one errors except 0... I mean 1.

2020-06-14 Thread Jake Montgomery
On Saturday, June 13, 2020 at 1:09:16 PM UTC-4, Jan Mercl wrote: > > On Sat, Jun 13, 2020 at 5:37 PM Jake Montgomery > wrote: > > > You cant really write a short 'end()' function. You have to write an end > function for every type of slice. Or use reflection, w

Re: [go-nuts] Go has eliminated most of my off-by-one errors except 0... I mean 1.

2020-06-13 Thread Jake Montgomery
On Saturday, June 13, 2020 at 10:55:43 AM UTC-4, Jan Mercl wrote: > > On Sat, Jun 13, 2020 at 4:42 PM Tom Limoncelli > wrote: > > I'd suggest to just write the short 'end' function by yourself if you > think it's useful for you. It does not harm performance as it will get > inlined AFAICT. >

[go-nuts] Re: Right way to convert c char to golang bytes

2020-06-06 Thread Jake Montgomery
Can you post some code that reproduces the C.GoBytes() behavior you see? According to the documentation it should work as you expect. This "simulation" works (but can not be run in the playground because of cgo usage): https://play.golang.org/p/gec7VNy4-UW On Saturday, June 6, 2020 at 2:57:41 AM

[go-nuts] Re: Assignment of pointer values in a struct...

2020-06-04 Thread Jake Montgomery
Trig, I'm very curious why you want to use a pointer to a string? Since strings are immutable, and already are like "pointers" internally, I have rarely, if ever, used *string in go. What is it that you achieve by doing this? - Jake On Wednesday, June 3, 2020 at 10:33:31 PM UTC-4, Trig wrote:

[go-nuts] Re: Is there a way to create a global variable inside go routine stack? so that i can access any time, without passing around between methods/functions. Crazy thought !!!..

2020-05-25 Thread Jake Montgomery
On Sunday, May 24, 2020 at 3:46:54 PM UTC-4, adithya...@gmail.com wrote: > > if i am not wrong, Even the main itself is a go routine, which have global > variables? > Perhaps you should describe a bit more what you mean? People seem to be making assumptions that you meant something different tha

[go-nuts] Re: time.Ticker's behavior

2020-05-25 Thread Jake Montgomery
I'll take a crack at it. The behavior you see is one tick about 100ms after start, a second one marked as 200ms after start, then one 1200ms, one at 2200, and another at 3200ms after start. The key is in the documentation for NewTicke r: "It adjusts the i

[go-nuts] Re: MediaStreamError

2020-05-22 Thread Jake Montgomery
This forum is about the Go language. Perhaps I am missing something, but this looks like Java? Does this relate to go in some way? On Friday, May 22, 2020 at 4:21:10 AM UTC-4, Ali Hassan wrote: > > I plug video streaming with my website but I got MediaStreamError . > > > How to resolve this erro

Re: [go-nuts] Any solution to hide my source code written in Go and make it a library to develop in Go as well

2020-05-20 Thread Jake Montgomery
Not sure if you care, but plugins are (sadly) not yet supported in Windows. So if you go that route you will not work on Windows. On Sunday, May 17, 2020 at 11:21:40 PM UTC-4, robert engels wrote: > > Just distribute it as a plugin (https://golang.org/pkg/plugin/) - you > only need to make the

[go-nuts] Re: Waitgroup.done wont Panic?

2020-05-14 Thread Jake Montgomery
To clarify what Jan said, a Go program exits when main() exits. Since `wg` has a count of 0, the call to wg.Wait() on like 18 doe not wat, so the program exits before your goroutine even has time to run. With slight modification, it does panic as expected: https://play.golang.org/p/ivcfhsu1N9K

Re: [go-nuts] Deleting map entry from the top level of a nested map doesn't clean the underlying memory

2020-04-27 Thread Jake Montgomery
Perhaps a small program that reproduces the issue would help. I wrote a quick one: https://play.golang.org/p/hbnuZsEqUKV . However, after an hour of running I see no "leak". I am on "go1.14 windows/amd64". After 6,000,000 iterations and 4 TB total allocated The memory stats (HeapInuse and Hea

[go-nuts] Re: "Go build failed." in Go tour requires explicit Kill

2020-04-16 Thread Jake Montgomery
On Wednesday, April 15, 2020 at 1:02:47 PM UTC-4, Marvin Renich wrote: > > In the Go tour, what is the purpose of requiring the user to explicitly > press the "Kill" button when the build fails? This seems completely > unnecessary to me. > > If this is just a natural consequence of the interna

[go-nuts] Re: Writing data without synchronization

2020-04-15 Thread Jake Montgomery
On Tuesday, April 14, 2020 at 7:38:44 AM UTC-4, Slawomir Pryczek wrote: > > Hi Guys, was wondering about some things related to multithread code. > > 2. For lazy initialization double-check pattern. I found on several > sources that it is safe, still race detector complains about data races > (

Re: [go-nuts] Intercepting field access and method call

2020-04-12 Thread Jake Montgomery
It sounds like maybe this is your first statically typed language. Go is statically typed, which means that the scenarios you are talking about can not happen. That is by design, and has huge benefits for code reliability, and also readability. If you call a function that takes a Foo struct as a

[go-nuts] Re: Print something while read message from server with websocket

2020-03-26 Thread Jake Montgomery
UTC-4, 洪嘉鴻 wrote: > > I'm sorry. > The followings are the complete codes of server and client: > Server <https://play.golang.org/p/9vu0GW5a5Y8> > Client <https://play.golang.org/p/CmXjfAJSCY7> > > Thank you very much! > Max > > Jake Montgomery於 202

[go-nuts] Re: Print something while read message from server with websocket

2020-03-25 Thread Jake Montgomery
You do not provide enough information to give a really good answer. There are a number of ways to achieve this, but they depend on the details. A more complete example would help. What is the type of `ws`? If it is something on which you can set a read timeout, then one way would be to set a t

[go-nuts] Re: Bencharking issue with b.StartTimer and b.StopTimer. Was: Benchmark using b.StopTimer and b.StartTimer has unexpected behaviour - to me at least

2020-03-24 Thread Jake Montgomery
of warning in the docs? On Tuesday, March 24, 2020 at 4:01:17 PM UTC-4, Orson Cart wrote: > > On Tuesday, 24 March 2020 19:51:24 UTC, Jake Montgomery wrote: >> >> Strange. I hope someone has a real answer for you. >> >> In the meantime, you can simplify your ex

[go-nuts] Re: Bencharking issue with b.StartTimer and b.StopTimer. Was: Benchmark using b.StopTimer and b.StartTimer has unexpected behaviour - to me at least

2020-03-24 Thread Jake Montgomery
Strange. I hope someone has a real answer for you. In the meantime, you can simplify your example to demonstrate the issue: package demo_test import ( "testing" ) var Foo1 []string var Count int = 8 func Benchmark1(b *testing.B) { for i := 0; i < b.N; i++ { Foo1 = foo(Count)

Re: [go-nuts] go build output depending on project structure

2020-03-19 Thread Jake Montgomery
;nitish' > > 2) go build -v - x main.go > > >> This creates a binary called 'main' > > ldd output of both the binaries is the same. > > Thanks, > Nitish > > > On Thu, Mar 19, 2020 at 7:18 PM Jake Montgomery > wrote: > >> Nitish, &

Re: [go-nuts] go build output depending on project structure

2020-03-19 Thread Jake Montgomery
Nitish, Is there some reason that you want, or need, to be using go build this way, by specifying files? Or is it just curiosity about how the tools work? The typical way to use go build is to build without specifying individual files. If you are using CGO, I would certainly recommend that you d

Re: [go-nuts] How to break-out of martini middleware

2020-03-15 Thread Jake Montgomery
> > Note that Martini is not maintained anymore > I hope this is not too off topic, but when choosing a third party go package it is really important to consider whether the package is being maintained. In my experience it is worth steering clear of any complex package that is not being activ

Re: [go-nuts] Re: Mem-Leak in Go method

2020-03-09 Thread Jake Montgomery
On Monday, March 9, 2020 at 1:37:00 PM UTC-4, Nitish Saboo wrote: > > Hi Jake, > > The memory usage remains constant when the rest of the service is > running.Only when LoadPatternDB() method is called within the service, > Memory Consumption increases which actually should not happen. > I am a

[go-nuts] Re: Mem-Leak in Go method

2020-03-09 Thread Jake Montgomery
You may indeed have a leak. I did not check your code that carefully. But i do wonder about your statement: > > 1)As soon as I call LoadPatternDB() method in parser.go there is some > increase in memory consumption(some memory leak). Ideally that should not > have happened. > Go is a garbage c

[go-nuts] Re: append slice concurrently without lock,after that panic occurred when iterate the slice

2020-03-09 Thread Jake Montgomery
It seems like you start your post by acknowledging that you have a race. But you are wondering why that race is causing a panic? Is that a correct assessment of you post? A race condition can cause all sorts of bad behavior. Some may behave "normally" 99.9% of the time, then cause an incorr

[go-nuts] Re: Changing source code in order code to be supported from older Golang versions e.g. Go 1.10

2020-03-06 Thread Jake Montgomery
On Friday, March 6, 2020 at 1:20:38 PM UTC-5, Amnon Baron Cohen wrote: > > Anyone who is able to put up with a 20 year old OS > will be able to tolerate a 2 year old Go version... > Dimitrios' question is a perfectly legitimate one. Your response does nothing to actually answer the question. It a

Re: [go-nuts] How to obtain complete call chain of runtime functions in pprof, like 'mcall'

2020-03-05 Thread Jake Montgomery
I think you meant https://github.com/robaho/goanalyzer On Thursday, March 5, 2020 at 7:09:18 AM UTC-5, Robert Engels wrote: > > You might be interested in github.com/robaho/go-analyzer which I believe > significantly improves the profiling information when dealing with highly > concurrent Go pro

[go-nuts] Re: go vet on playground emits message on printf %x with floating point

2020-03-04 Thread Jake Montgomery
This is a known problem: https://github.com/golang/go/issues/34993 It was fixed in Go 1.14: https://go-review.googlesource.com/c/tools/+/202041/ I'm curious what you use hex float for? On Tuesday, March 3, 2020 at 7:10:00 PM UTC-5, bup...@gmail.com wrote: > Playground: https://play.golang.org/p

Re: [go-nuts] Should it panic when set a channel to nil concurrently

2020-03-02 Thread Jake Montgomery
Good explanation, Marvin. This is precisely why we have the race detector. If all races produced a panic, then it would not be needed. Some races behave "correctly" for a long time, and only on rare occasion result in silent data corruption that can be almost impossible to debug. Other races mi

Re: [go-nuts] Understind how to apply timeout using gouritine

2020-02-28 Thread Jake Montgomery
Contexts are great. And if your goal is to solve a specific problem, then sometimes they may be the best solution. But you implied in your OP that you were learning go. And in that case, I would still urge you to understand your original channel based code, and why it does not work, and how to

Re: [go-nuts] Understind how to apply timeout using gouritine

2020-02-26 Thread Jake Montgomery
hael Levieux got the idea and repliedr:"You cannot terminate a > function execution from its caller.." . So I was wrong in my understanding > how to implement "cancel" or "break" goroutinea. > > > El martes, 25 de febrero de 2020, 13:45:03 (UT

[go-nuts] Re: undefined (type *math/rand.Rand has no field or method randIntn)

2020-02-25 Thread Jake Montgomery
On Tuesday, February 25, 2020 at 1:42:31 PM UTC-5, Anjana Prabhakar wrote: > > I get the error as r1.randIntn undefined (type *math/rand.Rand has no > field or method randIntn). Please help. > The message is pretty clear. The first step I would take with a message like that is to look at the d

Re: [go-nuts] Understind how to apply timeout using gouritine

2020-02-25 Thread Jake Montgomery
ce. Here is the link > https://play.golang.org/p/7DigEVsKbdx > How can I cancel goToSleep() when timeout is reached? > > > El lunes, 24 de febrero de 2020, 14:16:32 (UTC-3), Jake Montgomery > escribió: >> >> Your code will still not compile. In this group, it is oft

[go-nuts] Re: odd benchmark results for time.Now() call inside vs outside mutex

2020-02-24 Thread Jake Montgomery
FWIW, I also don't see any appreciable difference: goos: windows goarch: amd64 BenchmarkStateSet1-4 1368303 872 ns/op BenchmarkStateSet2-4 1379320 887 ns/op BenchmarkStateSet3-4 1343781 865 ns/op PASS ok command-line-arguments 7.446s On

Re: [go-nuts] Understind how to apply timeout using gouritine

2020-02-24 Thread Jake Montgomery
Your code will still not compile. In this group, it is often helpful to include a link to your code in the playground (https://play.golang.org/) using the "Share" button. That is in addition to, or instead of, posting your code in the message. This will allow others to easily run your code, but

Re: [go-nuts] Question about the zero-value design: Why pointers zero value is not the zero value of what they points to?

2020-02-18 Thread Jake Montgomery
> > The problem with that reasoning is that you could use it for anything and > then we would never improve any programming language or create others. > Ideally, the compiler will catch all the bugs it possibly can so that the > programmer can spend the thinking energy on resolving the problem.

[go-nuts] Re: QuickUnion slower than QuickFind : array lookup taking too long ?

2020-02-16 Thread Jake Montgomery
15, 2020 at 2:55:18 PM UTC-5, envee wrote: > > My apologies about syntax coloring. > Here is the createSlice function : > > func createSlice(n int) []int { > a := make([]int, n, n) > // initialize each element of the array to it's index value > for i := range a { > a[i

[go-nuts] Re: QuickUnion slower than QuickFind : array lookup taking too long ?

2020-02-15 Thread Jake Montgomery
On Saturday, February 15, 2020 at 6:24:02 AM UTC-5, envee wrote: > > Hi, > > I am using the following version of go : > PS C:\Temp> go version > go version go1.13.5 windows/amd64 > > I am trying to compare the performance of QuickUnion (just the basic one > with no weighting/ranking/path compressi

Re: [go-nuts] Question about the zero-value design: Why pointers zero value is not the zero value of what they points to?

2020-02-15 Thread Jake Montgomery
> > I see it is a nice property, but I'd say only for people writing the > compiler. I adventure [sic] to say that people using the language won't > care too much about this property. Having a useful zero-value (in this > case, an initialized pointer), like we have with strings for example, >

[go-nuts] Re: What are finalizers missing?

2020-02-15 Thread Jake Montgomery
On Friday, February 14, 2020 at 2:10:01 PM UTC-5, Tyler Compton wrote: > > The conventional wisdom I see in the Go community is to avoid using > finalizers to manage file descriptors, C memory, or any other non-Go memory > resource. The generally accepted rationale (at least to my understanding)

[go-nuts] Re: cmd/vet: "possible misuse of unsafe.Pointer" on C pointer -> uintptr -> different package -> unsafe.Pointer -> C pointer

2020-02-13 Thread Jake Montgomery
You need to read https://golang.org/pkg/unsafe/#Pointer *very, very, very* carefully before using unsafe.Pointer in any way. It spells out 6 conversions that are considered "valid". It says: "Code not using these patterns is likely to be invalid today or to become invalid in the future." AFAICT

[go-nuts] Re: Looking for some nicely broken image files (gif, png, and jpeg)

2020-02-13 Thread Jake Montgomery
This may be slightly tangential, but this seems like the kind of code that would benefit greatly from fuzz testing, like go-fuzz . For this kind of code, go-fuzz can really help harden it against bad, malformed and malici

Re: [go-nuts] Re: Checking if two map variables refer to the same map

2020-02-12 Thread Jake Montgomery
The playground is your friend: https://play.golang.org/p/p10XugRD4_z So, the answer is no. On Tuesday, February 11, 2020 at 6:56:05 PM UTC-5, Kevin Regan wrote: > > Would something like this work: > > m1 := make(map[string]string) > m2 := m1 > > if &m1 == &m2 { >... > } > > > On Tue, Feb 11, 2

Re: [go-nuts] Re: Why Discord is switching from Go to Rust

2020-02-10 Thread Jake Montgomery
runtime.GC() would not work for them. According to the docs - " GC runs a garbage collection and blocks the caller until the garbage collection is complete. It may also block the entire program." So that would be very counter productive in this case. On Monda

Re: [go-nuts] annoing: runtime error: cgo argument has Go pointer to Go pointer

2020-01-30 Thread Jake Montgomery
On Thursday, January 30, 2020 at 2:31:59 AM UTC-5, Andreas Otto wrote: > > > > Am Mittwoch, 29. Januar 2020 23:19:34 UTC+1 schrieb Bruno Albuquerque: >> >> One way to work this around is to use https://github.com/mattn/go-pointer >> . >> >> >> thanks, but also use this kind of "*HASH based and ex

Re: [go-nuts] JSON: Having trouble parsing map keys with dots like {"foo.bar":"baz"}

2020-01-28 Thread Jake Montgomery
FYI - "go vet" will catch this. Running "go vet" is always a good idea. On Tuesday, January 28, 2020 at 9:00:05 AM UTC-5, Lutz Horn wrote: > > Remove the blank in ``json: "baz.bar"` and make it `json:"baz.bar"`. This > works: https://play.golang.com/p/i9SURYgGO66 > >

Re: [go-nuts] Requesting help with the code

2020-01-27 Thread Jake Montgomery
On Monday, January 27, 2020 at 11:16:12 AM UTC-5, Sam Whited wrote: > > On Mon, Jan 27, 2020, at 02:41, Kareem Shaikh wrote: > > Can anyone please tell me what should I change in order to get the right > output? > > > > For example: > > > > I want to change 10 degrees to Fahrenheit. > > I

Re: [go-nuts] Unexpected evaluation order in a return statement with multiple operands

2020-01-16 Thread Jake Montgomery
I could not agree more with Axel's assessment, and wanted to emphisize it for any Go-noobs reading this. An important part of the go philosophy is to write code that is as clear and simple as possible. It is not about compact code, or 'clever' code. Code should be easy to understand, even when

[go-nuts] Re: A question !

2020-01-05 Thread Jake Montgomery
Welcome Motaz! This might be slightly OT from your question, but one big benefit of Go over Python for production code is that go is statically typed, and strongly typed. This may feel like a shackle at first, but it eliminates a whole universe of bugs, the kind that can strike without warning

[go-nuts] Re: os.RemoveAll of directory that contains long paths hangs

2020-01-04 Thread Jake Montgomery
FWIW, I was* unable to reproduce* this on Windows 7. Tried both a file and directory as the last part of the path. Otherwise, it was exactly as you specified. On Friday, January 3, 2020 at 12:50:22 PM UTC-5, Brian Samek wrote: > > I wanted to check here before I opened an issue. > > Given a Wi

[go-nuts] Re: net.conn TCP connection

2019-12-31 Thread Jake Montgomery
If you are really interested in how the Go code relates to the underlying socket system calls, the code is readily available. AFAICT, the TCPConn.Read() call *on linux* eventually comes down to the unix version poll.PD.Read(). See https://golang.org/src/internal/poll/fd_unix.go#L145. Before tha

[go-nuts] Re: net.conn TCP connection

2019-12-30 Thread Jake Montgomery
It sounds like maybe you have some misconceptions about TCP. It is a stream protocol, there are no data boundaries that are preserved. If send 20 bytes via TCP in a single call, it is *likely *that those 20 will arrive together at the client. But it is *NOT guaranteed*. It is perfectly legitimat

[go-nuts] Re: Simple worker pool in golnag

2019-12-28 Thread Jake Montgomery
The high level design discussions are great. But I want to point out that the code, as written, has a race related bug. When this line is called, the workerWg has a 0 count. go kafkaProducerWorkers(autoCancelChan, workerWg) It is entirely possible for the workerWg.Wait() line to be called be

[go-nuts] Re: net.conn TCP connection

2019-12-28 Thread Jake Montgomery
On Friday, December 27, 2019 at 10:36:28 PM UTC-5, Ron Wahler wrote: > > I did look at ReadAll, but it won't return until it sees EOF. I am trying > to find something that would return when the standard read would return. I > get the memory part and would manage that. Any other ideas ? > Its un

[go-nuts] Re: Way to handle errors in goroutine. Is this safe?

2019-12-07 Thread Jake Montgomery
As Ian pointed out, the code you provided has a race condition. Using timers to try to avoid a race like you do here may work *most *of the time, but it is not rigorously correct. When dealing with concurrency is is critical to always be 100% rigorusly "correct". Otherwise you will eventually

Re: [go-nuts] Multiple processes in parallel for cgo service

2019-12-07 Thread Jake Montgomery
Nitish, I don't think you really explained the problem you are having. There is nothing in go that prevents you from running multiple instances of an executable, hence creating multiple processes running the same program. You can simply open two console windows and start the same long runnin

[go-nuts] Re: Enforce immutability through static analysis

2019-11-22 Thread Jake Montgomery
I'm afraid your question is a bit confusing, which may account for some of the responses you have received so far. Here is what I think you are asking for. You want to define an interface which *your *package will use, and *other *packages will implement. You want to put restrictions on what the

Re: [go-nuts] Should I return an error object, or a pointer to an error object?

2019-11-14 Thread Jake Montgomery
On Wednesday, November 13, 2019 at 3:22:56 PM UTC-5, Brian Candler wrote: > > > the current implementation of interfaces is that they always store > pointer > > values. If you store a non-pointer value in an interface, that value > > is copied into memory, and a pointer to that memory is stored

Re: [go-nuts] strict type assignability to prevent arbitrary values

2019-11-08 Thread Jake Montgomery
The inability to have a type safe enum in Go has bothered me as well. While using a struct, as Peter suggests, does prevent accidental use of literals, it also prevents you from making your enum items constant.This means that the values can be changed, accidentally, or intentionally, in anothe

Re: [go-nuts] How to kill running function from core golang libraries

2019-11-01 Thread Jake Montgomery
On Friday, November 1, 2019 at 10:30:50 AM UTC-4, Shulhan wrote: > > > On Fri, 1 Nov 2019, 21:07 burak sarac, > > wrote: > >> I have a go routine running something like 'hash.sum(data)' using import >> "hash" that I want to terminate immediately in case of user wants to >> kill, I can not send

[go-nuts] Re: Automatically releasing memory resources allocated in cgo?

2019-11-01 Thread Jake Montgomery
Ian's advice seems sound. But there is one other option to consider. When practical, I like to simply copy C allocated memory to Go allocated memory in the wrapper for the cgo call, and free the C memory immediately. This removes the insanity of keeping track of C memory in Go. Obviously there

[go-nuts] Re: errors custom As

2019-10-24 Thread Jake Montgomery
I have not done much with the new errors stuff, but I'll try to help. I assume you have read https://github.com/golang/go/wiki/ErrorValueFAQ and https://blog.golang.org/go1.13-errors. There may be other posts as well. These new error functions, Is() and As() are about error types. It looks l

[go-nuts] Re: JSON encoder does not use custom TextMarshaler for map keys when the map key type is a custom string type

2019-10-24 Thread Jake Montgomery
Just a friendly reminder. When sending code to this list, please use a link to the Go playground or use plain text. The colored text with a black background is unreadable. Thanks. On Wednesday, October 23, 2019 at 11:45:24 PM UTC-4, Barakat Barakat wrote: > > I'm using macOS Mojave, go 1.12.4 >

[go-nuts] Re: About package lxn/walk

2019-10-10 Thread Jake Montgomery
Welcome Max, First a tip. It is easier for people to view your code samples if you post them in the playground . Even though this code will not run in the playground, due to the imports, its a nice way for people to quickly see what you are talking about. The code y

[go-nuts] Re: Interface method return other interface?

2019-10-09 Thread Jake Montgomery
It is a generally accepted best practice in go to "accept interfaces and return structs". Just google "golang accept interfaces return structs". However, there are absolutely times when it is ok, or even necessary, to return an interface. They key to to read some of the articles about the pract

Re: [go-nuts] Channels may not be the best solution in Go

2019-10-04 Thread Jake Montgomery
JuciÊ, I'm not going to endorse or dispute you assertions in the general case. But, I do want to point out that the OP started with "I've been working on a math library". It then provides a link to the library on github. It may be a matter of personal choice and style when writing an applicati

Re: [go-nuts] Use of NoMethod type for custom marshaling

2019-09-15 Thread Jake Montgomery
On Sunday, September 15, 2019 at 1:26:06 AM UTC-4, Sathish VJ wrote: > > Yes, that makes sense. Thank you. > > The example I wrote was concocted. But I've seen others do it on their > own types too, which didn't make sense at all. Maybe they were just > copy-pasting similar code from elsewhere

[go-nuts] Re: CPU profiling with pprof

2019-09-07 Thread Jake Montgomery
I can not speak to your specific issues, but I would point out that the link you referenced as "the documentation of the profiling", is not the technical documentation. It is simply an informative blog post. It was also written in 2011 and last updated in 2013. Given those two things, I would

[go-nuts] Re: What did you see at GopherCon 2019 (San Diego)?

2019-09-03 Thread Jake Montgomery
Yay! Thanks for the heads up. On Tuesday, September 3, 2019 at 8:09:45 AM UTC-4, Akram Ahmad wrote: > > To everyone who has (patiently) been biding time, your wait is finally > over—The video recordings of the talks at GopherCon 2019 are now available > at the following coordinates: GopherCon 20

[go-nuts] Re: Closed channel vs nil channel when writing

2019-09-02 Thread Jake Montgomery
On Monday, September 2, 2019 at 9:41:54 AM UTC-4, T L wrote: > > https://go101.org/article/channel.html > That is a great, and pretty detailed article. For quick reference I like https://dave.cheney.net/2014/03/19/channel-axioms . -- You received this message because you are subscribed to the