Re: [go-nuts] Re: pkg.go.dev: redirect URL for latest major version or big red warning for old version

2024-04-08 Thread Tom Payne
I see this working for modules, but not major versions. For example the whole github.com/golang/protobuf module is deprecated: https://github.com/golang/protobuf/blob/75de7c059e36b64f01d0dd234ff2fff404ec3374/go.mod#L1 However, there are is no deprecation message for github.com/google/go-github :

[go-nuts] Alternative text/template function libraries to github.com/Masterminds/sprig?

2023-01-09 Thread Tom Payne
github.com/Masterminds/sprig is a popular library of template functions, used by some popular projects, e.g. Kubernetes Helm. Unfortunately, Masterminds/sprig also has a number of inherent flaws: 1. The order of arguments to many of its functions is incompatible with text/template's pipeline synta

[go-nuts] Getting cross-package test coverage data?

2020-05-13 Thread Tom Payne
What's the current state of getting combined cross-package test coverage data? Specifically: - I have a lib directory containing my library code, which has some tests, but not many. - I have a cmd directory containing my main code and many tests that exercises the code in lib . -

Re: [go-nuts] Re: marshal multiple json documents which may have different format versions into the latest struct version

2020-05-01 Thread Tom Payne
Possibly also useful if you're dealing with JSON documents with different structures: https://github.com/twpayne/go-jsonstruct This will generate the most specific Go struct possible that covers all the example documents that you give it. In your example it will generate: package main type T

Re: [go-nuts] testing code that uses ioutil.ReadDir?

2020-04-11 Thread Tom Payne
Testing code that uses the os and ioutil packages is tricky. I created https://pkg.go.dev/github.com/twpayne/go-vfs https://pkg.go.dev/github.com/twpayne/go-vfs/vfst to make it easier. Key features: - Everything eventually calls the underlying os/ioutil function, so you get real behavior, not

[go-nuts] When to use runtime.GOOS vs. build flags/file suffixes?

2020-04-08 Thread Tom Payne
Go allows OS-specific code to be selected two different ways, either using the runtime.GOOS constant or with file-level build tags like "//+build linux" or (equivalently) OS-specific source file suffixes like _linux. What's the recommended way to decide when to use which? As far as I can tell:

Re: [go-nuts] Recommended way to prevent my project being built with an old Go version?

2020-04-07 Thread Tom Payne
roduced at exactly the minimum Go version that you want. On Thursday, April 2, 2020 at 1:26:04 AM UTC+1, Tom Payne wrote: > > Thanks Ian for the fast and authoritative answer. I'll do what you suggest. > > Cheers, > Tom > > On Tuesday, March 31, 2020 at 2:31:19 AM UTC+1, Ian L

Re: [go-nuts] Recommended way to prevent my project being built with an old Go version?

2020-04-01 Thread Tom Payne
Thanks Ian for the fast and authoritative answer. I'll do what you suggest. Cheers, Tom On Tuesday, March 31, 2020 at 2:31:19 AM UTC+1, Ian Lance Taylor wrote: > > On Mon, Mar 30, 2020 at 6:22 PM Tom Payne > > wrote: > > > > Go's backwards compatibilit

[go-nuts] Recommended way to prevent my project being built with an old Go version?

2020-03-30 Thread Tom Payne
Hi, Go's backwards compatibility guarantee is fantastic, but only applies to the language, not the standard library. How to I cause a build-time failure if someone tries to build my project with a too-old Go version? I have a Go project that uses (or would like to use) a few features introduce

[go-nuts] Re: Experience report on a large Python-to-Go translation

2020-01-26 Thread Tom Payne
Really interesting post, thank you. On iterators without leaking goroutines, have a look at the standard library's bufio.Scanner and database/sql.Rows. These provide easy iteration over arbitrary sequences in a compact idiomatic form. -- You received this message because you are subscribed to

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

2020-01-15 Thread Tom Payne
d, 15 Jan 2020 at 21:29, Ian Lance Taylor wrote: > On Wed, Jan 15, 2020 at 12:24 PM Tom Payne wrote: > > > > Thanks all for the insight and explanation. Could I suggest tweaking the > Go language specification to emphasize the separation, so it reads: > > > >

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

2020-01-15 Thread Tom Payne
Thanks all for the insight and explanation. Could I suggest tweaking the Go language specification to emphasize the separation, so it reads: "when evaluating the operands of an expression, assignment, or return statement, *then* all function calls, method calls, and communication operations are

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

2020-01-15 Thread Tom Payne
The Go language specification on order of evaluation states: "when evaluating the operands of an expression, assignment, or return statement, all function calls, method calls, and communication operations are evaluated in lexical left-to-right

