Re: [go-nuts] runtime : Callers and CallersFrames is expensive , can i cached CallersFrames 's result .

2021-07-27 Thread 'Ian Cottrell' via golang-nuts
Not sure if it the same issue, but one problem is that runtime.CallersFrames returns a *Frames, which means it does an allocation. It would be nice to have a call that either returned a Frames by value, or one that takes a frame to reset and fill in. On Tuesday, 27 July 2021 at 16:18:17 UTC-4 I

Re: [go-nuts] Is there +v Stringer interface?

2020-06-24 Thread 'Ian Cottrell' via golang-nuts
You want to implement fmt.Formatter . In general I prefer implementing Formatter to either Stringer or GoStringer if I am only doing it for printing, even for the simple cases, as I feel it better reflects the intent. I reserve implementing the String metho

Re: [go-nuts] Understanding logic behind failing nil check

2019-11-21 Thread 'Ian Cottrell' via golang-nuts
Because the return of call1 is not nil, you gave it a proper type before you packed it into the error interface. see https://golang.org/doc/faq#nil_error for an explanation. This bites most go programmers at least once. On Thu, Nov 21, 2019 at 10:33 AM Kevin wrote: > hi all, > Im relatively new

Re: [go-nuts] Parsing go.mod

2019-09-03 Thread 'Ian Cottrell' via golang-nuts
The parsing code will eventually be public, see https://github.com/golang/go/issues/31761 When it is done, you would want golang.org/x/mod/modfile, which will be a (possibly modified) copy of the compiler internal package of the same name. On Tue, Sep 3, 2019 at 3:29 AM Paul Jolly wrote: > > So

Re: [go-nuts] custom build tags - seeing which files get selected

2019-05-14 Thread 'Ian Cottrell' via golang-nuts
./... is a wildcard pattern that matches directories including and below the current one go list -f '{{.GoFiles}}' -tags MYTAGS ./... should do what you want. *From: *'White Hexagon' via golang-nuts *Date: *Tue, May 14, 2019 at 11:17 AM *To: *golang-nuts Thanks Ian. > > I should have mentioned

Re: [go-nuts] goimports performance degrades in go module

2018-11-08 Thread 'Ian Cottrell' via golang-nuts
Hi, Could you try the module aware fork of goimports https://github.com/heschik/goimports and let us know if it works and is acceptable speed wise? We are not merging it back yet because we think it may be slower for non module users, and we want some more confidence that it is a drop in replaceme

Re: [go-nuts] Locate source code path (to import for code gen) of go module enabled project.

2018-11-06 Thread 'Ian Cottrell' via golang-nuts
You can use golang.org/x/tools/go/packages and call packages.Load. It will accept both directory names and package names as the patterns. Let us know if you need any more information! On Tue, Nov 6, 2018 at 11:35 PM bsr wrote: > How can I find

Re: [go-nuts] Why can't we use unicode? [Go2 Generics]

2018-09-07 Thread 'Ian Cottrell' via golang-nuts
The same thing works in any X system that supports compose, probably bound to the Shift+AltGr On Fri, Sep 7, 2018 at 12:29 PM roger peppe wrote: > In acme (and plan 9 generally), there's a nice set of mnemonic > abbreviations for unicode characters. > It's great, and I miss it in other environme

Re: [go-nuts] Calling the Go compiler inside of tests

2017-12-15 Thread 'Ian Cottrell' via golang-nuts
You could just use the go/types package to typecheck the result instead of compiling it, depending on exactly what you want to check that may be enough. On Fri, Dec 15, 2017 at 8:37 AM Tamás Gulácsi wrote: > When you invoke "go test", it compiles a test binary and calls that. > Why can't you ju

Re: [go-nuts] Re: Eliminating redundant map lookups

2016-11-27 Thread 'Ian Cottrell' via golang-nuts
Yes you will get two map operations happen, one lookup and one assign. Wrapping the code into a (mildly modified for pretty output) runnable example: https://play.golang.org/p/oGKvfS9ssH In the basic case of a new key, there is no way to avoid doing both a lookup and assign, but in the case where