[go-nuts] Re: Creating and Accessing DLL methods in GO

2022-09-29 Thread Brian Candler
My first reaction is, do you *really* want to call a Go DLL from a Go main program? It seems to me like you will have two active copies of the Go runtime with their own garbage collectors etc. Go "plugins" might be closer to what you need:

[go-nuts] Re: Question on 'src/internal/singleflight': The return result of the ForgetUnshared method seems to be inaccurate

2022-09-23 Thread Brian Candler
On Friday, 23 September 2022 at 03:23:29 UTC+1 atomic wrote: > Thank you so much, so happy, you are amazing. > You answered a question that has been bothering me for days Thank you for providing a carefully isolated and reproducible problem. It was a fun challenge! And thanks to Cuong for

[go-nuts] Re: Question on 'src/internal/singleflight': The return result of the ForgetUnshared method seems to be inaccurate

2022-09-22 Thread Brian Candler
@@ -121,6 +124,7 @@ return true } if c.dups == 0 { +c.forgotten = true delete(g.m, key) return true } On Thursday, 22 September 2022 at 23:16:22 UTC+1 Brian Candler wrote: > OK, I think I have it. It's ugly. > > Firstly, note that multiple i

[go-nuts] Re: Question on 'src/internal/singleflight': The return result of the ForgetUnshared method seems to be inaccurate

2022-09-22 Thread Brian Candler
els (those you started in steps 4 and 5 above) 10. The select { case res := <-ch } triggers in the *other* goroutine - the one which didn't have a timeout. Hence it receives the error, and that's where you panic(). On Thursday, 22 September 2022 at 20:37:07 UTC+1 Brian Candler wrote: > OK

[go-nuts] Re: Question on 'src/internal/singleflight': The return result of the ForgetUnshared method seems to be inaccurate

2022-09-22 Thread Brian Candler
OK, I see where you're coming from - and I agree, this is a difficult one! The point you were making is that if g.ForgetUnshared(key) { cancel() } should only invoke cancel() if this result

[go-nuts] Re: Question on 'src/internal/singleflight': The return result of the ForgetUnshared method seems to be inaccurate

