Re: [go-nuts] Re: How to mock functions in Go ?

2019-08-01 Thread Edward Muller
This can also be done without an interface: https://play.golang.org/p/fgRX2nXIxn0 In ^ example “Thing” would be the type you are working on, with functional options (https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis

Re: [go-nuts] How to implement a file download service in GRPC

2019-07-31 Thread Edward Muller
https://github.com/grpc-ecosystem/grpc-gateway > On Jul 30, 2019, at 4:12 PM, Rampradeep Nalluri > wrote: > > It is easy to pipe a file reader to http.ResponseWriter object using > io.copy() when I implement a large file download service over

Re: [go-nuts] Re: invitation to gophers.slack.com

2017-01-20 Thread Edward Muller
Great! On Fri, Jan 20, 2017 at 11:16 AM Jan Mercl <0xj...@gmail.com> wrote: > > On Fri, Jan 20, 2017 at 7:06 PM Edward Muller <edwar...@interlix.com> > wrote: > > > https://invite.slack.golangbridge.org/ instead, which is where people > should go to signup

Re: [go-nuts] Is slice in golang thread-safe for appending

2017-01-19 Thread Edward Muller
Which may or may not have the same backing array. https://play.golang.org/p/GsffpJc1cX PS: I probably should have just said 'no. slices are not "thread-safe"'. I have complicated the issue to no benefit. On Thu, Jan 19, 2017 at 2:56 PM Jason Stillwell wrote: > But it

Re: [go-nuts] Is slice in golang thread-safe for appending

2017-01-19 Thread Edward Muller
No, it is not.* * appending can replace the underlying array, so in certain situations it can be, but that's more by accident IMO so just don't rely on that. On Thu, Jan 19, 2017 at 1:43 PM xiaohai dai wrote: > I know that map in golang is not thread-safe for writing. >

Re: [go-nuts] Downloading go1

2016-12-08 Thread Edward Muller
> > On Fri, Dec 2, 2016 at 4:17 PM, Brad Fitzpatrick <bradf...@golang.org> > wrote: > > I've asked for a list of our objects under that prefix. > > > On Thu, Dec 1, 2016 at 1:56 PM, Edward Muller <edwar...@interlix.com> > wrote: > > For $reasons I nee

Re: [go-nuts] Re: Downloading go1

2016-12-01 Thread Edward Muller
I could, but for other $reasons I'd rather not if I don't have to. I will if it's lost to history though. On Thu, Dec 1, 2016 at 2:10 PM James Bardin wrote: > > Can you build it from source? > The repo of course contains the entire history. > > > > On Thursday, December 1,

Re: [go-nuts] Noob question: Pointers to interfaces

2016-11-09 Thread Edward Muller
Sounds like it's also more than a map[type]interface{} and more like either map[type][]interface{} or a map[type]map[uuid]interface{}. And that's somewhat naive as well. I'd probably implement a method to store and fetch each "type" that the ECS could actually care about, which could probably be

Re: [go-nuts] Noob question: Pointers to interfaces

2016-11-07 Thread Edward Muller
Based on that example, I'm even more confused about what you are trying to accomplish. Can we take a step back and forget about the implementation of a solution and describe the problem you are working on? On Mon, Nov 7, 2016 at 19:08 Kaylen Wheeler wrote: > Here's what I

Re: [go-nuts] Noob question: Pointers to interfaces

2016-11-07 Thread Edward Muller
Then just use pointers (see lines 45+): https://play.golang.org/p/vl47WDHOdN On Mon, Nov 7, 2016 at 4:50 PM Kaylen Wheeler wrote: I want pointers because I want most components to be structs, and I want the ability to modify the fields in those structs. On Monday, 7

Re: [go-nuts] Noob question: Pointers to interfaces

2016-11-07 Thread Edward Muller
Why do you want to use pointers? On Mon, Nov 7, 2016 at 4:42 PM Kaylen Wheeler wrote: > Thanks for the "basic pattern" example here. There's one little > modification I'm wondering about. > > Can this line: > > rv.Elem().Set(m[rv.Type()]) > > be changed to this? > >

Re: [go-nuts] Noob question: Pointers to interfaces

2016-11-07 Thread Edward Muller
This was also my swag at an example: https://play.golang.org/p/QG7g9veKEI PS: it's still not strictly "type safe". On Mon, Nov 7, 2016 at 4:46 PM Edward Muller <edwar...@interlix.com> wrote: > Why do you want to use pointers? > > On Mon, Nov 7, 2016 at 4:42 P

