2

I'm stuck in a situation and cannot figure out what I messed up. Easiest way to explain is probably some minimal example: http://play.golang.org/p/14lbOBsCCo

I am tying to modify a value of a struct via its pointer but end up modifing some memory other the part I want. Line 92 is where my issue is.

How would you debug a situation like this (tools etc.), and how do I get the broker.Port set?

Thanks for hints/suggestions!

1 Answer 1

6

You're not using pointers throughout. Start off with a Registry of type:

type Registry []*Broker

and work from there

Working example

As far as debugging tricks, this was my process:

  • Value isn't being changed, so something is being copied by value
  • Notice that Registry is type []Broker, but we want to modify Brokers, so it needs to be a pointer
  • Change type Registry to []*Broker
  • Keep attempting to compile, letting the compiler tell me every place we are using a value where we need a pointer (woohoo fast compile times and static typing)
Sign up to request clarification or add additional context in comments.

2 Comments

That's it! Your answer is almost as demeaning as "let me google this for you" :) Thanks!
I added a little more info, but sometimes it's the simple things ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.