Re: [go-nuts] Get a copy of reflect.Value's underlying value

2017-07-31 Thread Josh Humphries
You have to use a temporary to swap the values: tmp := a.Interface() a.Set(b) b.Set(reflect.ValueOf(tmp)) *Josh Humphries* jh...@bluegosling.com On Mon, Jul 31, 2017 at 10:18 AM, eZio Pan <eziopa...@gmail.com> wrote: > Hello, > I want to build a "univers

[go-nuts] atomic package pointer operations with maps and channels

2017-08-11 Thread Josh Humphries
vice versa, is disallowed? We're already using the unsafe package, so I can't think of a clear reason to prevent this. ---- *Josh Humphries* jh...@bluegosling.com -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this grou

Re: [go-nuts] atomic package pointer operations with maps and channels

2017-08-12 Thread Josh Humphries
On Fri, Aug 11, 2017 at 6:22 PM, Ian Lance Taylor <i...@golang.org> wrote: > On Fri, Aug 11, 2017 at 2:51 PM, Josh Humphries <jh...@bluegosling.com> > wrote: > > > > It is possible to extract a map's actual value/address if it is stored in > >

Re: [go-nuts] Get a copy of reflect.Value's underlying value

2017-08-01 Thread Josh Humphries
Although that solution creates a heap-allocated tmp for every element in the slice. Using an interface, the value will be inlined instead of heap-allocated if it fits without boxing (so most primitive types and pointer types won't need heap allocation). *Josh Humphries* jh...@bluegosling.com

Re: [go-nuts] Get a copy of reflect.Value's underlying value

2017-08-01 Thread Josh Humphries
On Tue, Aug 1, 2017 at 11:44 AM, roger peppe <rogpe...@gmail.com> wrote: > On 1 August 2017 at 13:57, Josh Humphries <jh...@bluegosling.com> wrote: > > Although that solution creates a heap-allocated tmp for every element in > the > > slice. Using an interface, the

Re: [go-nuts] Get a copy of reflect.Value's underlying value

2017-08-01 Thread Josh Humphries
On Tue, Aug 1, 2017 at 2:43 PM, roger peppe <rogpe...@gmail.com> wrote: > On 1 August 2017 at 19:33, Josh Humphries <jh...@bluegosling.com> wrote: > > On Tue, Aug 1, 2017 at 11:44 AM, roger peppe <rogpe...@gmail.com> wrote: > >> > >>

[go-nuts] chaining contexts, best practices question

2017-08-08 Thread Josh Humphries
implement our own cancellation propagation -- like a goroutine that will stop the server(s) when the root context gets cancelled. I'm curious how others tackle these kinds of concerns. *Josh Humphries* jh...@bluegosling.com -- You received this message because you are subscribed to the

Re: [go-nuts] Re: Is this bad concurrency?

2017-08-18 Thread Josh Humphries
goroutines have completed (e.g. cancel the context and then await, provided you've added to the wait group for each task and each one marks their work as done on completion). *Josh Humphries* jh...@bluegosling.com On Fri, Aug 18, 2017 at 5:19 PM, <bill.war...@talentinc.com> wrote: > Thank

Re: [go-nuts] Create methods for structs at runtime

2017-06-20 Thread Josh Humphries
This is a problem that is usually solved in Go with code generation. You would use a go:generate directive to generate implementations for an interface of interest. Something like java.lang.reflect.Proxy in Go would be very cool though. *Josh Humphries* jh...@bluegosling.com On Tue, Jun 20

Re: [go-nuts] Iota with string constants

2017-10-16 Thread Josh Humphries
-of-week by defining the constants in order. With strings, you have to use a custom compare function that acts on string names (ick). *Josh Humphries* jh...@bluegosling.com On Sun, Oct 15, 2017 at 4:13 PM, <m...@inanc.io> wrote: > Is it anything wrong just assigning string values t

Re: [go-nuts] Converting type map[string]interface {} to type map[interface {}]interface {}

2017-08-21 Thread Josh Humphries
You can't convert between maps with different types of keys or values. So you have to copy the map into one with the correct target type: https://play.golang.org/p/qmD2pypNbj *Josh Humphries* jh...@bluegosling.com On Mon, Aug 21, 2017 at 10:48 AM, Tong Sun <suntong...@gmail.com>

Re: [go-nuts] Re: golang and http2

2017-11-15 Thread Josh Humphries
at you are doing, and thus it requires you to be more explicit in both client and server code to make it work. *Josh Humphries* jh...@bluegosling.com On Wed, Nov 15, 2017 at 3:43 PM, Albert Tedja <nicho.te...@gmail.com> wrote: > Thank you for the links. > > I am still somewhat di

Re: [go-nuts] How to get explicit receiver of a method through reflect?

2017-11-22 Thread Josh Humphries
a factory method that takes a function and adapts it to the interface. And then the value can be used both to invoke the logic (by calling the one method of the interface) and for inspecting its concrete type and value. *Josh Humphries* jh...@bluegosling.com On Wed, Nov 22, 2017 at 8:26 AM

Re: [go-nuts] How to get explicit receiver of a method through reflect?

2017-11-23 Thread Josh Humphries
a function that does not capture a method receiver, and then your interpretation of whatever you read using unsafe will likely cause memory corruption and/or a program crash. *Josh Humphries* jh...@bluegosling.com On Wed, Nov 22, 2017 at 8:46 PM, Hoping White <baihaop...@gmail.

Re: [go-nuts] Union types mindset

2017-11-20 Thread Josh Humphries
rfaces (this is a common pattern in Go, to make sure any change to a concrete type to make it *not* implement a particular interface result in a compile-time error). *Josh Humphries* jh...@bluegosling.com On Mon, Nov 20, 2017 at 4:27 PM, 'Paulo Matos' via golang-nuts < golang-nuts@googleg

[go-nuts] type returned by reflect.ArrayOf breaks the spec

2017-11-06 Thread Josh Humphries
an example of this erroneous behavior. Demonstrations of these issues: https://play.golang.org/p/Qu0irn2rCF I am guessing I should just file a bug in a Github issue, but wanted to first check to see if this, somehow, might be expected behavior. (And if so, to learn why.) *Josh Humphries* jh

Re: [go-nuts] tests for variadic functions

2018-05-23 Thread Josh Humphries
The syntax you are looking for is: max(test.vals...) The ellipsis indicates that the var args are the *contents* of the slice, as opposed to trying to pass the slice as if it were just a single element of the var args. *Josh Humphries* jh...@bluegosling.com On Wed, May 23, 2018 at 7:09

Re: [go-nuts] Mixed type array in Go

2018-01-04 Thread Josh Humphries
("unsupported type: %T", e))* *}* *}* ---- *Josh Humphries* jh...@bluegosling.com On Thu, Jan 4, 2018 at 10:24 AM, Tong Sun <suntong...@gmail.com> wrote: > I need a data struct / solution that I can store mixed data-types into an > array. How to architect that? >

