Re: [go-nuts] Re: Call the .net dlls into the golang

2024-05-23 Thread 'Brian Candler' via golang-nuts
"try building at the command line" That's your clue. You'll most likely get a meaningful error message on stderr, which your IDE is hiding. On Thursday 23 May 2024 at 13:47:10 UTC+1 Pavan Kumar A R wrote: > Hello , > > I am try to call the c program in the golang , but i am getting the issue

Re: [go-nuts] Errors trying to use external pkg z3

2024-05-22 Thread 'Brian Candler' via golang-nuts
* Start in an empty directory * Run "go mod init example" * Create your main.go with that import statement in it * Run: go mod tidy go run . On Wednesday 22 May 2024 at 16:26:54 UTC+1 Kenneth Miller wrote: > I tried that, same error > > On Wednesday, May 22, 2024 at 9:12:58 AM UTC-6 Brian

Re: [go-nuts] Errors trying to use external pkg z3

2024-05-22 Thread 'Brian Candler' via golang-nuts
It's because the name of the module is "github.com/aclements/go-z3/z3", not "z3" Only packages in the standard library have short names, like "fmt", "strings" etc. On Wednesday 22 May 2024 at 15:46:30 UTC+1 robert engels wrote: > If it is your own code, you have to use > > import

[go-nuts] Re: var errors stdlib

2024-05-10 Thread 'Brian Candler' via golang-nuts
On Friday 10 May 2024 at 17:03:46 UTC+1 Sebastian Bogan wrote: Would something like the following work (and be less risky)?: type ConstError string func (e ConstError) Error() string { return string(e) } const ErrNotExist = ConstError("file does not exist") If you compare an error

[go-nuts] Re: Slice conversion function not working on big endian platform

2024-05-08 Thread 'Brian Candler' via golang-nuts
That code doesn't even compile in go 1.22 or go.1.21: https://go.dev/play/p/mPCBUQizSVo ./prog.go:20:14: cannot convert unsafe.Pointer(s) (value of type unsafe.Pointer) to type []To What's the underlying requirement? In the test case it looks like you want to take a slice of int32's, in

[go-nuts] Re: tuples! tuples! tuples!

