Re: [go-nuts] Could we trade all the `ctx context.Context` arguments for one pointer in `g`?

2024-02-22 Thread 'Alex Efros' via golang-nuts
Hi! One more thing to keep in mind for the proposal: sometimes we need to merge two contexts. https://github.com/golang/go/issues/36503 https://github.com/golang/go/issues/57928 -- WBR, Alex. -- You received this message because you are subscribed to the Google Groups

Re: [go-nuts] Extension for type assertion of interface array

2018-04-26 Thread Alex Efros
Hi! On Sun, Apr 22, 2018 at 09:48:13PM -0700, nsakth...@gmail.com wrote: > this pattern requires a language level change to avoid unwanted array copy [...] > but shouldn't the language provide an extension to already available syntax The language is trying to avoid hiding performance-critical

Re: [go-nuts] Re: Good Cyclomatic Complexity Number for Go

2018-04-13 Thread Alex Efros
Hi! On Fri, Apr 13, 2018 at 12:41:35PM -0700, Lee Painton wrote: > The only situation in which this limit has seemed unreasonable is when a > large number of independent cases followed a selection function (a large > case statement), which was allowed. Another situation is function which does

Re: [go-nuts] Correct way to bump a Go library to v2

2018-04-12 Thread Alex Efros
Hi! On Thu, Apr 12, 2018 at 08:34:28PM -0700, Nick Snyder wrote: > For (3) though, I am a little hesitant to delete the v1 code from master > since this will break people go getting v1. If you wanna support go both for v1 and v2 using current import path then you've no choice - you have to keep

Re: [go-nuts] net.Conn not returning error upon Write after being closed from far side.

2018-04-11 Thread Alex Efros
Hi! On Wed, Apr 11, 2018 at 10:19:21AM -0700, Ian Lance Taylor wrote: > You might want to open an issue about this. Done: https://github.com/golang/go/issues/24808 -- WBR, Alex. -- You received this message because you are subscribed to the Google Groups

Re: [go-nuts] net.Conn not returning error upon Write after being closed from far side.

2018-04-11 Thread Alex Efros
Hi! On Wed, Apr 11, 2018 at 07:35:50AM -0700, pierspowlesl...@gmail.com wrote: > So I believe I have found the source of this problem. A method Temporary is > defined on syscall.Errno, for a reason that is unclear to me ECONNRESET and > ECONNABORTED are considered temporary. I would definitely

Re: [go-nuts] net.Conn not returning error upon Write after being closed from far side.

2018-04-10 Thread Alex Efros
Hi! On Tue, Apr 10, 2018 at 07:58:29AM -0700, pierspowlesl...@gmail.com wrote: > I'm trying to understand what is going on under the hood here. SO_LINGER (see socket(7)) delay happens. Add this after Accept(): conn, err := listener.Accept() if err == nil { err =

Re: [go-nuts] TCP connection reuse when doing HTTP

2018-04-10 Thread Alex Efros
Hi! On Tue, Apr 10, 2018 at 06:14:46AM -0700, Sun Frank wrote: > my question is how to reuse underlying TCP connection when doing a lot of > frequent short HTTP requests using golang? This happens by default: https://play.golang.org/p/XnzQoGqQlno > they say the key is to close resp.Body Yes,

Re: [go-nuts] Regexp: Matching a new line but *not* start of string, from a Reader

2018-04-09 Thread Alex Efros
Hi! On Mon, Apr 09, 2018 at 08:57:04AM -0700, Paul Lalonde wrote: > The FindReaderSubmatchIndex may need to read arbitrarily far after the end > of the match, so if you want multiple matches you'll need a ReadSeeker and > re-wind to the end of the previous match. Ah, I see. So I should

Re: [go-nuts] Re: Regexp: Matching a new line but *not* start of string, from a Reader

2018-04-09 Thread Alex Efros
Hi! On Mon, Apr 09, 2018 at 04:09:55AM -0700, Tamás Gulácsi wrote: > A small hack can help: add someting at the beginning of the Reader (with > io.MultiReader) that won't allow the match on the beginning. Try to add "\n" at beginning of the stream and then start regexp with \n instead of ^. If

Re: [go-nuts] Regexp: Matching a new line but *not* start of string, from a Reader

2018-04-09 Thread Alex Efros
Hi! On Mon, Apr 09, 2018 at 09:25:02AM +0100, roger peppe wrote: > While we're on the subject, ISTM that FindReaderSubmatchIndex should > really return []int64 not []int. A bit late now though. BTW, is there any good example for FindReaderSubmatchIndex? I've just tried it with strings.Reader and

[go-nuts] colorful go test output

2018-04-05 Thread Alex Efros
Hi! When we run `go test` (without package param) it doesn't redirect os.Stdout, so it's possible to detect is it a TTY and enable color output: unix.IoctlGetTermios(int(os.Stdout.Fd()), ioctlReadTermios) But when we run `go test .` (with package param) it does redirect os.Stdout, so it's

Re: [go-nuts] Is there a build option to only consider the vendor folder for imports?

2018-04-04 Thread Alex Efros
Hi! On Tue, Apr 03, 2018 at 03:25:44PM -0700, roar...@zillowgroup.com wrote: > In an effort to make sure code that builds on my local machine will build > on our build machine, I am looking for a build option to force the compiler > to only look for imported code in the vendor directory & pkg.