Re: [go-nuts] Existing hermetic end-to-end testing libraries for CLI applications?

2020-01-10 Thread Tom Payne
Many thanks for this Paul - this is exactly what I was looking for. Cheers, Tom On Fri, 10 Jan 2020 at 09:55, Paul Jolly wrote: > Hi Tom, > > > tl;dr Are there any existing end-to-end testing libraries for CLI > applications? Specifically, what I'm looking for is a library that makes it > easy

[go-nuts] Existing hermetic end-to-end testing libraries for CLI applications?

2020-01-09 Thread Tom Payne
Hi, tl;dr Are there any existing end-to-end testing libraries for CLI applications? Specifically, what I'm looking for is a library that makes it easy to test that "running this command should produce this output" without fear that a buggy application could corrupt the filesystem. Background:

Re: [go-nuts] regexp syntax and named Unicode character classes

2020-01-07 Thread Tom Payne
Thank you :) Is this worth adding to the regexp/syntax documentation? I'd happily contribute a patch. On Tuesday, January 7, 2020 at 7:36:02 PM UTC+1, Ian Lance Taylor wrote: > > On Tue, Jan 7, 2020 at 10:22 AM Tom Payne > > wrote: > > > > tl;dr How should

[go-nuts] regexp syntax and named Unicode character classes

2020-01-07 Thread Tom Payne
Hi, tl;dr How should I use named Unicode character classes in regexps? I'm trying to write a regular expression that matches Go identifiers , which start with a Unicode letter or underscore followed by zero or more Unicode letters, decimal digits, and/o

[go-nuts] [ANN] go-jsonstruct: generate Go structs from multiple JSON objects

2019-12-16 Thread Tom Payne
Do you have a bunch of JSON objects with no schema that you want to idiomatically unmarshall in Go? Existing JSON-to-Go struct generators take one object as input. This one takes all the JSON objects you can throw at it, be they API responses, unstructured JSON column values in a database, or a

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

2019-11-01 Thread Tom Payne
Thank you very much for the fast, clear, and detailed answer :) On Fri, 1 Nov 2019 at 15:08, Ian Lance Taylor wrote: > On Fri, Nov 1, 2019 at 6:31 AM Tom Payne wrote: > > > > cgo is often used to provide bindings to C libraries. Any memory > allocated in the C library is not

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

2019-11-01 Thread Tom Payne
cgo is often used to provide bindings to C libraries. Any memory allocated in the C library is not visible to Go, so Go does not have an accurate view of the program's memory usage and does not run the garbage collector or any finalizers often enough. Consequently, memory usage for a Go server t

[go-nuts] A better io.Reader.Read signature?

2019-09-05 Thread Tom Payne
Dave Cheney has written (yet another) excellent blog post on Go, on the subject of API design and caller-controlled allocations: https://dave.cheney.net/2019/09/05/dont-force-allocations-on-the-callers-of-your-api In this he compares two possible signatures for the io.Reader.Read method: fun

Re: [go-nuts] Re: Disable test result caching from within Go code?

2019-04-12 Thread Tom Payne
Here's an example of a test that is cached but shouldn't be: https://github.com/twpayne/go-geom/blob/master/examples/postgis/main_test.go#L18 This particular test uses github.com/ory/dockertest to run an integration test against a PostgreSQL database. It uses Docker which is an external service,

Re: [go-nuts] Why does "go mod" ignore tags in this case?

2019-04-03 Thread Tom Payne
Thanks Roger. To close this topic, you were right: I'd missed that there is a special release process for v2 of a module and above, and also go's mod cache was out-of-sync as I'd been moving tags around. "go mod verify" is your friend. On Thu, 21 Feb 2019 at 09:05, roger peppe wrote: > I suspec

Re: [go-nuts] Re: Existing code for order-preserving concurrent work queue?