2024-04-28 Thread 'Brian Candler' via golang-nuts
A few questions (I'm ignoring generics for now, and have not cross-referenced the other proposals). 1. Is it possible to access the n'th element of an implicitly typed tuple? More generally, how do you unpack such a tuple - other than by assigning to a compatible named tuple type? 2. How does

[go-nuts] Re: net/http Http Server - fail with Proxy Protocol header (v1/v2)

2024-04-26 Thread 'Brian Candler' via golang-nuts
Really I was unsure whether you can guarantee that the first few bytes of a TLS "client hello" can never happen to be the ASCII characters P R O X Y As a binary protocol I think it's unlikely to occur, but I've not attempted to prove it. On Friday 26 April 2024 at 02:30:51 UTC+1 Eli

[go-nuts] Re: net/http Http Server - fail with Proxy Protocol header (v1/v2)

2024-04-15 Thread 'Brian Candler' via golang-nuts
> My point is that a http server that is using the standard library always reply with an "HTTP/1.1 400 Bad Request" when the proxy protocol is part of the tcp package. That's the correct response, because the request is not compliant with HTTP. > So the net/http should just handle the http

[go-nuts] Re: net/http Http Server - fail with Proxy Protocol header (v1/v2)

2024-04-15 Thread 'Brian Candler' via golang-nuts
Your answer was given here: https://github.com/golang/go/issues/65078#issuecomment-1890419683 In other words: - net/http handles HTTP - go-proxyprotocol handles the proxy protocol - you combine the two to get the behaviour you want Orthogonal pieces which handle their own responsibilities are a

Re: [go-nuts] Re: <-ctx.Done() panic - link injecting bot?

2024-03-30 Thread 'Brian Candler' via golang-nuts
I clicked the "Report message" button for each of them, selecting type of abuse "Spam". Whether anyone reads these is doubtful though. The first spam was on 3 Jan 2024 and I reported it straight away; it hasn't stopped the new ones coming through. On Saturday 30 March 2024 at 10:21:18 UTC

Re: [go-nuts] Nil pointer panic that should be impossible

2024-03-25 Thread 'Brian Candler' via golang-nuts
And as Axel's own reproducer shows, even having two threads reading and writing the same *variable* which points to a string can result in indeterminate behaviour, since a string is really a struct containing two parts (a pointer and a len). You're not mutating the string itself, but you are

Re: [go-nuts] Nillable basic types?

2024-03-20 Thread 'Brian Candler' via golang-nuts
I got the impression the proposal was motivated by scalars that did not currently allow `nil` values Under the heading "Alternatives and why they're bad" he describes some ways this is currently dealt with - such as the common idiom of returning or passing a pointer to a value, instead of a

Re: [go-nuts] Nillable basic types?

2024-03-20 Thread 'Brian Candler' via golang-nuts
On Wednesday 20 March 2024 at 09:01:43 UTC Mike Schinkel wrote: Your comments made me go back and read the whole thing, but I was unable to find a list of enumerated objectives, and I did not find the text you quoted. Did I miss it somehow? It's in the very first post that opened this

Re: [go-nuts] Nillable basic types?

2024-03-20 Thread 'Brian Candler' via golang-nuts
When you say "var x NillableUint8" then you've just declared a variable of an interface type, and interface types are already nilable, so there's no need for "| nil" in the type! https://go.dev/play/p/f54akG65qJ3 https://go.dev/play/p/Jmtlta0h9m9 // generic version It's a perfectly valid way

Re: [go-nuts] Nillable basic types?

2024-03-18 Thread 'Brian Candler' via golang-nuts
I like Go because it's relatively simple and low-level, like C, except with things like garbage collection and channels integrated. If Go were to have "| nil" types then the internal representation of such variables would have to be something like this: type Maybe[T any] struct { Value T

Re: [go-nuts] How To Reduce Json Marshalling Time

2024-03-09 Thread 'Brian Candler' via golang-nuts
Perhaps it would be helpful to give some concrete figures for the real-world application. "the response time of Go API is higher than PHP" - how much? Are we talking, say, 1.2ms versus 1ms? Or 10ms versus 1ms? Is this testing between a client and server adjacent on the same LAN, or is the

[go-nuts] Re: How to add labels to Go runtime prometheus metrics?

2024-03-06 Thread 'Brian Candler' via golang-nuts
The server name will be added by Prometheus itself as an "instance" label for each target being scraped (or you can manually set the instance label for each target), so in general what you're asking is not necessary. None of the standard Prometheus exporters include a label for the hostname

Re: [go-nuts] Enums, Go1 and proposals

2024-03-04 Thread 'Brian Candler' via golang-nuts
On Monday 4 March 2024 at 15:18:05 UTC Jeremy French wrote: What I find valuable is to be able to accept an enum as a parameter to a function, and know that it will be one of several approved values (e.g. month of the year) ISTM all that's needed is to have a way to create a named type which

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-27 Thread 'Brian Candler' via golang-nuts
> let's consider the two possible definitions: > > 1. Pointers to distinct zero-size variables are equal: [...] > 2. Pointers to distinct zero-size variables are not equal: Another possibility: 3. Equality comparisons between pointers to zero-size variables are forbidden at compile time. 3a. If

Re: [go-nuts] help

2024-02-18 Thread 'Brian Candler' via golang-nuts
Your code includes this line: log.Println("DATABASE_URL:", os.Getenv("DATABASE_URL")) What does the log message actually show? This will confirm whether the environment variable is being passed correctly or not. I note you are using a different YAML structure for "environment" under go_app than

[go-nuts] Re: Trying to understand aversion to main package

2024-02-15 Thread 'Brian Candler' via golang-nuts
On Thursday 15 February 2024 at 00:08:44 UTC Jerry Londergaard wrote: If code is outside of the main function but still in the main package, it seems its testable like other functions? Yes indeed. I suspect though if one is putting tests in package main_test, then I guess you can't import

Re: [go-nuts] big int panic on text conversion

2024-02-14 Thread 'Brian Candler' via golang-nuts
Have you tried running your entire code under the race detector? https://go.dev/blog/race-detector On Wednesday 14 February 2024 at 06:02:02 UTC Kurtis Rader wrote: > Maybe provide a minimal reproducible example ( > https://stackoverflow.com/help/minimal-reproducible-example)? > > While it is

[go-nuts] Re: KeepAlive with net.Listen

2024-02-11 Thread 'Brian Candler' via golang-nuts
You're thinking backwards. "Long polling" is something done at the *client* side: this is where you send a HTTP request, but the reply intentionally doesn't come back for a long time - generally until the server detects some event that needs reporting. At a web *server*, you simply read the

[go-nuts] Re: KeepAlive with net.Listen

2024-02-10 Thread 'Brian Candler' via golang-nuts
Handling keep-alives on the *server* side doesn't require any sort of connection pool. Just create one goroutine for each incoming TCP connection, and once you've handled one request, loop around, waiting for another request on the same connection. (That's assuming the client does request use

Re: [go-nuts] Opening network connections blocks system thread

2024-02-10 Thread 'Brian Candler' via golang-nuts
I can't see how a large number of waiting goroutines would cause an increase in the number of OS threads, which was the OP's original problem (hitting the 10,000 thread limit) What the OP is implying - but we have not seen good evidence for yet - is that in some circumstances a non-blocking

[go-nuts] Re: Go 1.22 binary size improvements?

2024-02-09 Thread 'Brian Candler' via golang-nuts
Sorry you're right, it's "otool -L" for macOS. And you say that if you cross-compile from Linux with 1.22.0 to build a macOS binary, you get a size approx 93.8MB as well? Very odd. On Friday 9 February 2024 at 14:43:35 UTC cpu...@gmail.com wrote: > Yes, CGO is disabled. ldd doesn't seem to

[go-nuts] Re: Go 1.22 binary size improvements?

2024-02-09 Thread 'Brian Candler' via golang-nuts
Have you at any point set CGO_ENABLED=0 ? What does "ldd /path/to/binary" show on both the old (larger) and new (smaller) binaries? Maybe one is dynamically linked and the other statically linked? -- You received this message because you are subscribed to the Google Groups "golang-nuts"

[go-nuts] Re: Go 1.22.0: Alpine: go test with coverage works but returns exit status 1

2024-02-08 Thread 'Brian Candler' via golang-nuts
$ go test -v ./... -coverprofile=coverage.out -coverpkg=./internal/... -covermode count || echo "flaky:$?" example.com/m: open /tmp/go-build2233205084/b002/covmeta.f6e4431d5ec1fd71f02b3ce4e56eb691a86525173d917007425576a7d9db7c72: no such file or directory C:\dev\git\golang-test-cover>go test

[go-nuts] Re: Go 1.22.0: Alpine: go test with coverage works but returns exit status 1

2024-02-08 Thread 'Brian Candler' via golang-nuts
I found the solution to the "toolchain not available" problem: put "go 1.22.0" instead of "go 1.22" in go.mod. Clues picked up from #62278 . It's confusing for people who've been using go for a while though, when go.mod used to contain "go X.Y" and it

[go-nuts] Re: Go 1.22.0: Alpine: go test with coverage works but returns exit status 1

2024-02-08 Thread 'Brian Candler' via golang-nuts
Is it a bug or exepected behaviour? If a test fails, I would expect it to terminate with an error (exit code 1 in this case). If I run your reproducer locally (not in Docker) with the modified TestHelloer, it works fine(*) and gives me an exit code of 0: % go test -v ./...

Re: [go-nuts] Re: new range over int docs?

2024-02-07 Thread 'Brian Candler' via golang-nuts
But the main point is, the canonical version published at https://go.dev/ref/spec is still from Aug 2, 2023 On Wednesday 7 February 2024 at 12:02:28 UTC Rob Pike wrote: > Ha ha, someone forgot to change the year. It should read Jan 30, 2024. > > That's confusing. > > -rob > > > On Wed, Feb 7,

[go-nuts] Re: Do we need to call multipart.Part.Close

2024-02-06 Thread 'Brian Candler' via golang-nuts
Documentation could certainly be improved, since the Part.Close() method has literally no documentation. Whilst it does feel unsound, in practice I don't think the behaviour could be changed now without breaking the Go compatibility guarantee

[go-nuts] Re: Do we need to call multipart.Part.Close

2024-02-06 Thread 'Brian Candler' via golang-nuts
https://cs.opensource.google/go/go/+/refs/tags/go1.21.6:src/mime/multipart/multipart.go;l=325 All it does is read all the remainder of the part to io.Discard. So if you're sure you've read each part before moving onto the next one, it looks like you should be good. On Tuesday 6 February 2024

Re: [go-nuts] Re: snprintf() in Go with at most constant memory requirement difference than snprintf(3)?

2024-02-06 Thread 'Brian Candler' via golang-nuts
> Thanks! In addition to that, It also helps with code with upper limit > memory-requirement, which fmt.Sprintf() can't. If you're processing data from untrusted sources, then you probably ought to validate it first. > How to use a limiting > io.Writer with fmt.Sprintf()? How would this limit

[go-nuts] Re: snprintf() in Go with at most constant memory requirement difference than snprintf(3)?

2024-02-06 Thread 'Brian Candler' via golang-nuts
The C functions are mainly there to prevent overrunning already-allocated buffers, which isn't an issue with Go. You could truncate the response: a := fmt.Sprintf("%s", "Blah blah blah")[0:10] You could use suitable precision specifiers: a := fmt.Sprintf("%.10s", "Blah blah blah")

[go-nuts] Re: Golang formating of alternate form with zero padding

2024-02-03 Thread 'Brian Candler' via golang-nuts
Admittedly, C and Python work the same way, which is different to Go. #include int main(void) { printf("%07x\n", 42); printf("%0#7x\n", 42); printf("0x%07x\n", 42); return 0; } // Output 02a 0x0002a 0x02a On Wednesday 31 January 2024 at 13:56:07 UTC Brian Candler

[go-nuts] Re: Golang formating of alternate form with zero padding

2024-01-31 Thread 'Brian Candler' via golang-nuts
https://pkg.go.dev/fmt#hdr-Printing The '#' means you want the alternate format with the 0x prepended, and the '7' means you want the number itself padded to 7 digits x := fmt.Sprintf("%07x", 42) // 02a y := fmt.Sprintf("%0#7x", 42) // 0x02a z := fmt.Sprintf("0x%07x", 42) //

Re: [go-nuts] Re: Is encoding/json POSIX compatible?

2024-01-30 Thread 'Brian Candler' via golang-nuts
"incomplete" lines (3.195), but not arbitrarily long ones. On Tuesday 30 January 2024 at 15:20:00 UTC Javier Marti wrote: > So, as per the link that I sent, a json file is not a text file, right? is > just a file, I want to have this clear > > > thanks > > On Tue

[go-nuts] Re: Is encoding/json POSIX compatible?

2024-01-30 Thread 'Brian Candler' via golang-nuts
The JSON spec does not require any whitespace after the object, newline or otherwise. And POSIX does not require that files end with a newline. Maybe you are thinking of another spec, like https://jsonlines.org/ - but that's not part of JSON. On Tuesday 30 January 2024 at 14:16:35 UTC Xabi

[go-nuts] Re: Rendering fonts in Go

2024-01-12 Thread 'Brian Candler' via golang-nuts
At worst, it may possible to compile C into Go. It sounds mad, but I believe SQLite has been ported to pure Go this way. https://pkg.go.dev/modernc.org/sqlite https://twitter.com/bradfitz/status/855271867162083329?lang=en https://groups.google.com/g/golang-nuts/c/QDEczMhlQBU/m/4lCn2kP0AwAJ

[go-nuts] Re: mmapping over Go heap

2024-01-10 Thread 'Brian Candler' via golang-nuts
> accessing it after munmap leads to SIGSEGV or worse There must be a hundred different ways you can make a Go program segfault, and this doesn't sound any worse that the rest of them. Besides, unless the GC is changed to handle mmap regions differently, I think you would have the problem the

[go-nuts] Cipher suite oddity

2024-01-09 Thread 'Brian Candler' via golang-nuts
Something just pointed out to me(*) that I don't understand: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA is in tls.CipherSuites() TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 is in tls.InsecureCipherSuites() Why is the SHA256 variant

Re: [go-nuts] Re: [RFC] Syntactic Dissonance

2024-01-06 Thread 'Brian Candler' via golang-nuts
Full explanation here: https://blog.merovius.de/posts/2018-06-03-why-doesnt-go-have-variance-in/ On Saturday 6 January 2024 at 11:55:27 UTC John Pritchard wrote: > Hi, > > Thinking about types and their conception, I could avoid the type > assertion boilerplate and rationalize the type

[go-nuts] Re: <-ctx.Done() panic

2024-01-03 Thread 'Brian Candler' via golang-nuts
Panics can be caused by all sorts of things, but concurrency issues are a big one. Have you tried running your code under the race detector? https://go.dev/blog/race-detector On Wednesday 3 January 2024 at 10:57:49 UTC cheng dong wrote: > i have a program paniced with > > ``` >

[go-nuts] Re: How to get net.Conn in rpc function in net/rpc

2023-12-28 Thread 'Brian Candler' via golang-nuts
What do you mean by "Real IP" and in particular how does it differ from the TCP source address? If the client is behind a NAT, then (a) you won't know the client's real IP unless they tell it to you (and you trust what they say), and (b) you won't be able to connect to that address anyway. If

[go-nuts] Re: regexp docs for 'Index' ?

2023-12-14 Thread 'Brian Candler' via golang-nuts
No: result is the result, which is a bunch of 2-element arrays concatenated. As the documentation says: "result[2*n:2*n+2] identifies *the indexes* of the nth submatch" (i.e. the start index and the end index) In principle, accessing the i'th result is like this: start, end :=

[go-nuts] Re: regexp docs for 'Index' ?

2023-12-14 Thread 'Brian Candler' via golang-nuts
[a:b] gives you the elements from a to b-1 inclusive. So if you want the pair at position x, it has to be [x:x+2] https://go.dev/play/p/3nvEfOjdfnj On Thursday 14 December 2023 at 08:38:57 UTC Peter Galbavy wrote: > I noticed today that the regexp docs read: > > If 'Index' is present, matches

[go-nuts] Re: detecting deleted file that is still open and appending without error in Go?

2023-12-11 Thread 'Brian Candler' via golang-nuts
On Sunday 10 December 2023 at 16:41:00 UTC Jason E. Aten wrote: My question is: is there a way to have the Go process detect if the file it is writing to has been deleted by another process (git in this case) so that attempting to append to the file is no longer effective? On Unix, I'd fstat

[go-nuts] Re: Sending Context across channel - is it an anti-pattern?

2023-12-06 Thread 'Brian Candler' via golang-nuts
A (cancellable) context is mostly just a channel, which is closed as a broadcast signal, wrapped in an interface. I don't think that how you pass it around makes any difference, including sending it over another channel. Aside: it can be argued that "worker pool" is an anti-pattern in Go.

[go-nuts] Re: Using Go in picore (tinycore)

2023-12-06 Thread 'Brian Candler' via golang-nuts
You should note that you don't necessarily need to install the go compiler on your target machine. You can build ARM binaries on an x86_64 machine for example - set the parameters GOOS and GOARCH. Go is especially good for this sort of cross-compilation, as it doesn't require any special

[go-nuts] Re: Mongo Go Models (mgm) module and order by

2023-11-22 Thread 'Brian Candler' via golang-nuts
https://github.com/Kamva/mgm/discussions perhaps? (Open, but nothing posted since June 2022). On Wednesday, 22 November 2023 at 17:02:35 UTC Tong Sun wrote: > Any Mongo Go Models (mgm) user here? > https://github.com/Kamva/mgm > > Looks like that mgm can do aggregation but not "order by". > Is

[go-nuts] Re: Deciding between better documentation or making a module harder to misuse

2023-11-18 Thread 'Brian Candler' via golang-nuts
Maybe you're overthinking this. One option would be for Number to have a boolean attribute saying whether it's definitely finite, exposed as an IsFinite() method on Sequence. Calling FindLast() on a sequence where IsFinite() is false would panic. It's not compile-time safe, but it's better

[go-nuts] Re: Go-native abstract service interface design

2023-11-17 Thread 'Brian Candler' via golang-nuts
I think it depends on what your semantic contract is for this interface. If the caller starts a server with Run(ctx), is it implied that cancelling of ctx should stop the running server? If so, ISTM that there is no need for a separate Shutdown() method. (And there would be no need for App and

[go-nuts] Re: Is "When in doubt, use a pointer receiver" misleading advice?

2023-11-15 Thread 'Brian Candler' via golang-nuts
On Tuesday, 14 November 2023 at 03:38:04 UTC Mike Schinkel wrote: 1. A value variable and multiple value receivers <--- compiles 2. A pointer variable and multiple value receivers <--- compiles 3. A pointer variable and multiple pointer receivers. <--- compiles 4. A value variable and multiple

[go-nuts] Re: Handling EOF when using json.NewDecoder() from named pipe

2023-10-17 Thread 'Brian Candler' via golang-nuts
Are you sure that the writer isn't closing the named pipe between writing JSON objects? If necessary you can check this with strace. I'm pretty sure you'll get an EOF in the *reader* when the *writer* closes from their side. You can demonstrate this with the shell: (In terminal 1) mkfifo

[go-nuts] Re: Is there a race in exec.CombinedOutput?

2023-10-04 Thread 'Brian Candler' via golang-nuts
Code reference: https://cs.opensource.google/go/go/+/refs/tags/go1.21.1:src/os/exec/exec.go;l=523-565 * c.writerDescriptor creates the pipe, and a copying function is appended to the slice c.goroutine. This slice contains the functions which will be started in their own goroutines. *

Re: [go-nuts] sql string not interpolated as expected

2021-01-03 Thread 'Brian Candler' via golang-nuts
I think the nearest is: labelStrs := []interface{}{"carnivore", "mammal", "vertebrate"} rows, err := c.Database.Db.Query(` select id from mbk_user_label where label_name in (?,?,?) `, labelStrs...) Of course, you may need to change the number of question-marks to match

Re: [go-nuts] Generics and formatting

2021-01-02 Thread 'Brian Candler' via golang-nuts
Raised as https://github.com/golang/go/issues/43470 On Friday, 1 January 2021 at 18:40:36 UTC Ian Lance Taylor wrote: > On Fri, Jan 1, 2021 at 9:50 AM 'Brian Candler' via golang-nuts > wrote: > > > > Just a minor issue, but playing with this example: > > https:

[go-nuts] Re: Generics Error - How to fix?

2021-01-01 Thread 'Brian Candler' via golang-nuts
If by "generics doc" you mean this one , then note: *"Generic types can have methods. The receiver type of a method must declare the same number of type parameters as are declared in the receiver

[go-nuts] Generics and formatting

2021-01-01 Thread 'Brian Candler' via golang-nuts
Just a minor issue, but playing with this example: https://go2goplay.golang.org/p/IUL1QDrtOwW - click "Run" and it works - click "Format" and it fails with the following error: prog.go:40:24: expected ']', found ',' (and 6 more errors) -- You received this message because you are subscribed to