Re: [go-nuts] “Design Patterns: Elements of Reusable Object-Oriented Software” in Go

2018-02-02 Thread Josh Humphries
in Wikipedia -- likes more like its a related pattern: the decorator (sometimes known as the interceptor pattern). *Josh Humphries* jh...@bluegosling.com On Fri, Feb 2, 2018 at 12:03 PM, <matthewju...@gmail.com> wrote: > I’m looking at patterns summarized on Wikipedia from “Design Patterns: &

Re: [go-nuts] Deploying protobuf code on AppEngine standard

2018-02-01 Thread Josh Humphries
d the rest of your code). ---- *Josh Humphries* jh...@bluegosling.com On Thu, Feb 1, 2018 at 6:31 AM, s2gatev <m...@s2gatev.com> wrote: > Hey there! > > I'm trying to convert an AppEngine flexible setup to standard environment. > I hit a problem with a piece of code that depends on

Re: [go-nuts] “Design Patterns: Elements of Reusable Object-Oriented Software” in Go

2018-02-08 Thread Josh Humphries
to produce. (For example, the ASM <http://download.forge.objectweb.org/asm/asm4-guide.pdf> library for Java.) > > -rob > > > On Thu, Feb 8, 2018 at 2:14 PM, Josh Humphries <jh...@bluegosling.com> > wrote: > >> FWIW, it looks like someone else has gone through this

Re: [go-nuts] “Design Patterns: Elements of Reusable Object-Oriented Software” in Go

2018-02-07 Thread Josh Humphries
FWIW, it looks like someone else has gone through this exercise: https://github.com/tmrts/go-patterns *Josh Humphries* jh...@bluegosling.com On Fri, Feb 2, 2018 at 12:03 PM, <matthewju...@gmail.com> wrote: > I’m looking at patterns summarized on Wikipedia from “Design Patterns: &

Re: [go-nuts] Re: “Design Patterns: Elements of Reusable Object-Oriented Software” in Go

2018-02-08 Thread Josh Humphries
On Wed, Feb 7, 2018 at 5:45 PM, roger peppe wrote: > As someone totally unfamiliar with the GoF patterns, hre's my take. > I looked at the wikipedia articles and tried to work out what > problem I thought the pattern was trying to address and then > wrote some Go code to do

Re: [go-nuts] Appreciating Go

2018-02-22 Thread Josh Humphries
On Thu, Feb 22, 2018 at 4:56 AM, Steven Hartland wrote: > On 22/02/2018 09:46, andrewchambe...@gmail.com wrote: > > Just a list of things I like about Go, thanks everyone for the hard work: > > snip... > > Minor things that could be improved in order of importance: > > -

Re: [go-nuts] Re: JSON and Embedded Types (Aliases)

2018-01-22 Thread Josh Humphries
to int). *Josh Humphries* jh...@bluegosling.com On Mon, Jan 22, 2018 at 5:58 PM, Dan Kortschak < dan.kortsc...@adelaide.edu.au> wrote: > This is sort of surprising though: https://play.golang.org/p/mjfkzIqAo_b > > On Mon, 2018-01-22 at 10:20 -0800, C Banning wrote: > &