Re: [go-nuts] Noob question: Pointers to interfaces

2016-11-07 Thread Edward Muller
FWIW: As soon as interface{} is involved you are no longer "type safe". On Mon, Nov 7, 2016 at 2:56 PM Kaylen Wheeler wrote: > So, what I'm trying to accomplish is a little unusual, and may need some > explanation. > > Basically, I'm trying to find a typesafe way to access

Re: [go-nuts] Re: Golang should have a center packages index hosting like npm, rust crates

2016-10-26 Thread Edward Muller
Yes, use that proposal's format. Re: godoc. Great idea. if no one else is interested in doing the work I'll be happy to take a look into it. I've been looking for an excuse to work with gddo On Wed, Oct 26, 2016 at 1:42 PM Dave Cheney wrote: > Indeed. If only there was some

Re: [go-nuts] Re: Golang should have a center packages index hosting like npm, rust crates

2016-10-26 Thread Edward Muller
Please start tagging your releases with semver tags. Start now, there is no reason to wait. On Wed, Oct 26, 2016 at 03:13 Dave Cheney wrote: > I'd very much like to see that. > > https://github.com/golang/go/issues/12302 > >

Re: [go-nuts] Go 1.7.3 is released

2016-10-19 Thread Edward Muller
See: https://github.com/golang/go/issues/17519 & https://github.com/golang/go/issues/17276 On Wed, Oct 19, 2016 at 1:48 PM Tim Henderson wrote: > I can reproduce that error. Here is my `go env` output the test output is > identical. > > $ go env > GOARCH="amd64" > GOBIN="" >

Re: [go-nuts] Re: Reading http.Request.Body...

