[go-nuts] Re: Go channels overused and hyped?

2017-08-09 Thread Caleb Doxsey
Channels are very useful and necessary to really get your program using all the resources at your disposal. Doing that with locks or callbacks is error prone and makes solving some problems all but impossible. Let me give you an example of a pattern we used a few days ago: We were processing

[go-nuts] Re: // go:generate won t work, //go:generate will

2017-04-30 Thread Caleb Doxsey
Hi, Just a reminder that Go is an open source project. Although changing go:generate probably isn't going to happen, your comment about lint not catching the issue seemed reasonable to me. So I went ahead and implemented it and created a pull request: https://github.com/golang/lint/pull/291

[go-nuts] Re: NewTicker leak

2017-04-14 Thread Caleb Doxsey
Hi Fabián, The reason that this isn't working is because time.Ticker contains a runtimeTimer field: r: runtimeTimer{ when: when(d), period: int64(d), f: sendTime, arg:c, }, This corresponds with a struct defined in runtime: // Package

Re: [go-nuts] anything much faster container.List

2017-02-27 Thread Caleb Doxsey
Hi Oleg, Use an unrolled list: https://en.wikipedia.org/wiki/Unrolled_linked_list In computer programming, an unrolled linked list is a variation on the > linked list which stores multiple elements in each node. It can > dramatically increase cache performance, while decreasing the memory >

[go-nuts] Re: How to generate generic code with generate?

2017-01-24 Thread Caleb Doxsey
er according to github star. > I wonder if there are any better packages out there , have u reach on > this? > > > 在 2017年1月23日星期一 UTC+8下午10:04:22,Caleb Doxsey写道: >> >> Hi, >> >> With github.com/badgerodon/goreify you can do this: >> >> //go:

[go-nuts] Re: How to generate generic code with generate?

2017-01-23 Thread Caleb Doxsey
Hi, With github.com/badgerodon/goreify you can do this: //go:generate goreify examples/min.Min numeric // Min finds the minimum value in a slice func Min(args ...generics.T1) (r generics.T1) { if len(args) == 0 { panic("the minimum of nothing is undefined") } r = args[0] for i := 1; i <

[go-nuts] Re: A question about the atomic operations in golang

2017-01-08 Thread Caleb Doxsey
Shouldn't this particular case be ok? From the memory doc: https://golang.org/ref/mem The go statement that starts a new goroutine happens before the goroutine's > execution begins. So the write has to happen before the goroutine starts. At least that's what the example indicates: > For

[go-nuts] Re: Behaviour manifested by select statement

2016-12-29 Thread Caleb Doxsey
Use time.After: package main import ( "log" "math/rand" "time" ) func randomSleep(min, max int64) <-chan time.Time { rand.Seed(time.Now().UnixNano()) sleepDuration := time.Duration(rand.Int63n(max-min)+min) * time.Millisecond log.Printf("Sleep duration:

[go-nuts] Re: How to use ~/ in terminal with go program?

2016-12-28 Thread Caleb Doxsey
You can use this library: https://godoc.org/github.com/mitchellh/go-homedir#Expand On Wednesday, December 28, 2016 at 8:22:06 AM UTC-5, Aurélien Desbrières wrote: > > As explain ~/ in golang , I > am trying to request the user to cat a file with a

[go-nuts] Re: Kafka with "At least once" for message delivery guarantees

2016-12-28 Thread Caleb Doxsey
These days I would recommend using the confluent consumer: https://github.com/confluentinc/confluent-kafka-go. It's just a wrapper around librdkafka. Sarama works fine too though. With all of these you can configure the behavior you are looking for. For example: request.required.acks would

[go-nuts] Re: Installing two go releases side-by-side

2016-12-16 Thread Caleb Doxsey
The easy solution here is gimme . $ eval "$(gimme 1.8beta2)" Downloads and installs go and sets all the environment variables for you. On Wednesday, December 14, 2016 at 11:58:55 AM UTC-5, aind...@gmail.com wrote: > > I currently have the distribution "go

[go-nuts] Re: Channels and Networks together

2016-12-15 Thread Caleb Doxsey
The challenge with the design of channels, is they need to be reliable to work properly, and networks are anything but reliable. Channels only really make sense within a single process. That said, there have been libraries developed which help make working with distributed systems easier The

[go-nuts] Re: Group and Sum slices

2016-10-11 Thread Caleb Doxsey
Go doesn't have LINQ, but it does have a database/sql package. If you're not afraid of using strings, probably the cleanest way to do this would be to use sqlite, an embedded database, that understands SQL and has support for in-memory tables. Here's a go binding:

[go-nuts] Re: time representation to use with javascript

2016-10-11 Thread Caleb Doxsey
One thing you could try is to use two ints. One to represent seconds and the other nanoseconds. This is what protobuf does: https://github.com/golang/protobuf/blob/master/ptypes/timestamp.go. An ISO8601 string works too. On Monday, October 10, 2016 at 11:22:48 PM UTC-4, bsr wrote: > > Hello, >

[go-nuts] Re: Go locking and channels much slower than Java equivalent, program spends most of time in sync.(*Mutex).Lock() and sync.(*Mutex).Unlock()

2016-10-02 Thread Caleb Doxsey
One thing you can try is to increase the number of locks so that the goroutines aren't all stopped on a single lock. For example you can partition your stores: https://play.golang.org/p/y16yr57KcQ type PartitionedStore struct { stores []Store } func NewPartitionedStore(sz int)

[go-nuts] Re: Handling multiple things happening at the same time

2016-09-10 Thread Caleb Doxsey
Why would you do this manually? You should use systemd to create a service. It will handle starting on load, logging, restarting when it crashes, etc. On Saturday, September 10, 2016 at 7:06:03 AM UTC-4, Simon Ritchie wrote: > > > maybe gocron can schedule the http.ListenAndServe to run all the

[go-nuts] Re: TCP Server

2016-07-17 Thread Caleb Doxsey
Hi Edgar, Have you done much web development in the past? The easiest option may be google app engine. You can create a restful HTTP API pretty easily and it comes with a lot of functionality out of the box. You can find a getting-started tutorial here:

[go-nuts] Re: database proxy ?

2016-06-27 Thread Caleb Doxsey
For postgres use pgbouncer. For mysql there's youtube's vitess. On Monday, June 27, 2016 at 12:24:32 PM UTC-4, Tieson Molly wrote: > > > Are there any existing packages or libraries that implement a generic > database/sql proxy? > > My goal was to create a small service that connected to the