Re: [go-nuts] Implementing an EventBus in Go

2019-03-10 Thread Kasun Vithanage
Hi were you talking about something like this? I used channels over callbacks. I quickly prototyped it. Is this approach better or we have to do improvements? package main import ( "fmt" "math/rand" "sync" "time" ) type Data struct { data interface{} topic string } type ChannelSlice []chan Da

Re: [go-nuts] Implementing an EventBus in Go

2019-03-10 Thread Kasun Vithanage
Thanks, I was wondering whether we can replace callbacks with channels. The same way it is used in here, instead of calling a function we can also send the data to a channel associated with the receiver. like var subs = make(map[string] []chan string) func publish(topic string, data string) { g

[go-nuts] Re: Packaging a Go module for Nix

2019-03-10 Thread Wael Nasreddine
On Sunday, March 10, 2019 at 5:01:01 PM UTC-7, Manlio Perillo wrote: > > On Monday, March 11, 2019 at 12:30:02 AM UTC+1, Wael Nasreddine wrote: >> >> TL;DR Given a Go module, assuming that I have already done `go mod >> download`: Is it possible to prevent network access if I delete the entire >>

Re: [go-nuts] sync/atomic and zero-initialization

2019-03-10 Thread Ian Lance Taylor
On Sun, Mar 10, 2019 at 7:54 PM shivaram via golang-nuts wrote: > > Can users of sync/atomic assume that memory will initially be zeroed? Or is > it necessary for a manual zeroing (using the atomic store operations) to > happen-before any reads? > > Context: https://github.com/golang/go/issues/5

[go-nuts] Re: Packaging a Go module for Nix

2019-03-10 Thread Wael Nasreddine
On Sunday, March 10, 2019 at 6:44:10 PM UTC-7, Manlio Perillo wrote: > > On Monday, March 11, 2019 at 2:06:44 AM UTC+1, Wael Nasreddine wrote: >> >> >> >> On Sunday, March 10, 2019 at 5:01:01 PM UTC-7, Manlio Perillo wrote: >>> >>> On Monday, March 11, 2019 at 12:30:02 AM UTC+1, Wael Nasreddine wro

Re: [go-nuts] Implementing an EventBus in Go

2019-03-10 Thread Randall O'Reilly
for reference, here is a very basic Qt-style signal / slot style subscribe / publish model in Go, just using a map of receivers and their receiver callback functions: https://github.com/goki/ki/blob/master/ki/signal.go - Randy > On Mar 10, 2019, at 11:07 PM, Kasun Vithanage wrote: > > Yes, wh

Re: [go-nuts] Implementing an EventBus in Go

2019-03-10 Thread Kasun Vithanage
My intention is to implement it myself. I was wondering whether to go plain old callback way where a subscriber can subscribe to a topic and callback is fired when a topic is updated. I was really wondering how to utilize go's channels to improve this pattern and gain performance. My final inte

[go-nuts] http handler called twice if server.WriteTimeout

2019-03-10 Thread wangyun
The /sleep-6s handler is called twice if set server.WriteTimeout to 3s and handler cost 6s. And if don't call "get-1" handler, the "sleep-6s" handler will not be called twice, why is that happen? server code: https://play.golang.org/p/DngpDOfb05W client code: https://play.golang.org/p/jNQHIurac

Re: [go-nuts] Implementing an EventBus in Go

2019-03-10 Thread Kasun Vithanage
Yes, when a publisher publish for a topic it should be routed to all subscribers to that topic :) On Monday, March 11, 2019 at 10:28:17 AM UTC+5:30, Burak Serdar wrote: > > On Sun, Mar 10, 2019 at 10:41 PM Kasun Vithanage > wrote: > > > > Hi all, > > > > I've experience implementing event bu

Re: [go-nuts] Implementing an EventBus in Go

2019-03-10 Thread Marcin Romaszewicz
Channels are producer/consumer queues, they don't handle one to many broadcasting, you'd need one channel per subscriber then you'd queue the message to each of them. In my opinion, they work more nicely than callbacks, since your handler can run in its own execution context, and not in the callbac

Re: [go-nuts] Implementing an EventBus in Go

2019-03-10 Thread Burak Serdar
On Sun, Mar 10, 2019 at 10:41 PM Kasun Vithanage wrote: > > Hi all, > > I've experience implementing event buses in Java. > In Java, I used a singleton where I can register callbacks to methods and > fire event from a publisher(maybe from another thread) and propagate it to > subscribers. > > In

[go-nuts] Implementing an EventBus in Go

2019-03-10 Thread Kasun Vithanage
Hi all, I've experience implementing event buses in Java. In Java, I used a singleton where I can register callbacks to methods and fire event from a publisher(maybe from another thread) and propagate it to subscribers. In Go what would be the best pattern to implement a pub/sub event bus? Ar

Re: [go-nuts] Pointer declaration syntax

2019-03-10 Thread Rob Pike
& turns a value into a pointer. * turns a pointer into a value. Whether a pointer should be declared with & or * or "ptr" or anything else is an arbitrary decision made the way it was by the Go designers because, as Ian says, C did it with *. -rob On Mon, Mar 11, 2019 at 10:22 AM Michael Jones

[go-nuts] sync/atomic and zero-initialization