2019-01-27 Thread Tom Payne
Yes, I did, thank you! My reply was to the previous message (robert engels' post about it being "straightforward" but not providing code) and I think we just both hit send at about the same time. On Sat, 26 Jan 2019 at 02:52, Michael Jones wrote: > Did you notice that I sent you the complete cod

Re: [go-nuts] Can package init() functions in different packages ever run concurrently?

2018-11-14 Thread Tom Payne
On Thursday, November 15, 2018 at 1:51:08 AM UTC+1, Ian Lance Taylor wrote: > > On Wed, Nov 14, 2018 at 4:43 PM, Tom Payne > > wrote: > > > > I couldn't find the answer to this from Googling. > > > > According to the documentation that I've fo

[go-nuts] Can package init() functions in different packages ever run concurrently?

2018-11-14 Thread Tom Payne
I couldn't find the answer to this from Googling. According to the documentation that I've found: - For any given package, its imports' init() functions are run before the package's init() function. - Within a package, init() functions are more-or-less run in lexical filename order. My question

Re: [go-nuts] How to get the user's umask without race condition?

2018-11-14 Thread Tom Payne
impossible on posix using only syscalls, >>> but you may be able to use /proc: >>> https://manpages.debian.org/stretch/manpages-dev/umask.2.en.html#NOTES >>> >>> >>> On Tue, Nov 6, 2018 at 4:35 PM Tom Payne > >>> wrote: >>> >>>> Hi,

[go-nuts] How to get the user's umask without race condition?

2018-11-06 Thread Tom Payne
Hi, The user's umask can be set with the umask(2) system call, this sets the new umask and returns the old one. As far as I can tell, the canonical way to get the user's current umask is to call umask twice: once to get the old value and set a temporary one, then a second call to restore the ol

Re: [go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Tom Payne
equal to accept(2). > > On Thu, Aug 24, 2017, 20:13 Tom Payne > > wrote: > >> Thanks. Looking at the man page for Linux's accept(2) >> http://man7.org/linux/man-pages/man2/accept.2.html it seems that >> l.Accept is unlikely to ever return an error. >> &

Re: [go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Tom Payne
ndlers invoked in the go statement > that did not finished already. > > On Thu, Aug 24, 2017, 19:49 Tom Payne > > wrote: > >> Awesome, thanks Jan for the fast and clear response. >> >> In fact, the for {} is an infinite loop so wg.Wait() will never be >> reac

Re: [go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Tom Payne
, August 24, 2017 at 7:41:59 PM UTC+2, Jan Mercl wrote: > > No, wg.Add cannot "switch" to wg.Wait, they're both in the samr goroutine, > the go statement will be always the next one to execute after wg.Add within > serve(). > > On Thu, Aug 24, 2017, 19:29 T

[go-nuts] Potential race condition in prototypical network server code

2017-08-24 Thread Tom Payne
I'm not singling out Dave Cheney here, I'd just like to check my understanding of Go's resource handling and concurrency. In this blog post a "prototypical network server" is presented: https://dave.cheney.net/2017/08/20/context-isnt-for-cancellation Code: func serve(l net.Listener) error {

Re: [go-nuts] Reasoning behind behavior of range, when index is maintained

2017-08-02 Thread tom . payne
A side effect of this approach is that the index after the range loop will be zero if slice contains zero or one elements: https://play.golang.org/p/F7lLZ5wcuv This means that code using the index after the range will need to re-test whether the slice was empty to avoid a potential panic. On

[go-nuts] "go install": no warning/error when binaries conflict

2017-07-18 Thread tom . payne
Consider a package with multiple binaries with the same name, "cmd" in this case: pkg1/cmd/main.go: package main; import "fmt"; func main() { fmt.Println("pkg1") } pkg2/cmd/main.go: package main; import "fmt"; func main() { fmt.Println("pkg2") } When running $ go install ./... I would expect

Re: [go-nuts] Re: [ANN] Go geospatial libraries: geometries, GeoJSON, WKB, KML, PostGIS, GPX, polyline

2017-03-27 Thread Tom Payne
On 27 March 2017 at 19:15, Constantine Vassilev wrote: > How to use go-geom to convert WKBHEX to KML? > > Are there a simple example? > > On Sunday, November 13, 2016 at 10:33:27 AM UTC-8, Tom Payne wrote: >> >> A quick announce of a few libraries for geospatial a

[go-nuts] Gob encoding of maps is not consistent, should this be fixed?

2016-12-19 Thread Tom Payne
This example demonstrates that the Gob encoding of the same map value varies: https://play.golang.org/p/DZRV9i0uf_ This is because the encoder iterates over the map using a for ... range loop and the iteration order for maps is not defined: https://github.com/golang/go/blob/master/src/encodi

[go-nuts] Re: [ANN] Go geospatial libraries: geometries, GeoJSON, WKB, KML, PostGIS, GPX, polyline

2016-11-15 Thread Tom Payne
urces/tree/master/tooling > > where you think it is appropriate. Would you consider submitting a PR > with some additions? > > Daniel > > On Sunday, November 13, 2016 at 1:33:27 PM UTC-5, Tom Payne wrote: >> >> A quick announce of a few libraries for geospatial appl

[go-nuts] [ANN] Go geospatial libraries: geometries, GeoJSON, WKB, KML, PostGIS, GPX, polyline

2016-11-13 Thread Tom Payne
A quick announce of a few libraries for geospatial applications that are now mature and battle-tested: https://github.com/twpayne/go-geom : efficient geometry library, using a high-performance cache-friendly data representation (more info