Re: [go-nuts] Re: JSON and Embedded Types (Aliases)

2018-01-22 Thread Josh Humphries
d *P.T *T// conflicts with embedded field T and *P.T *P.T // conflicts with embedded field T and *T } So it is possible that this is not a bug in the encoding/json package but in the compiler. *Josh Humphries* jh...@bluegosling.com On Mon, Jan 22, 2018 at 7:28 PM, Josh Humphri

Re: [go-nuts] Re: JSON and Embedded Types (Aliases)

2018-01-22 Thread Josh Humphries
(based on the type alias names), but the field's type is simply int (which is not exported due to starting with lower-case letter). *Josh Humphries* jh...@bluegosling.com On Mon, Jan 22, 2018 at 3:12 AM, 'Axel Wagner' via golang-nuts < golang-nuts@googlegroups.com> wrote: > On Mo

Re: [go-nuts] Re: JSON and Embedded Types (Aliases)

2018-01-23 Thread Josh Humphries
ames are upper-cased. I think this is either a bug in reflect -- which should set StructField.PkgPath to "" since the field name is exported -- OR a bug in the compiler which should complain that there are three fields whose resolved name appears to be the unexported identifier "int&

Re: [go-nuts] go-grpc question

2018-10-17 Thread Josh Humphries
n when using standard Kubernetes services (when using gRPC for >> server-to-serve communication), as kubedns resolves a service name into a >> single virtual IP. I'm not sure if the current state of the world regarding >> TCP load balancers and the grpc-go project, but if it's still

Re: [go-nuts] go-grpc question

2018-10-17 Thread Josh Humphries
state of the world regarding TCP load balancers and the grpc-go project, but if it's still an issue and you run services in Kubernetes, you can use a 3rd party resolver: https://github.com/sercand/kuberesolver. *Josh Humphries* jh...@bluegosling.com On Wed, Oct 17, 2018 at 2:13 AM wrote

Re: [go-nuts] protoc question

2018-11-18 Thread Josh Humphries
onment. But you can also use a --plugin flag to protoc to tell it exactly where the plugin binary lives. *Josh Humphries* jh...@bluegosling.com On Sun, Nov 18, 2018 at 4:57 PM Tharaneedharan Vilwanathan < vdhar...@gmail.com> wrote: > Hi All, > > I have a minor question. When I run

Re: [go-nuts] Rethink possibility to make circular imports

2018-11-30 Thread Josh Humphries
On Fri, Nov 30, 2018 at 8:50 AM Michel Levieux wrote: > Hi guys, > > I've been trying to find examples of cases where it is complicated to > structure the project because circular imports are forbidden, but I can't > find something simple that I can show you. The thing is when I've been >

Re: [go-nuts] getting a reflect.Type for a type

2018-12-05 Thread Josh Humphries
On Wed, Dec 5, 2018 at 12:16 PM Burak Serdar wrote: > On Wed, Dec 5, 2018 at 10:12 AM Mark Volkmann > wrote: > > > > I can get a reflect.Type for a variable with the following: myType := > reflect.TypeOf(myVariable) > > > > How can I get a reflect.Type for a type I have defined? > > For

Re: [go-nuts] How to append nil using reflect

2019-01-11 Thread Josh Humphries
On Fri, Jan 11, 2019 at 5:59 PM Xinhu Liu wrote: > Hi Ian, > > thanks for your reply. > > After reading and experimenting a lot I think I understand the slight > differences between nil and interface{} with nil value. > > The only thing I find confusing is that interface{}(nil) == nil returns >

Re: [go-nuts] golang gRPC question

2018-09-12 Thread Josh Humphries
On Wed, Sep 12, 2018 at 9:05 AM robert engels wrote: > Hi, I am adding a remote component to my github.com/robaho/keydb project > and decided to use gRPC. > > I’ve reviewed the docs, and it appears to want to be stateless - which > given the nature of Google makes sense. > > But for something

Re: [go-nuts] Re: How to end producer from the consumer side

2019-01-22 Thread Josh Humphries
On Tue, Jan 22, 2019 at 8:33 AM wrote: > Hi, we have the same problem of OP. > But, in the Chris's playground there could be an error, indeed if the > consumer > runs slower of the producer the program ends in a deadlock. > > To force this behavior just add a time.Sleep() after the foor loop in