2019-03-10 Thread shivaram via golang-nuts
Can users of sync/atomic assume that memory will initially be zeroed? Or is it necessary for a manual zeroing (using the atomic store operations) to happen-before any reads? Context: https://github.com/golang/go/issues/5045 has the suggestion that "you shouldn't mix atomic and non-atomic access

[go-nuts] Re: Packaging a Go module for Nix

2019-03-10 Thread Manlio Perillo
On Monday, March 11, 2019 at 12:30:02 AM UTC+1, Wael Nasreddine wrote: > > TL;DR Given a Go module, assuming that I have already done `go mod > download`: Is it possible to prevent network access if I delete the entire > `$GOPATH/pkg/mod/cache`? > > Another solution is to delete only $GOPATH/pkg/

[go-nuts] Re: Packaging a Go module for Nix

2019-03-10 Thread Manlio Perillo
On Monday, March 11, 2019 at 2:06:44 AM UTC+1, Wael Nasreddine wrote: > > > > On Sunday, March 10, 2019 at 5:01:01 PM UTC-7, Manlio Perillo wrote: >> >> On Monday, March 11, 2019 at 12:30:02 AM UTC+1, Wael Nasreddine wrote: >>> >>> TL;DR Given a Go module, assuming that I have already done `go mod

[go-nuts] Re: Packaging a Go module for Nix

2019-03-10 Thread Wael Nasreddine
On Sunday, March 10, 2019 at 5:01:01 PM UTC-7, Manlio Perillo wrote: > > On Monday, March 11, 2019 at 12:30:02 AM UTC+1, Wael Nasreddine wrote: >> >> TL;DR Given a Go module, assuming that I have already done `go mod >> download`: Is it possible to prevent network access if I delete the entire

[go-nuts] Re: Packaging a Go module for Nix

2019-03-10 Thread Manlio Perillo
On Monday, March 11, 2019 at 12:30:02 AM UTC+1, Wael Nasreddine wrote: > > TL;DR Given a Go module, assuming that I have already done `go mod > download`: Is it possible to prevent network access if I delete the entire > `$GOPATH/pkg/mod/cache`? > > Yes. Use `go mod vendor` and the -mod=vendor b

[go-nuts] Packaging a Go module for Nix

2019-03-10 Thread Wael Nasreddine
TL;DR Given a Go module, assuming that I have already done `go mod download`: Is it possible to prevent network access if I delete the entire `$GOPATH/pkg/mod/cache`? Hello, I'm a member of Nix , and I'm attempting to create a new infrastructure for packaging Go modules

Re: [go-nuts] Pointer declaration syntax

2019-03-10 Thread Michael Jones
If you consider lv and rv in BCPL, and see how that becomes * and & in B and stays that way in C/C++/... it may be more clear. The C declaration syntax was revolutionary for being inside out. “int *p” really means “p is the type of variable where *p means an int.” Your argument seems right, in the

[go-nuts] Re: still confused on how to use Go modules

2019-03-10 Thread T L
I removed the unnecessary dependencies in go.mod and uploaded the repo to another place. It can be imported now. On Sunday, March 10, 2019 at 1:52:55 AM UTC-5, T L wrote: > > I would admit I made a mistake here, by putting some unnecessary > dependencies > in the go.mod file (https://github.com/

Re: [go-nuts] Pointer declaration syntax

2019-03-10 Thread 박민우
Thank you for the explanation! and sorry for the typo, I meant to say something like, someInteger := 0 q := &someInteger or q := &SomeStructure{} as an example of & symbol as "pointer to". Anyway, I would say C's declaration syntax int *p makes more sense because *p , "where p points to", is int

Re: [go-nuts] Pointer declaration syntax

2019-03-10 Thread Yamil Bracho
& just returns an memory address and a variable is just that, a memory address. That the reason you can not apply & to a type... El dom., 10 mar. 2019 a las 10:41, 박민우 () escribió: > I am new to Go and I have read Go;s-declaration-syntax > document

[go-nuts] Re: Go playground to support none-standard modules

2019-03-10 Thread jake6502
You can setup and run your own playground with https://github.com/golang/playground. I have not done it myself, but you could probably use that to do what you propose. On Saturday, March 9, 2019 at 9:50:15 PM UTC-5, Tong Sun wrote: > > I know Go playground does not support none-standard modul

Re: [go-nuts] Pointer declaration syntax

2019-03-10 Thread Ian Lance Taylor
On Sun, Mar 10, 2019 at 7:41 AM 박민우 wrote: > > I am new to Go and I have read Go;s-declaration-syntax documentation. > > It states that: > > p: pointer to int > > Would be written as: > p *int > > However, other than declaration syntax, "&" is the symbol for "the pointer > to" like, > q := &int >

[go-nuts] Pointer declaration syntax

2019-03-10 Thread 박민우
I am new to Go and I have read Go;s-declaration-syntax documentation. It states that: p: pointer to int Would be written as: p *int However, other than declaration syntax, "&" is the symbol for "the pointer to" like, q := &int The above code w

[go-nuts] Re: http request entity too large

2019-03-10 Thread Stevo Slavić
I've just created improvement request https://github.com/golang/go/issues/30715 On Wednesday, February 1, 2017 at 12:07:52 PM UTC+1, Nicolas Martyanoff wrote: > > Is there any update regarding this issue ? The inability to make the > difference between an error triggered by the request size and