2016-10-11 Thread Edward Muller
There is also ReadAtLeast (https://golang.org/pkg/io/#ReadAtLeast) On Tue, Oct 11, 2016 at 3:13 PM forfader wrote: > Thank you. I figured there was such a function. Just couldn't find it. > > Michael- > > > On Tuesday, October 11, 2016 at 2:31:41 PM UTC-7, forfader wrote: >

Re: [go-nuts] Re: [ANN] gorram: like go run for any* function in stdlib or GOPATH

2016-10-11 Thread Edward Muller
gorram -r <...> On Mon, Oct 10, 2016 at 3:02 PM Mathieu Lonjaret wrote: > Looks shiny! > But is there some sort of cache I have to clear? I've just updated and > rebuilt, and I still get the old behaviour. > > > On 8 October 2016 at 04:05, Nate Finch

Re: [go-nuts] Correct use of Mutex

2016-10-03 Thread Edward Muller
type Foo struct { sync.RWMutex data map[string]bool } o := {} o.Lock() o.data[i] = true o.Unlock() elsewhere o.RLock() v := o.data[i] o.RUnlock() On Mon, Oct 3, 2016 at 11:55 AM wrote: > > Which is correct? > > o.Lock() > o.data[i] = true > o.Unlock() > > or > >

Re: [go-nuts] encode struct as JSON, and use it in http.NewRequest ( io.Writer vs. io.Reader issue )H

2016-10-03 Thread Edward Muller
See also https://golang.org/pkg/io/#Pipe On Sat, Oct 1, 2016 at 9:13 PM Shawn Milochik wrote: > How about https://golang.org/pkg/bytes/#NewReader ? > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe

Re: [go-nuts] Mocking os.Open and related calls for more code coverage

2016-09-27 Thread Edward Muller
One option is to adjust the method to take an io.ReadCloser instead of a path so you could pass in anything that supported the io.ReadCloser interface (which is easily adapted to via ioutil.NoCloser(io.Reader)). Another option is to generate a temporary file with data you want to test with and

Re: [go-nuts] How Golang implements slice?

2016-09-13 Thread Edward Muller
lement even if the descriptor tells us there are only 3, by >> using package unsafe <https://golang.org/pkg/unsafe/>, and doing some >> simple pointer calculation. It shows that function calls may modify the >> slice in parameters under the cover, which is a bad thing if it is not o

Re: [go-nuts] How Golang implements slice?

2016-09-12 Thread Edward Muller
On Mon, Sep 12, 2016 at 8:17 PM Fei Ding wrote: > Hi guys: > > I met a problem when I try to understand slice when using as function > parameters. After writing some code, I made a conclusion by myself, but > need some real check and explanation here, with your help. > > As

Re: [go-nuts] Best way to extract hostname from "host" or "host:port" style?

2016-09-12 Thread Edward Muller
There is probably some code here ( https://github.com/golang/go/commit/1ff19201fd898c3e1a0ed5d3458c81c1f062570b) you can lift until go1.8 comes out. On Mon, Sep 12, 2016 at 8:17 PM Jonathan Yu wrote: > Hi, > > I tried searching Google, but didn't find anything. I'm

Re: [go-nuts] Re: job queue with the ability to kill worker processes

2016-09-06 Thread Edward Muller
There is also: https://github.com/bgentry/que-go On Tue, Sep 6, 2016 at 12:56 PM Tieson Molly wrote: > Thanks Jason, I was looking for something to handle external processes. > > > > On Monday, September 5, 2016 at 11:13:59 AM UTC-4, Jason E. Aten wrote: >> >> On Thursday,

Re: [go-nuts] why this code deadlocks?

2016-09-01 Thread Edward Muller
Thanks, I should have checked the spec. On Thu, Sep 1, 2016 at 11:14 AM Darren Hoo wrote: > I don't think so. > > see https://golang.org/ref/spec#Select_statements > > If one or more of the communications can proceed, a single one that can > proceed is chosen via a uniform

Re: [go-nuts] on GOPATH

2016-09-01 Thread Edward Muller
For projects that are mostly not go (or go is a component anyway) you could do $HOME/project/src/ and then point $GOPATH=$HOME/project. You can use 2 different segments in $GOPATH (GOPATH=/foo/bar:/bar/foo) and go get will place go gettable packages in the first segment of $GOPATH. On Thu, Sep 1,

Re: [go-nuts] why this code deadlocks?

2016-09-01 Thread Edward Muller
I think you can still deadlock, but I'm not sure if the `default:` case is considered for random selection of a select like other branches are. It would just be less deterministic. On Thu, Sep 1, 2016 at 10:38 AM Darren Hoo wrote: > Got it, using buffered channel works for

Re: [go-nuts] why this code deadlocks?

2016-09-01 Thread Edward Muller
If you execute it you are told on which lines the deadlock happens... fatal error: all goroutines are asleep - deadlock! goroutine 1 [chan send]: main.main.func2() /Users/emuller/go/src/github.com/freeformz/tt/main.go:25 +0xce main.main()

Re: [go-nuts] dynamic frequency ticker

2016-08-30 Thread Edward Muller
How about something like this? https://play.golang.org/p/U50n3cqIXg On Tue, Aug 30, 2016 at 12:42 PM Aaron Cannon < cann...@fireantproductions.com> wrote: > How about creating a custom ticker that uses time.Sleep. There might > be some hidden caveats when using time.Sleep verses a real ticker

Re: [go-nuts] Invalid JSON document from 'go list -json std'

2016-08-22 Thread Edward Muller
`go list -json std | jq` does not complain, which is my usual "is my json valid" test. On Sat, Aug 20, 2016 at 12:13 PM Lars Tørnes Hansen wrote: > I expected that > go list -json std > ... would output a valid JSON document, because > go help list > writes: > The -json flag

Re: [go-nuts] Best practice for sets in go?

2016-07-26 Thread Edward Muller
I encourage people to use the later form because of the duality of a bool (true or false) and the fact that it implies meaning. When you see the bool you have to start considering the false path. I'd much prefer the extra few bytes for the longer inclusion checks because there is no ambiguity in

[go-nuts] GoBridge Appreciation Breakfast @ GopherCon

2016-07-06 Thread Edward Muller
We (Heroku) are sponsoring the Gophercon 2016 kickoff breakfast of gratitude: http://www.meetup.com/gobridge/events/229149949/ Please sign up if you are interested. Thanks! -- You received this message because you are subscribed to the

Re: [go-nuts] String Split Question

2016-07-06 Thread Edward Muller
https://play.golang.org/p/fOFT2voh6l > On Jul 5, 2016, at 2:57 PM, Freeman Fridie wrote: > > I have a data file with records in the following format: > > [field 1][field 2][field 3][field 4]... > > I need to be able to split the

Re: [go-nuts] encoding/json: any way to receive number literal "10.0" into integer field?

2016-06-17 Thread Edward Muller
AFAIK (and someone will probably provide something better) you need to do something like this: https://play.golang.org/p/riq-m6cgZu > On Jun 17, 2016, at 2:37 PM, jg...@bitgirder.com wrote: > > We have an upstream provider of JSON data which sends integer data > types as floating point