Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing a map[string]someStruct through .Emit()/.Next() #122

Closed
rob-deutsch opened this issue Sep 19, 2018 · 7 comments
Closed

Passing a map[string]someStruct through .Emit()/.Next() #122

rob-deutsch opened this issue Sep 19, 2018 · 7 comments
Labels
kind/support A question or request for support

Comments

@rob-deutsch
Copy link

Hi all, I'm trying to add a feature to IPFS, and a command is being run over HTTP.

I am passing a theMap := map[string]someStruct{...} through .Next(*theMap) and I have confirmed its being sent over HTTP as a JSON object.

However, in the client where I receive it with .Next() for some reason I'm only getting the first someStruct (not even the key) of the map.

Am I using Emit/Next correctly? Should this work?

@rob-deutsch
Copy link
Author

rob-deutsch commented Sep 20, 2018

Oh! Looking at another part of the codebase I noticed that the Command struct takes a Type.

I think I've found the right investigation path: https://godoc.org/github.com/ipfs/go-ipfs-cmds#Command

@Stebalien
Copy link
Member

That sounds like the correct diagnosis. Really, we should be complaining loudly (logging? panicing? if Type isn't specified and we try to Emit something other than an io.Reader.

@rob-deutsch
Copy link
Author

Thanks for the confirmation.

In this case its totally my fault, though. I was hacking away at an existing piece of code that already had the type specified as someStruct{}. So I shouldn't be surprised at the results I was getting when I was emitting map[string]someStruct{} in certain situations.

I plan to modify my code now so that it always emits a map[string]someStruct{}. That is, if I want to emit a single someStruct{} I'll first wrap it in a map.

Does anything seem unreasonable about that?

@Stebalien
Copy link
Member

That sounds reasonable.

@Stebalien Stebalien added the kind/support A question or request for support label Sep 24, 2018
@Stebalien
Copy link
Member

(closing for tracking, feel free to continue discussing)

@rob-deutsch
Copy link
Author

Thanks. Sorry that I didn't close it myself.

@Stebalien
Copy link
Member

Np. I just like to close things before I forget about them for 3+ months 😄.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support A question or request for support
Projects
None yet
Development

No branches or pull requests

2 participants