2022-09-21 Thread Brian Candler
Notice that DoChan starts a goroutine for the task... go g.doCall(c, key, fn) ... and then returns immediately. Also notice that the random time you pick for cancelTime can be longer than the different random time you sleep inside the goroutine (i.e. the function which you pass to

[go-nuts] Re: regex extract with group

2022-09-20 Thread Brian Candler
Can you show your Go code, including the failing test data? Using https://go.dev/play/ is best. If you're using the built-in re2 library, its regular expressions are documented here: https://github.com/google/re2/wiki/Syntax Not all regular expression libraries are the same, and this table

[go-nuts] Re: Question on 'cmd/compile: handle partially overlapping assignments' behavior on ARM64.

2022-09-20 Thread Brian Candler
On Tuesday, 20 September 2022 at 16:24:41 UTC+1 peterGo wrote: > I am unable to reproduce your results on AMD64. I don't see any regression. That's expected: the original post also said "I don't see the [...] the perfromance degradation on AMD64". The report is specific to ARM64. -- You

[go-nuts] Re: Using golang variable in bash script Command

2022-09-19 Thread Brian Candler
On Monday, 19 September 2022 at 10:50:36 UTC+1 princ...@gmail.com wrote: > > *search:=scanner.Text()cmd1,err:=exec.Command("bash", "-c", "find . -name > '*$search*'")* You first "search" is a go local variable. Your second "$search" is seen by the shell as a reference to an environment

[go-nuts] Re: Gothon Library to simulate useful Python methods

2022-09-05 Thread Brian Candler
On Monday, 5 September 2022 at 09:12:53 UTC+1 harald@gmx.net wrote: > small note here about the package naming -- to be taken with a larger > grain of salt, as usual: you repeat and thus "stutter" on > "Gothon/gothonSlice". I've looked into some existing slice generics > examples that now

[go-nuts] Re: Why not judge the status of response in getting module?

2022-09-02 Thread Brian Candler
On Friday, 2 September 2022 at 08:34:36 UTC+1 wangshan...@gmail.com wrote: > Now that you say that I can sort of understand the design in the source > code. Repository supports either HTTPS or HTTP, otherwise golang does not > handle it to reduce the complexity of the problem. > > I'd say it's

[go-nuts] Re: Why not judge the status of response in getting module?

2022-09-02 Thread Brian Candler
I think the issue is very unlikely to be HTTP/HTTPS as you suggest. What you seem to be saying is: - a request to https://yourdomain.com/foobar returns "404 not found" - a request to http://yourdomain.com/foobar would return the data of interest If that were the case, Go package fetching

[go-nuts] Re: How long does it take to import packages?

2022-08-31 Thread Brian Candler
"import" and const calculations are compile-time activities, whereas init() and global var assignment are run-time activities. How does the time to compile your code to an executable, compare to running the tests? If compiling the code is fast but running the tests is slow, that rules out any

[go-nuts] Re: the difference between type and type address in struct

2022-08-28 Thread Brian Candler
Another difference is that the *dog value in type A may be nil, meaning "no dog" - indeed, this is the default (zero) value of a pointer. Attempting to follow (deference) such a nil pointer, in other words trying to access the dog value that it points to, will result in a panic. On Sunday, 28

Re: [go-nuts] How to cross-compile Go 1.19 compiler for Solaris 11 on Linux

2022-08-27 Thread Brian Candler
On Saturday, 27 August 2022 at 17:10:21 UTC+1 Shane wrote: > Is it expected that linux_syscall.c would be compiled when the GOOS > environment variable is set to solaris? I see the log output does include this line: Building packages and commands for host, linux/amd64. Although I'm not sure

Re: [go-nuts] Is Go a security malware risk?

2022-08-23 Thread Brian Candler
On Tuesday, 23 August 2022 at 16:49:57 UTC+1 ren...@ix.netcom.com wrote: > I think what is being suggested that if the sec team bans all applications > that exhibit dynamic code loading behavior they’d be safer - which would > catch a lot of apps in the net. > But the article quoted makes the

Re: [go-nuts] Is Go a security malware risk?

2022-08-23 Thread Brian Candler
On Tuesday, 23 August 2022 at 15:30:49 UTC+1 Gopher-Insane wrote: > The issue is not a vulnerability in the language itself but the use of > that language to embed malware so AV signatures do not detect it. The > feeling is that our InfoSec will be wanting to restrict obscure languages > (Go,

[go-nuts] Re: Go multiplexers

2022-08-21 Thread Brian Candler
"conn" is just a value, you can pass it around. However, if you're sharing it between multiple goroutines you need to be careful, i.e. you need to synchronize properly. The synchronization solutions are very specific to your application: e.g. you could wait for that goroutine to finish with a

Re: [go-nuts] Go multiplexers

2022-08-21 Thread Brian Candler
> Can you tell me how I can figure out what it speaks? Finding that information doesn't appear to be hard: https://github.com/hashicorp/yamux#specification "The full specification for Yamux is provided in the spec.md file. It can be

[go-nuts] Re: Why declaring multiple variable at once for same type feature exists in Golang?

2022-08-18 Thread Brian Candler
August 2022 at 17:35:21 UTC+1 Brian Candler wrote: > What exactly is it about that expression that you don't think seems right? > > It's a shortcut for: > > var x string > var y string > var z string > > I think that saving typing is a good feature. > > Or do y

[go-nuts] Re: Why declaring multiple variable at once for same type feature exists in Golang?

2022-08-18 Thread Brian Candler
What exactly is it about that expression that you don't think seems right? It's a shortcut for: var x string var y string var z string I think that saving typing is a good feature. Or do you object to the feature of being able to declare variables at all? On Thursday, 18 August 2022 at

Re: [go-nuts] Application Monitoring

2022-08-17 Thread Brian Candler
The go prometheus client exposes a set of metrics about the go runtime, primarily around memory allocation, in addition to any that your application itself may choose to create. e.g. # HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles. # TYPE

Re: [go-nuts] Go generics and bloating

2022-08-17 Thread Brian Candler
les of that type: func (e Plus[a]) Eval() int { var left a = e.left var right a = e.right return any(left).(Evaler).Eval() + any(right).(Evaler).Eval() } On Wednesday, 17 August 2022 at 09:50:29 UTC+1 axel.wa...@googlemail.com wrote: > On Wed, Aug 17, 2022 at 10:43 AM B

Re: [go-nuts] Go generics and bloating

2022-08-17 Thread Brian Candler
On Tuesday, 16 August 2022 at 21:15:03 UTC+1 axel.wa...@googlemail.com wrote: > You are looking for "Featherweight Go", I believe. > https://arxiv.org/abs/2005.11710 > That's an interesting paper - at least the early parts that I could understand! I tried converting

[go-nuts] Re: Generics types not inferred correctly on type switch cases

2022-08-09 Thread Brian Candler
ow this situation could be overcome > without explicitly defining the parameter's type. Maybe posting a proposal? > On Tuesday, August 9, 2022 at 2:16:05 PM UTC+3 Brian Candler wrote: > >> Example of type inference in action: >> https://go.dev/play/p/pL7_8zaFIZN >> >&g

[go-nuts] Slightly confusing error with type parameters

2022-08-09 Thread Brian Candler
I don't know if there's much that can be done about this, but thought I'd mention it anyway. Suppose you're trying to make a parameterised type, like type Elem[T any] blah... ex: https://go.dev/play/p/1tS1SCxTFP- but you forget the "any", and just write type Elem[T] blah... ex:

[go-nuts] Re: Generics types not inferred correctly on type switch cases

2022-08-09 Thread Brian Candler
hat: hence for heterogenous slices you're stuck with interface types (including "any", which is a shortcut for the empty interface, "interface {}") On Tuesday, 9 August 2022 at 11:53:11 UTC+1 Brian Candler wrote: > As far as I can see, the problem isn't anything to do with gene

[go-nuts] Re: Generics types not inferred correctly on type switch cases

2022-08-09 Thread Brian Candler
As far as I can see, the problem isn't anything to do with generics, but with this line alone: input := []any{[]float32{1.0, 2.0}, 1.1} See: https://go.dev/play/p/gUqmUb-Vs_y You've made a slice with mixed elements. One happens to be a slice of float32's, and the other happens to be a

[go-nuts] Re: Short destination error with unicode.Transform

2022-07-30 Thread Brian Candler
If this is non-repeatable then perhaps it is some sort of race? Have you tried running your code with the race detector enabled? On Saturday, 30 July 2022 at 03:01:39 UTC+1 j...@simplecircle.io wrote: > I had a curious bug appear in my server logs when using a unicode > Transformer: > >

Re: [go-nuts] Re: Basic question on Channels

2022-07-27 Thread Brian Candler
the reader is ready to receive." . So an > unbuffered channel does not have the same behaviour as a buffered channel > of size 1, fair. > > I understand part about the waitGroup, I copy pasted code used to tutor > the newcomers to programming itself. > > On Wed, Jul 27,

[go-nuts] Re: Basic question on Channels

2022-07-27 Thread Brian Candler
2022 at 08:30:53 UTC+1 Brian Candler wrote: > Unless a channel is buffered, it is synchronous. A send cannot take place > until the reader is ready to receive. > > You can make it buffered using > numCh = make(chan int, 1) > go write() > go read() > > Or you

[go-nuts] Re: Basic question on Channels

2022-07-27 Thread Brian Candler
Unless a channel is buffered, it is synchronous. A send cannot take place until the reader is ready to receive. You can make it buffered using numCh = make(chan int, 1) go write() go read() Or you can have two calls to read(): numCh = make(chan int) go write() go

[go-nuts] Re: go vet configuration? to check variant of printf having to do with verbs

2022-07-26 Thread Brian Candler
Instead of a closure, could you put loopCnt and errCnt in a struct, and then make your loopErrMsg be a method on that? On Tuesday, 26 July 2022 at 16:03:01 UTC+1 gocss wrote: > also found this so it is a known limitation: > https://github.com/golang/go/issues/44350 > > On Tuesday, July 26, 2022

[go-nuts] Re: Print a json item wit a for loop

2022-07-25 Thread Brian Candler
You haven't said what you're trying to do, and the error tells you that p doesn't have a field called "jitem". Perhaps what you are trying to do is to extract a member from a structure dynamically: that is, jitem is the *name* of a struct member, only known at runtime? In that case, you can

[go-nuts] Re: Best way of implementing generic binary search?

2022-07-19 Thread Brian Candler
You don't need a compare method on your type. You can just pass a func(T, T) bool to your search function. In fact, the standard library already has this, except implemented in terms of slice indexes only, rather than a slice of generic type. https://pkg.go.dev/sort#Search You could always

[go-nuts] Re: how to minimize the size of struct?

2022-07-13 Thread Brian Candler
In every system that I'm familiar with, the alignments are all powers of 2. If you think of this as a kind of bin packing problem with different sized bins, then every large bin can always be split into 2 bins of half the size. Therefore, if something fits into a small bin, you can't possibly

Re: [go-nuts] Do I need a reentrant locks?

2022-07-06 Thread Brian Candler
On Wednesday, 6 July 2022 at 11:33:29 UTC+1 ren...@ix.netcom.com wrote: > As I said, make the mutating op simply record the desired op on a queue > and process the serially on another thread. You are essentially > implementing transactions. > But how do you protect tree *readers* from having

[go-nuts] Re: Do I need a reentrant locks?

2022-07-05 Thread Brian Candler
Have a public Set() that does the lock and then calls a private internal function, which assumes it's already running under the lock. https://go.dev/play/p/M1XuC8bxCxL On Tuesday, 5 July 2022 at 13:32:26 UTC+1 atd...@gmail.com wrote: > Hi, > > I have a tree datastructure where mutating some

Re: [go-nuts] Temporary prevent preemption?

2022-06-29 Thread Brian Candler
Vice-versa. Asynchronous preemption is when the goroutine is *not* waiting in a syscall, but is performing computations. If it spends too much time working, it will be kicked off and another goroutine given a chance to run on the same thread. On Wednesday, 29 June 2022 at 17:24:21 UTC+1 TH

Re: [go-nuts] Generic interface compiles with incorrectly instantiated types

2022-06-22 Thread Brian Candler
On Tuesday, 21 June 2022 at 21:19:29 UTC+1 tsvihb...@gmail.com wrote: > I'm now realizing that even that wouldn't fully behave as I wanted because > it doesn't account for nil values, so I'll have to figure out a better > solution. For a "Maybe" type specifically, the nil interface value

Re: [go-nuts] Generic interface compiles with incorrectly instantiated types

2022-06-21 Thread Brian Candler
Maybe it's clearer if you simplify Wrap[A] to just Wrap, since they are identical. https://go.dev/play/p/aJReo5lp2Yg Then it's clear that the parameter "w Wrap" to func Extract is just a plain old interface type, unrelated to generics. Dynamically at runtime it can be nil, or a value of any

Re: Private message regarding: [go-nuts] How to return concrete implementation to satisfy interface

2022-06-20 Thread Brian Candler
If you're new to Go, beware of one thing when returning interface values which are implemented by pointers. An interface value can be nil (i.e. the zero value of interface: no type and no value); or it can contain a concrete value a concrete pointer type - where the concrete value itself is

[go-nuts] Re: generics compile error: struct does not match interface, cannot infer type

2022-06-20 Thread Brian Candler
fic use case calling it like "interfaceFunc[T](x)" generically without >> being specific like "[string]", wondering why the compiler's inference is >> like that? is it a flaw or just a limitation of the concept per se? >> >> On Monday, June 20, 2022 at

[go-nuts] Re: generics compile error: struct does not match interface, cannot infer type

2022-06-20 Thread Brian Candler
Type inference doesn't work in all cases. When required, just be explicit: interfaceFunc[string](x) https://go.dev/play/p/j66sXsfMUBl On Monday, 20 June 2022 at 13:06:57 UTC+1 Mike Andrews wrote: > anyone know why this simple case doesn't compile? i'm trying to call a > function

[go-nuts] Re: Can't read >32KBytes from http response body.

2022-06-20 Thread Brian Candler
1. What's the web server you're connecting to? (Is it written in go, and if so, can you share it?) 2. What happens if you use io.Read instead of io.ReadAtLeast? 3. What happens if you remove the time.Sleep()? (Maybe the target webserver has a timeout which requires the transaction to be

[go-nuts] Re: Unmarshal semi-structured json data

2022-06-16 Thread Brian Candler
You should start here: https://pkg.go.dev/encoding/json You *can* just unmarshall into a generic interface{} variable and then use type assertions as necessary to coerce: https://go.dev/play/p/b1lCJlGPwLO However, I suggest that if the structure is known in

[go-nuts] Re: Making concurrent programs to run parallely in Go

2022-06-15 Thread Brian Candler
As I understand, it will execute in parallel by default. There's a pool of threads for running goroutines, defaulting initially to the number of cores. If a syscall blocks, then other threads will continue to run - and (I think) an extra thread is started too. > But still I had to use

[go-nuts] Re: goroutine benchmark results interpretation for anonymous func?

2022-06-13 Thread Brian Candler
On Monday, 13 June 2022 at 01:55:11 UTC+2 Const V wrote: > The way I'm using is "b" is a large buffer - hundreds of MB. > I want to stop processing after the string is found using "quit". > > for i := 0; i < cores; i++ { > go func(start, end, i int, quit chan string) { >

[go-nuts] Re: goroutine benchmark results interpretation for anonymous func?

2022-06-12 Thread Brian Candler
) >}(start, end, i, quit) > > On Sunday, June 12, 2022 at 2:54:51 AM UTC-7 Brian Candler wrote: > >> On Sunday, 12 June 2022 at 09:16:30 UTC+1 Const V wrote: >> >>> go func(start, end, i int, quit chan string) { >>> BytesContainsCh1(b.Bytes(), start, end, fi

[go-nuts] Re: goroutine benchmark results interpretation for anonymous func?

2022-06-12 Thread Brian Candler
On Sunday, 12 June 2022 at 09:16:30 UTC+1 Const V wrote: > go func(start, end, i int, quit chan string) { > BytesContainsCh1(b.Bytes(), start, end, find, ch) >}(start, end, i, quit) > I note that this could be further simplified to: go BytesContainsCh1(b.Bytes(), start, end, find,

Re: [go-nuts] Help with sync.Cond failing to signal

2022-06-12 Thread Brian Candler
And just as an aside, I think you would be interested in the talk "Rethinking Classical Concurrency Patterns" by Bryan C. Mills https://www.youtube.com/watch?v=5zXAHh5tJqQ On Sunday, 12 June 2022 at 05:06:47 UTC+1 ke...@burke.dev wrote: > That's a very clear explanation, it's obvious what the

Re: [go-nuts] encoding/asn1 overly strict?

2022-06-10 Thread Brian Candler
On Friday, 10 June 2022 at 14:31:10 UTC+1 Andreas Götz wrote: > On Thursday, June 9, 2022 at 6:44:58 PM UTC+2 Brian Candler wrote: > >> I forgot to add one thing, and you didn't paste the whole certificate PEM >> so I can't check this. >> >> Recent versions of G

[go-nuts] Re: Implementation for Copy-On-Write

2022-06-09 Thread Brian Candler
You can trim most of it out. Instead of the 'insert' func, just m.Store() the new value. But that isn't Copy-On-Write. This is simply replacing the value in a variable with another value. Anybody who read out the old value, still has their copy of the old value, probably stored in some

Re: [go-nuts] encoding/asn1 overly strict?

2022-06-09 Thread Brian Candler
sure it also includes a DNS SAN, if it doesn't already. It doesn't matter if it's just a string like "EEBUS"; you can specify the ServerName at connection time. On Thursday, 9 June 2022 at 17:38:04 UTC+1 Brian Candler wrote: > On Thursday, 9 June 2022 at 14:27:04 UTC+1 cpu...@gm

Re: [go-nuts] encoding/asn1 overly strict?

2022-06-09 Thread Brian Candler
On Thursday, 9 June 2022 at 14:27:04 UTC+1 cpu...@gmail.com wrote: > We receive an alert 40 (Handshake failure ) when using openssl. So the > cert is definitively faulty in some way. > > :~/wallbox/hack$ openssl s_client -connect 192.168.1.180:4712 > Certainly it will report a failed

Re: [go-nuts] encoding/asn1 overly strict?

2022-06-08 Thread Brian Candler
On Wednesday, 8 June 2022 at 10:09:26 UTC+1 cpu...@gmail.com wrote: > We've not found an approach for communicating with the device sofar unless > using patched Go stdlib. > Connect via a proxy like stunnel? Out of interest, does raw "openssl s_client" allow communication with the device? It

Re: [go-nuts] Nil could be the zero value for type variables

2022-06-02 Thread Brian Candler
On Wednesday, 1 June 2022 at 08:49:50 UTC+1 axel.wa...@googlemail.com wrote: > Where confusion might arise is in the operations on nil. It's already >> weird that nil slices and zero-length slices are distinguishable: >> https://go.dev/play/p/6MVECg4onAk >> >> We'd then end up in the same

Re: [go-nuts] Nil could be the zero value for type variables

2022-06-01 Thread Brian Candler
On Wednesday, 1 June 2022 at 02:19:43 UTC+1 Ian Lance Taylor wrote: > We could do that. The main concern is that "nil" is already > overloaded, and people new to Go are frequently confused by it. See > the FAQ entry https://go.dev/doc/faq#nil_error . Adding more uses of > nil will increase the

Re: [go-nuts] Improving safe global variables with generic or inheritance

2022-05-23 Thread Brian Candler
@gmail.com wrote: > -- Forwarded message - > From: Zhaoxun Yan > Date: Mon, May 23, 2022 at 6:05 PM > Subject: Re: [go-nuts] Improving safe global variables with generic or > inheritance > To: Brian Candler > > *That's really essential. For example, using your library,

Re: [go-nuts] Improving safe global variables with generic or inheritance

2022-05-23 Thread Brian Candler
> It's best to be intentional about it and explicitly acquire and release a mutex around the critical sections of your code - because ultimately, only your code knows which sections are critical. That's really essential. For example, using your library, the following code is most definitely

[go-nuts] Re: map update in Gin framework. Does it needs mutex?

2022-05-22 Thread Brian Candler
The race detector doesn't prove the absence of races - it only demonstrates they exist when the conditions are there. You need to generate HTTP client load such that multiple instances of /adding are invoked concurrently. Most certainly your program *will* panic if there are two threads

Re: [go-nuts] Re: A patch to avoid point-time race coincidence like Rust

2022-05-05 Thread Brian Candler
Correct. a := make(map[int]string) b := a means that b and a point to the same map. > Do you know any way in go to copy a map? Or the only way to do it is to use json Marshal and Unmarshal? That is called a "deep copy" and there are third party libraries for this. But if you think

[go-nuts] Re: A patch to avoid point-time race coincidence like Rust

2022-05-01 Thread Brian Candler
On Sunday, 1 May 2022 at 11:45:28 UTC+1 Brian Candler wrote: > get rid of the global variables. Use channels instead. Share memory by > communicating; don't communicate by sharing memory. > https://www.youtube.com/watch?v=PAAkCSZUG1c=168s http://go-proverbs.github.io/ -- You

[go-nuts] Re: A patch to avoid point-time race coincidence like Rust

2022-05-01 Thread Brian Candler
On Sunday, 1 May 2022 at 07:04:34 UTC+1 yan.z...@gmail.com wrote: > Any advice? > If the value you are trying to read and update is int32 or int64, you can use the sync.Atomic package. However, if you feel you need to do this all the time, I can't help but

[go-nuts] Re: x/crypto/ssh client.NewSession: Provide initial data or an already open channel?

2022-04-26 Thread Brian Candler
> Session doesn't export the underlying channel either, so opening a channel and directly initializing the Session isn't an option Because it isn't meaningful to do this. As far as I understand it, a session is a type of channel. When you want to open a session, actually you open a channel of

Re: [go-nuts] Any recipe to stop a goroutine of a function other than of a channel?

2022-04-16 Thread Brian Candler
For TCP sockets, there's SetDeadline, SetReadDeadline and SetWriteDeadline. See https://pkg.go.dev/net For the originally posted code, I would replace time.Sleep(5 * time.Second) with code which either waits 5 seconds, or terminates on a shutdown signal if that is received first. The

[go-nuts] Re: MatrixOne: a hyperconverged and one-size-fits-most database in Go

2022-04-16 Thread Brian Candler
On Friday, 15 April 2022 at 17:47:48 UTC+1 nicolas...@gmail.com wrote: > any feedback is welcome. > The only feedback I can give is from your reading your documentation, which appears at this point to be very vague. I was looking for a proper architectural white paper that says exactly what

Re: [go-nuts] Re: Protective buffered channel that never triggers deadlock

2022-04-15 Thread Brian Candler
On Friday, 15 April 2022 at 08:31:17 UTC+1 yan.z...@gmail.com wrote: > Thanks for your demonstration, Brian. > Actually my code involving cgo is quite like your first case, like this > code: > > *log("start testing")* > *go func{* > * for* > * select* > * case a: <=receiving* > *

Re: [go-nuts] Re: Protective buffered channel that never triggers deadlock

2022-04-15 Thread Brian Candler
On Friday, 15 April 2022 at 06:47:09 UTC+1 yan.z...@gmail.com wrote: > When one server finds something wrong, it sends out a request to another > server for help. > Then it makes a log and then a ticker to recheck the situation again and > again and in the meantime, to receive a response from

Re: [go-nuts] encoding/json mistakenly transfer int64 format to string

2022-04-14 Thread Brian Candler
:14 UTC+1 michael...@gmail.com wrote: > @Brian > That example is a superbly concise explanation go mod. Thanks! And I had > no idea you could specify filenames and modules in the Playground. That's > really useful! > > On Wednesday, April 13, 2022 at 3:11:54 AM UTC-4 Brian Cand

Re: [go-nuts] Re: Protective buffered channel that never triggers deadlock

2022-04-14 Thread Brian Candler
The fact that the sender may have to wait does not by itself make a "deadlock". It's a deadlock if the sender blocks and, due to poor programming, the receiver is *never* ready to receive. That's a problem with your software, not with Go's concept of channels. Blocking on send until the

[go-nuts] Re: No downloadable go1.18.1 version for darwin

2022-04-13 Thread Brian Candler
It's mentioned in the original announcement : "macOS binary artifacts for Go 1.18.1 are not available at this time due to an issue . We are working on providing them as soon as possible. Sorry for

[go-nuts] Re: Ignore data race

2022-04-13 Thread Brian Candler
"There is no such thing as a benign data race" https://docs.google.com/document/d/1WAT22FtFdMt43i3O8YrnlQTNTzZ3IoJBtu3P2DNRytg/ # was originally: https://software.intel.com/en-us/blogs/2013/01/06/benign-data-races-what-could-possibly-go-wrong On Wednesday, 13 April 2022 at 14:46:34 UTC+1

[go-nuts] Re: Protective buffered channel that never triggers deadlock

2022-04-13 Thread Brian Candler
> I made up a work around that just dumps the new message if the buffer is full: You don't need to do that: use select { ... } to check if the channel is ready to receive or not. https://go.dev/play/p/Mb7VVCTvnfk But in practice, this is almost never needed, because one goroutine is doing the

Re: [go-nuts] encoding/json mistakenly transfer int64 format to string

2022-04-13 Thread Brian Candler
> I am a little bewildered by the new mod configuration. It's as simple as this: go mod init blah go mod tidy You can put anything(*) for "blah". Literally "blah" will work. It's just whatever name you want to give your module. However if you plan to publish your module on github then using

[go-nuts] Re: Constant CPU usage on an idle HTTP server from Go 1.17

2022-04-12 Thread Brian Candler
basic example the nanosleep calls maybe is >> not the scheduller signaling itself because: >> >> - GODEBUG=asyncpreemptoff=1 has no effect >> - It doesn't happen with Go 1.16 >> - It is random. If it where the normal working of the scheduler, >> wouldn't it be predicta

[go-nuts] Re: Constant CPU usage on an idle HTTP server from Go 1.17

2022-04-12 Thread Brian Candler
ge because this behaviour was >> introduced in Go 1.14 and I only see it in Go 1.17. Also asyncpreemptoff=1 >> seems to make no difference. >> >> I am going to work again with Go 1.18 by default to see if I get the 100% >> CPU usage. >> >> El lunes, 11 de abr

[go-nuts] Re: Constant CPU usage on an idle HTTP server from Go 1.17

2022-04-11 Thread Brian Candler
On Monday, 11 April 2022 at 09:26:28 UTC+1 scorr...@gmail.com wrote: > and the output keeps growing like that with every new curl request until > eventually it starts constantly printing output like this: > >> >> [pid 143818] 10:02:22.697120 nanosleep({tv_sec=0, tv_nsec=1000}, >> NULL) = 0

Re: [go-nuts] float exactness

2022-04-11 Thread Brian Candler
According to the go spec : "Constant expressions are always evaluated exactly; intermediate values and the constants themselves may require precision significantly larger than supported by any predeclared type in the language" Hence there's

[go-nuts] Re: Constant CPU usage on an idle HTTP server from Go 1.17

2022-04-11 Thread Brian Candler
Those nanosleep calls are at 10ms intervals - i.e. 100 calls per second. I think this is normal behaviour of the Go scheduler, which signals itself every 10ms to force a preemptive context switch. That feature was introduced in go 1.14, at which point you were able to disable it at runtime

Re: [go-nuts] Structured configuration in Go

2022-04-10 Thread Brian Candler
Cue (and jsonnet) come into their own when building large systems built out of multiple components; they can create configs for multiple applications derived from a shared top-level configuration. However, the applications themselves don't have to understand cue or jsonnet, since both those

Re: [go-nuts] Missing /usr/lib/go/pkg/include/ for native binaries

2022-04-09 Thread Brian Candler
Are you sure Debian didn't split it into multiple packages, like a separate "golang-src" package perhaps? On Friday, 8 April 2022 at 13:49:28 UTC+1 sunto...@gmail.com wrote: > On Fri, Apr 8, 2022 at 2:00 AM Jack Li wrote: > > > > Yes, I download the latest go 1.18 installer for macOS from >

[go-nuts] Re: TMTP messaging protocol

2022-04-07 Thread Brian Candler
Cross-ref to previous thread: https://groups.google.com/g/golang-nuts/c/PLPjo5w3zTg On Wednesday, 6 April 2022 at 22:06:28 UTC+1 Liam wrote: > TMTP is a protocol [1] to let Internet sites message customers/members > directly, instead of unreliable, insecure email or costly custom apps. > >

[go-nuts] Re: I cannot generate public keys in sequence.

2022-04-06 Thread Brian Candler
If you have a problem using the go-ethereum library then you're probably best asking at the tracker or discussion group for that software. However, the error message seems pretty clear: you're trying to pass a value of type []byte to a function which takes a string. You can convert one to the

[go-nuts] Re: Execution of goroutines

2022-04-06 Thread Brian Candler
> Is there maybe something blocking involved in http.Get()? Yes of course - first establishing a TCP connection across the network, then sending data over it and waiting for the response. Each of these is a point where the goroutine gets descheduled because it has nothing more to do; it's

Re: [go-nuts] Why is it forbidden to add methods to an existing type?

2022-04-06 Thread Brian Candler
; between two boundaries that do understand null values, such as bridging an > RPC frontend and a SQL backend. > > If anything, it proves that Generics do simplify codebases, and that > well-defined, graceful null/nil handling is worth the effort. > On Tuesday, April 5, 202

Re: [go-nuts] Why is it forbidden to add methods to an existing type?

2022-04-05 Thread Brian Candler
at you're dealing with, and if you actually check the error result, > you do get safety. If you don't know what you've got, or if you're > iterating through the values, then you end up hitting the sad, sad, > reflective path...for now. > On Saturday, April 2, 2022 at 4:37:36 AM UTC-

[go-nuts] Re: First time contribution, unsure whether I need to open an issue or direct CL

2022-04-03 Thread Brian Candler
On Sunday, 3 April 2022 at 16:49:30 UTC+1 mirha...@gmail.com wrote: > CombinedOutput example listed above will always print only stdout, but not > combined stdout and stderr as intended to be shown in the example. Works for me (macOS 10.12, go 1.18) If this doesn't work for you, it could be

Re: [go-nuts] Why is it forbidden to add methods to an existing type?

2022-04-02 Thread Brian Candler
com/jackc/pgtypes convinced me that the results > were worth it. The benefits: A, package interpretation methods with a > piece of data, B, lazily valuate data when needed, and C, gain > introspective capability specific to the type and not using reflect > On Friday, April 1, 2022 at 4

[go-nuts] Re: go mod tidy doesn't rewrite go.mod file (shows go: warning "all" matched no packages)

2022-04-01 Thread Brian Candler
to go1.18 >> >> On Friday, 1 April 2022 at 11:36:04 UTC+2 Brian Candler wrote: >> >>> Interesting. If I put that go.mod file in an empty directory, then I >>> see the warning: >>> >>> $ go mod tidy >>> >>> go: warning: "al

Re: [go-nuts] Why is it forbidden to add methods to an existing type?

2022-04-01 Thread Brian Candler
That wasn't literal code with anglebrackets - you're supposed to fill that in yourself. I think he meant something like: type fooString struct{ string } https://go.dev/play/p/4Q94xMZDciV What this is doing is *embedding* a string value into a struct; if you have not come across type

[go-nuts] Re: go mod tidy doesn't rewrite go.mod file (shows go: warning "all" matched no packages)

2022-04-01 Thread Brian Candler
20200804184101-5ec99f83aff1 // indirect > google.golang.org/protobuf v1.27.1 // indirect > ) > ``` > > But when I run `go mod tidy`, it simply prints out the aforementioned > warning and the new go.mod file looks like this: > > ``` > module module_name_obfuscated > > g

[go-nuts] Re: go mod tidy doesn't rewrite go.mod file (shows go: warning "all" matched no packages)

2022-03-31 Thread Brian Candler
Can you show the contents of the go.mod file in the directory where you run "go mod tidy"? > I get this error when I run `go list all` as well. Try "go list" rather than "go list all" (because in that context, "all" is interpreted as the name of a package) On Thursday, 31 March 2022 at

Re: [go-nuts] Why is it forbidden to add methods to an existing type?

2022-03-28 Thread Brian Candler
This works: n, _ := strconv.ParseInt(string(x), 10, 64) Go intentionally does no automatic type conversion, not even this: var a int32 = 1234 var b int64 = a// error: use int64(a) instead It would be inconsistent if passing "mystr" to a function which accepts

Re: [go-nuts] Unexpected order of global variable declaration during package initialization

2022-03-24 Thread Brian Candler
On Thursday, 24 March 2022 at 12:35:38 UTC tapi...@gmail.com wrote: > Aha, sorry, the file order really matters here. > But for this specified case, it should not. > > That's not right. I remembered in an issue thread, it is mentioned that > the order should be > > 1. D is not ready (because it

Re: [go-nuts] Unexpected order of global variable declaration during package initialization

2022-03-24 Thread Brian Candler
Ugh, quoting got broken there. $ go run rewritten_f1.go f2.go Init A Init B Init C 1 4 3 $ go run f2.go rewritten_f1.go Init A Init B Init C 1 2 1 Hopefully that will show properly. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To

Re: [go-nuts] Unexpected order of global variable declaration during package initialization

2022-03-24 Thread Brian Candler
On Thursday, 24 March 2022 at 12:15:16 UTC tapi...@gmail.com wrote: > BTW, the rewritten version outputs > > Init A > Init B > Init C > 1 4 3 > > On my machine (go1.18 linux/amd64). > It depends on the order, and the OP was positing what happens when f2.go is presented first to the

Re: [go-nuts] Unexpected order of global variable declaration during package initialization

2022-03-24 Thread Brian Candler
On Thursday, 24 March 2022 at 11:30:37 UTC tapi...@gmail.com wrote: > > 2. A < D < B < C - happens when f2.go is passed first to the compiler. > In this case, the *expected output *would be "1 2 1". However, the *actual > output* is "1 2 3". > > This is not true by my understanding of the spec.

Re: [go-nuts] Looked at using Go ... nil/SEGV really bothered me .. Go2 Proposal?

2022-03-24 Thread Brian Candler
The OP hasn't said specifically which language or feature they're comparing with, but I wonder if they're asking for a pointer type which is never allowed to be nil, enforced at compile time. If so, a normal pointer-which-may-be-nil would have to be represented as a Maybe[*T] or union { *T |

[go-nuts] Re: When will the official encoding/json package support parsing json5?

2022-03-20 Thread Brian Candler
If you're going down that route, you could also consider jsonnet (which does have a Go implementation ) It will almost certainly be much more powerful than you need, but it *is* another superset of JSON which includes comments. On

<    1   2   3   4   5   6   7   8   >