Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 641 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Anonymous Structs in Go

#1
This is just a short tutorial about using anonymous structs in Go, which can be very handy when dealing with JSON server responses (especially from Facebook).

So say you have this JSON response from the server:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


and you want to put `lights` into a Go struct that looks like this:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


with anonymous structs you can now do this with ease!


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


[To see links please register here]

is a link to a Go playground where I implemented this example.

Good luck with your Go coding!
Reply

#2
That's interesting... So what exactly would creating an anonymous struct accomplish when dealing with server sent JSON repsonse(s)?
Reply

#3
Quote:(02-08-2017, 07:33 PM)Hoss Wrote:

[To see links please register here]

Quote: (02-08-2017, 07:28 PM)DarkMuse Wrote:

[To see links please register here]

That's interesting... So what exactly would creating an anonymous struct accomplish when dealing with server sent JSON repsonse(s)?

because you don't always want the outer JSON object, you just want the data portion. To do this without an anonymous struct you would have to define a new type like:

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


and then create an instance of that type and after you populate it with the response you have to extract the Lights map.

Facebook responses look like this:

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


and so I would make an anonymous struct to extract the data objects from the data tag, maybe like:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

That's fucking dope dude. You're a legend.
Reply

#4
Quote:(02-08-2017, 07:28 PM)DarkMuse Wrote:

[To see links please register here]

That's interesting... So what exactly would creating an anonymous struct accomplish when dealing with server sent JSON repsonse(s)?

because you don't always want the outer JSON object, you just want the data portion. To do this without an anonymous struct you would have to define a new type like:

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


and then create an instance of that type and after you populate it with the response you have to extract the Lights map.

Facebook responses look like this:

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


and so I would make an anonymous struct to extract the data objects from the data tag, maybe like:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through