Follow

@utahcon so is map[string]interface{} in golang similar to casting to a null pointer for a struct in c?

Reading go is strangely familiar and yet so foreign...

@rage That feels like a loaded question, even still I will attempt to answer it.

A map in Go is a key/value pair (most like an array in C).

interface{} in Go is an "empty interface", which may hold value of ANY type.

When you call "map[string]interface{}" you are telling Go that your map will have values of type string, and values of ANY type.

The best C equivalent would be an array, except C arrays don't allow for keys instead of indices, so the example falls apart.

@rage though to be fair I am not 100% sure what a null pointer for a struct in C would equate to in Go... it's just been too long

@rage If you haven't (but I am sure you have) take the A Tour of Go at tour.golang.org it explains a lot of this with a live editor and runtime you can play with. Also try out things in the Go Playground at play.golang.org

@utahcon I'll check that out before asking any more ignorant questions lol

Thanks!

@rage sorry that came off as a RTFM, which I guess it was, but I am happy to help you along. I went through the tour a bunch of times to grok it all, and it still didn't click until I started doing things. I had most recently been developing in Python so all my experience is more related there, but happy to help.

@utahcon no worries! I have been reading the docs, but I didn't try the tour.

Sign in to participate in the conversation
Fosstodon

Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.