[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
from TLS. > > I agree with all other points, but wanted to mention that.  > > -eli > > > On Monday, April 15, 2024 at 4:43:50 PM UTC-4 Brian Candler wrote: > > > My point is that a http server that is using the standard library always > reply with an "HT

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

2024-04-15 Thread 'Brian Candler' via golang-nuts
eone needs to parse the proxy protocol, it's fine to implement or > add a 3rd party lib, but I think the "default" should just work. > > Brian Candler schrieb am Montag, 15. April 2024 um 20:41:50 UTC+2: > >> Your answer was given here: >> https://github.com/golang/

[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
. So should I long-poll until next request > line comes or keep-alive times out? Is there a better way to detect > incoming requests and then maybe awake the goroutine using channels? > On Saturday, February 10, 2024 at 1:52:23 AM UTC-8 Brian Candler wrote: > >> Handling keep-al

[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
System/Library/Frameworks/Security.framework/Versions/A/Security > (compatibility version 0.0.0, current version 0.0.0) > > On Friday, February 9, 2024 at 2:22:36 PM UTC+1 Brian Candler wrote: > >> Have you at any point set CGO_ENABLED=0 ? >> >> What does "ldd /p

[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
e you say that the coverage file is created, and presumably you > would have noticed the "toolchain not available" error message. In any > case, you're using a base image with go 1.22.0. > > Exactly. > As seen in the output above, further commands (go tool cover) using

[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
when go.mod used to contain "go X.Y" and it was invalid to put "go X.Y.Z". Now that appears to have swapped around <https://github.com/golang/go/issues/62278#issuecomment-1698829945>. On Thursday 8 February 2024 at 08:30:25 UTC Brian Candler wrote: > Is it a

[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
ocumentation at all feels unsound. A Close method > usually means you have to defer it right after getting the resource, so I > would have expected the docs to be more clarifying on its usage. > El martes, 6 de febrero de 2024 a las 15:11:55 UTC+1, Brian Candler > escribió: > >>

[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

[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
hile the "n" > indexes are actually the values of the submatches, not the indexes. I still > think it's confusing, but makes more sense when I write it like this: > https://go.dev/play/p/SHl_aSU3kPZ > > On Thursday 14 December 2023 at 09:06:00 UTC Brian Candler wrote:

[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. *

[go-nuts] Re: Why doesn't the database/sql package in Go support using placeholders "?" to replace the database name and username in SQL statements?

2023-09-18 Thread Brian Candler
limited to only a subset of queries (or > places inside a query) — as the link to SO's answer, shared previously, > explained. > > Hope this makes it a little bit more clear. > > On Sunday, September 17, 2023 at 10:45:27 AM UTC+2 Brian Candler wrote: > >> According

[go-nuts] Re: cannot find package "github.com/go-redis/redis/v8"

2023-09-18 Thread Brian Candler
You always need a go.mod file if you are importing other modules. But if you're not publishing your code, you can name your own module however you like: "go mod init example" is fine. On Monday, 18 September 2023 at 11:27:09 UTC+1 Aadi Sharma wrote: > I am using go-redis package and can not

[go-nuts] Re: Help with WASM performance

2023-09-16 Thread Brian Candler
What WASM runtime are you using to execute the code? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this

[go-nuts] Re: Weird error when trying to fetch a module.

2023-09-15 Thread Brian Candler
> I can not find the go.mod for flatbuffers! It is not in the root of the repository and also not inside the go subdir where the code resides Presumably relies on this: https://go.dev/ref/mod#non-module-compat See also

Re: [go-nuts] Re: Weird error when trying to fetch a module.

2023-09-15 Thread Brian Candler
> Keep your go source at the root of the repo and tag that Or would it be OK just to put go.mod at the root of the repo, containing module github.com/flatgeobuf/flatgeobuf - and leave the rest of the source where it is? I believe that will still allow someone to import or get

Re: [go-nuts] Re: Parsing difficult JSON

2023-09-14 Thread Brian Candler
Could you just unmarshal it to a map[string]IntTSList, and then walk it and build whatever structure you want? If you want to pick certain fixed fields into a struct and separate out the leftovers to be parsed as "subnet[X].Y", then see

Re: [go-nuts] How ignore a subdirectory

2023-09-13 Thread Brian Candler
I believe that "go fmt ." (note the space after "go") works on the current package only. On Wednesday, 13 September 2023 at 11:34:35 UTC+1 Jan Mercl wrote: > On Wed, Sep 13, 2023 at 12:25 PM John Souvestre > wrote: > > I did try that also. I get this error message: > > > > CreateFile

Re: [go-nuts] Using go module 101, undefined types

2023-09-12 Thread Brian Candler
> I also tried to build the whole project with `go build .` To do that you would need: mkdir -p bin go build -o bin ./... The following compiles fine for me. Note that in your original post the error talks about api.PetStore, but the code you showed was a call to api.NewPetStore.

[go-nuts] Re: Generic function for types with common method name but different return type

2023-09-10 Thread Brian Candler
> https://go.dev/play/p/h5jzISRyTkF In this approach, I'm not fond of how I must call the f function on line 30. Without specifying a type parameter, the call fails to compile. If I replace f[A](a, "") with f(a, "") it still works for me, in the playground. What go version are you using?

Re: [go-nuts] go1.21.0 panics when loading plugin

2023-09-05 Thread Brian Candler
But if you remove the reference to regexp/syntax in the top-level main.go, then it also works fine (with no change to the plugin code itself). On Tuesday, 5 September 2023 at 20:05:58 UTC+1 Howard C. Shaw III wrote: > It looks to me like the regexp package has an func init() that never gets >

Re: [go-nuts] go1.21.0 panics when loading plugin

2023-09-05 Thread Brian Candler
Slightly simplified version: ==> go.mod <== module example.com go 1.20 ==> main.go <== package main import ( "plugin" "regexp/syntax" ) func main() { if syntax.Perl != 212 { panic("Unexpected flags") } p, err := plugin.Open("p1.so") if err != nil { panic(err) } s, err := p.Lookup("F") if err

Re: [go-nuts] go1.21.0 panics when loading plugin

2023-09-05 Thread Brian Candler
I forgot to include ==> go.mod <== module example.com go 1.20 -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view

Re: [go-nuts] go1.21.0 panics when loading plugin

2023-09-05 Thread Brian Candler
e of syntax.Perl within main() or F(), I see that it is 212 as expected, even when the error occurs. On Monday, 4 September 2023 at 18:55:07 UTC+1 Brian Candler wrote: > I'm afraid I have to contradict that answer (from an AI chatbot perhaps?) > > Go's regexp library, called re2, is documented her

Re: [go-nuts] go1.21.0 panics when loading plugin

2023-09-04 Thread Brian Candler
I'm afraid I have to contradict that answer (from an AI chatbot perhaps?) Go's regexp library, called re2, is documented here: https://github.com/google/re2/wiki/Syntax It *does* support the \w character class. See the section headed "Perl character classes (all ASCII-only)". Furthermore, the

[go-nuts] Re: go-embed results in http 404

2023-09-02 Thread Brian Candler
Firstly, there must be no space between "//" and "go:embed". Otherwise it's just treated as a regular comment, and you get an empty fs with no error. (Perhaps "go vet" could be enhanced to catch this?) After fixing this, you'll see the underlying error: main.go:10:12: pattern public: no

[go-nuts] Re: go build of a *_unix.go file still used under windows ?

2023-08-31 Thread Brian Candler
is true) and then a naïve reader, > like me, would think the later paragraphs about GOOS also apply. > > Peter > > On Thursday, 31 August 2023 at 10:13:12 UTC+1 Brian Candler wrote: > >> https://github.com/golang/go/issues/51572 >> >> On Thursday, 31 August 2023

[go-nuts] Re: go build of a *_unix.go file still used under windows ?

2023-08-31 Thread Brian Candler
https://github.com/golang/go/issues/51572 On Thursday, 31 August 2023 at 08:57:15 UTC+1 Peter Galbavy wrote: > I have used comment level build constraints for a while but I moved to > using _linux.go and _windows.go over time as it makes it clearer for > external viewing. > > A user reported

Re: [go-nuts] Re: wtf

2023-08-26 Thread Brian Candler
{ > i = 1 > > } > } > > func HandleWTF(b bool) { > p := process{} > var i = 2 > var pt any = > defer p.close(pt) > if b { > i = 1 > > } > } > > func main() { > Handle(true)// error > Handle(false) // no error > HandleWTF(true) // er

[go-nuts] Re: wtf

2023-08-26 Thread Brian Candler
Any arguments to defer functions are evaluated at the time that the defer is executed. In HandleWTF, defer p.close(err) is called immediately after err is declared with value nil, so nil is what is used. >From the specification : "Each time a "defer"

Re: [go-nuts] does gonum insist on row-major?

2023-08-26 Thread Brian Candler
Could you explain the comment "all of Go is cm"? https://go.dev/play/p/tDJiSTqsiSC On Saturday, 26 August 2023 at 14:02:34 UTC+1 Dan Kortschak wrote: > On Sat, 2023-08-26 at 13:45 +0100, Jason E. Aten wrote: > > ah... there is documentation, it is just buried... > > > >

[go-nuts] Re: Using underscore in return statements - a small convenience idea

2023-08-23 Thread Brian Candler
Something similar is in the pipeline: https://github.com/golang/go/issues/61372 When implemented, it will be spelled "zero" rather than "_" As I understand it, you'll still need to say 0, "" or nil where those are available for the type in question. Therefore in the f1() example you gave,

[go-nuts] Re: how to constrain a type

2023-08-17 Thread Brian Candler
o at some point I'm > going to iterate over them and within that iterating use a type switch. > This is because the shapes _don't_ know how to draw themselves but an > external function that reads them will know. > > On Thursday, August 17, 2023 at 4:35:10 PM UTC+1 Brian Candler

[go-nuts] Re: how to constrain a type

2023-08-17 Thread Brian Candler
I'm not sure without knowing *how* you want to use []*Shape{}. Perhaps you want Shape to be an interface? type Shape interface { DrawMe() } type BoxShape struct ... func (*BoxShape) DrawMe() { } type LineShape struct ... func (*LineShape) DrawMe() { } shapes := []Shape{} (Note that

[go-nuts] Re: [rfc] build bug in type abstraction?

2023-08-16 Thread Brian Candler
On Wednesday, 16 August 2023 at 14:05:49 UTC+1 John Pritchard wrote: I have a disparity between "go run" [ https://go.dev/play/p/5mr5M0luZ9k?v=goprev] and "go build" [https://github.com/syntelos/go-type-abstraction/tree/third]. Using go version 1.21.0. I don't quite understand where "go

[go-nuts] Re: What does `shallow clone` mean?

2023-08-14 Thread Brian Candler
On Friday, 11 August 2023 at 17:56:01 UTC+1 Shinya Sakae wrote: I often hear the term `shallow copy', but I don't know what `shallow clone` means. Don't worry: they are the same thing. When cloning a map, the keys and values are set using ordinary assignment, as the description says. It

[go-nuts] Re: How to convert an svg to a png (or gif) image?

2023-08-04 Thread Brian Candler
Also there's a project which compiles C code to Go - ISTR it was used to build a pure Go version of Sqlite. Presumably the same approach could be applied to an image processing library. https://twitter.com/bradfitz/status/855271867162083329?lang=en

[go-nuts] Re: Any option to substitute plug-in package ?

2023-08-03 Thread Brian Candler
I believe Hashicorp's go-plugin was developed long before Go's stdlib plugin functionality was made available. But they still use it. It's well established and tested, the architecture has security benefits, and it works cross-platform. It also makes it easier for plugins to be distributed by

Re: [go-nuts] Re: Amateur's questions about "Go lang spec"

2023-08-02 Thread Brian Candler
y followed by a list of (mostly) allowed operations >> that illustrate the original rule?" >> You hit the nail on the head. >> >> I don't have much faith in me as programmer, so I ask about any such >> issue that is bothering me. >> >> Best regards, >

[go-nuts] Re: Any option to substitute plug-in package ?

2023-08-02 Thread Brian Candler
The plugin package is very limiting even under Linux: see this reddit post . I suggest you look at hashicorp's go-plugin .

Re: [go-nuts] Error handling

2023-08-02 Thread Brian Candler
FWIW, I'm in the "I like how it is now better than any other proposal so far" camp; I think this happens as you get used to the Go way. Go is Go. The only thing I would consider is making *interface* types (only) implicitly usable in a boolean context, e.g. if err { ... } However, I suppose

[go-nuts] Re: Error handling

2023-07-30 Thread Brian Candler
err := io.Copy(w, r) *orelse* { w.Close() os.Remove(dst) return fmt.Errorf("copy %s %s: %v", src, dst, err) } My question still stands. Semantically, what value exactly does the "orelse" condition test is not equal to nil? - does it test the value from the preceding assignment? If so, is

[go-nuts] Re: Error handling

2023-07-30 Thread Brian Candler
Typo: should have said var foo error r, bar := os.Open(src) orelse return foo // does this do "if foo != nil { return foo }" ?? On Sunday, 30 July 2023 at 10:20:12 UTC+1 Brian Candler wrote: > On Sunday, 30 July 2023 at 09:40:25 UTC+1 DrGo wrote: > > orelse must return an

[go-nuts] Re: Error handling

2023-07-30 Thread Brian Candler
On Sunday, 30 July 2023 at 09:40:25 UTC+1 DrGo wrote: orelse must return an error (ie satisfies the error interface); the specific type and variable name do not matter. But how does "orelse" perform the check in the first place? Does it look for the variable named in the return statement?

[go-nuts] Re: Error handling

2023-07-30 Thread Brian Candler
On Sunday, 30 July 2023 at 06:57:15 UTC+1 DrGo wrote: I looked at the long list of proposals to improve error handling in go but I have not seen the one I am describing below. There is a meta-ticket here: https://github.com/golang/go/issues/40432 Under the section "Simplifications of if err

[go-nuts] Re: Error handling

2023-07-30 Thread Brian Candler
Just to be clear: are you hard-coding the variable name "err" into the semantics of "orelse"? That is, you can't assign the error return to a variable of any other name? I disagree that this makes the job of linters any easier than it is today. For example, if you'd written ...

Re: [go-nuts] Re: Amateur's questions about "Go lang spec"

2023-07-28 Thread Brian Candler
If you wanted to be absolutely clear, you could insert "The following are examples of expression statements" - although it didn't really trouble me as-is. On Friday, 28 July 2023 at 16:12:11 UTC+1 Jason Phillips wrote: > The confusion may come from the fact that a list of forbidden built-in >

[go-nuts] Re: Possible Go Compiler or Runtime bug?

2023-07-27 Thread Brian Candler
anything to do with this. The cap() of a slice relates to the amount of storage allocated for the data elements (which the header points to), not the space consumed by the header itself. On Thursday, 27 July 2023 at 13:42:21 UTC+1 Brian Candler wrote: > That looks very weird. The panic is trigge

[go-nuts] Re: Possible Go Compiler or Runtime bug?

2023-07-27 Thread Brian Candler
That looks very weird. The panic is triggered if I uncomment line 17 (the final fmt.Printf) even though it never reaches there - it panics when getStrBytes is called from line 9 (in line 23). On Thursday, 27 July 2023 at 13:12:40 UTC+1 Kyle Harrity wrote: > I first asked this on

[go-nuts] Re: Can a struct be made comparable?

2023-07-14 Thread Brian Candler
nly one struct field is considered for comparison purposes. > > On Friday, July 14, 2023 at 10:00:34 AM UTC+1 Brian Candler wrote: > >> I forgot you wanted generics: >> https://go.dev/play/p/PhGVjsWWTdB >> >> On Friday, 14 July 2023 at 09:47:21 UTC+1 Brian Ca

[go-nuts] Re: Can a struct be made comparable?

2023-07-14 Thread Brian Candler
I forgot you wanted generics: https://go.dev/play/p/PhGVjsWWTdB On Friday, 14 July 2023 at 09:47:21 UTC+1 Brian Candler wrote: > You seem to be saying "if the S field is different then I want to consider > these two structs different, and get pointers to the two structs. If the

[go-nuts] Re: Can a struct be made comparable?

2023-07-14 Thread Brian Candler
so I don't know either way yet), >> but in any case, it is incredibly slow. >> >> On Friday, July 14, 2023 at 8:31:39 AM UTC+1 Peter Galbavy wrote: >> >>> As a slight digression - I thought I was going mad, but 'slices' and >>> 'maps' are new :-) Only in 1.

[go-nuts] Re: Can a struct be made comparable?

2023-07-13 Thread Brian Candler
Structs are already comparable, but all fields must be the same: https://go.dev/play/p/XwhSz4DEDwL I think your solution with function 'eq' is fine. You can see the same thing in the standard library in slices.CompactFunc and slices.EqualFunc https://pkg.go.dev/slices#CompactFunc

[go-nuts] Re: Issue with integration test coverage

2023-07-11 Thread Brian Candler
Why are you using kill -9? That doesn't allow the process any time to tidy up whilst exiting. But also see https://go.dev/testing/coverage/#FAQ "If my program panics, will coverage data be written? Programs built with go build -cover will only write out complete profile data at the end of

[go-nuts] Re: How to run extra routine for http server properly ?

2023-07-07 Thread Brian Candler
If it's an important business task which needs to take place even if the machine crashes, then maybe you want to post a request into a persistent message queue (e.g. NATS, Kafka) before returning to the user. The task can then be picked up by a separate worker process. On Friday, 7 July 2023

Re: [go-nuts] Go 1.21 new builtin function clear()

2023-07-06 Thread Brian Candler
In principle I agree with the sentiment, in the sense this is what you'd expect from other languages like Python. However, slices are fundamentally different to maps in Go. Map values contain a pointer to a mutable data structure (that's why you can't insert into a zero map - you have to

Re: [go-nuts] how to close a child process after father process be killed

2023-07-05 Thread Brian Candler
> Is there any way to create a child process that is detached from the original cgroup using exec.Command? > I don't want my child process to be killed when the parent process dies. This might be an issue with process groups, not cgroups, in which case I think Setsid is what you want, something

[go-nuts] Re: how to diagnose slow build

2023-06-29 Thread Brian Candler
What platform are you building under - in particular, is it Windows? On Thursday, 29 June 2023 at 13:11:07 UTC+1 王富民awaw wrote: > My builds have been very slow recently and I want to know why is `go > build` so slow for me. > Is it due to reading disks or something else? > > What is the

Re: [go-nuts] Unexpected circular type definition limitation

2023-06-15 Thread Brian Candler
> You can always solve name spacing issues by splitting it up into separate packages. Or type aliases: https://go.dev/play/p/Slhgs8SLyo6 On Thursday, 15 June 2023 at 09:47:39 UTC+1 Axel Wagner wrote: > Type declarations in functions are only scoped from the point of their > declaration until

[go-nuts] Re: tool for ast graph visualization

2023-06-14 Thread Brian Candler
Aside: draw.io also has functionality like graphviz for the web 2.0 generation: https://drawio-app.com/blog/automatically-create-draw-io-diagrams-from-csv-files/ On Wednesday, 14 June 2023 at 10:01:10 UTC+1 Vraj Reshamdalal wrote: > Hi alex-coder! > You can try using Graphviz. > Graphviz

  1   2   3   4   5   6   7   8   >