Re: [go-nuts] Is it possible to unmarshall Json by selecting the struct from a field in the Json?

2018-03-29 Thread Alex Efros
Hi! On Thu, Mar 29, 2018 at 04:29:09AM -0700, gary.willoug...@victoriaplumb.com wrote: > Thanks for the all the responses but I was after a more dynamic solution > where you don't need to 'register' the types or select them using a switch > but that it just works. I believe this is just a

Re: [go-nuts] Is it possible to unmarshall Json by selecting the struct from a field in the Json?

2018-03-28 Thread Alex Efros
Hi! On Wed, Mar 28, 2018 at 02:13:55PM -0400, Shawn Milochik wrote: > Thanks for the challenge! I found some unused code in the getItem function, > and a way to make it a bit shorter by removing the lookup map. However, > depending on the number of struct types the map may be cleaner for OP. > >

Re: [go-nuts] Is it possible to unmarshall Json by selecting the struct from a field in the Json?

2018-03-28 Thread Alex Efros
Hi! On Wed, Mar 28, 2018 at 01:38:04PM -0400, Shawn Milochik wrote: > Yes, you can do this. Perhaps someone knows of some kind of cleaner > shortcuts to get there, but this works and is easy to understand without > any magic: > > https://play.golang.org/p/tqon7s2KxTz Here is a bit simplified

Re: [go-nuts] About a channel detail, bug, defect, or intended?

2018-03-24 Thread Alex Efros
Hi! On Sat, Mar 24, 2018 at 03:41:19AM -0700, T L wrote: > Shouldn't it be that the receive from the only buffer and fill next queuing > value to the only buffer in one atomic operation? AFAIR spec doesn't provide such a guarantee, so this isn't a bug. If you need to know when last value from

Re: [go-nuts] Copy a slice to new memory adresses

2018-03-23 Thread Alex Efros
Hi! On Fri, Mar 23, 2018 at 12:10:55PM -0700, Alex Dvoretskiy wrote: > For example, I have a multidimensional slice, which I want to modify, but > keep an original slice untouched. > > Do I need to do this all the time or there is another convenient way to do > this?: > >

Re: [go-nuts] How to read a JSON Response body

2018-03-20 Thread Alex Efros
Hi! On Tue, Mar 20, 2018 at 10:37:40AM -0700, st ov wrote: > json.Unmarshal(resp.Body, ) This one is invalid. > json.NewDecoder(resp.Body).Decode() > > or > > b, _ := ioutil.ReadAll(resp.Body) > json.Unmarshal(b, ) In the ReadAll case you'll have to allocate []byte in memory to store whole

Re: [go-nuts] Closing os.Stdin while trying to read from it?

2018-03-19 Thread Alex Efros
Hi! On Mon, Mar 19, 2018 at 05:52:52AM -0700, Matt Mueller wrote: > Is it possible to programmatically tell os.Stdin that we've reached EOF > while you're trying to read from it? As default os.Stdin is in blocking mode then only way to have it read EOF after calling Read() on it is to actually

Re: [go-nuts] Closing os.Stdin while trying to read from it?

2018-03-16 Thread Alex Efros
Hi! On Thu, Mar 15, 2018 at 12:49:15PM +, roger peppe wrote: > If it helps, you can set deadlines on *os.File now, as of Go 1.10: > >https://play.golang.org/p/h3Pg9Ql0CMB > > I don't see a way to cancel without deciding the deadline in advance though. Why? What makes os.Stdin so

Re: [go-nuts] Goroutines, Nonblocking I/O, And Memory Usage

2018-03-16 Thread Alex Efros
Hi! On Thu, Mar 15, 2018 at 09:09:18AM -0700, Rio wrote: > Yeah, there's no way to avoid the kernel buffer waste. You can tune kernel buffer size to minimize it. > > I did such a custom poller for a network proxy. It was a pain > > to get right (I only did the Eww!poll version). > > I tried

Re: [go-nuts] General question: complex search form and query params

2018-03-02 Thread Alex Efros
Hi! Many years ago I've implemented something similar in Perl, which was later released as https://metacpan.org/pod/DBIx::SecureCGI. Nowadays I suppose best way to do something like this is using GraphQL (for ex. https://github.com/graphql-go/graphql). -- WBR, Alex. --

Re: [go-nuts] Appreciating Go

2018-02-25 Thread Alex Efros
Hi! On Sun, Feb 25, 2018 at 01:51:08AM -0800, Maxim Ivanov wrote: > > type Time struct { > > Err error > > *time.Time > > } > Problem is that it continues to be product type, nothing really enforces > that you can't use t as a time.Time when

Re: [go-nuts] Appreciating Go

2018-02-25 Thread Alex Efros
Hi! On Sat, Feb 24, 2018 at 02:02:37PM -0800, Bakul Shah wrote: > r := os.Open(filename) > if isError(r) { return r.(error) } > f := r.(*os.File) // or better: var f *os.File; f = r > > Error checking being a common pattern, isError() can be added as a builtin > or trivially in errors pkg.

Re: [go-nuts] Re: Go += Package Versioning

2018-02-25 Thread Alex Efros
Hi! On Fri, Feb 23, 2018 at 06:23:33PM -0800, Spencer Nelson wrote: > Is it possible for me to have different minor/patch versions for different > modules in one repository? For example, suppose I have this: > > github.com/my/thing/go.mod > github.com/my/thing/blue/go.mod > > And