I'm currently playing with Go, was wondering what are the patterns for defining the data types. For example take the Bencode and representing it as a Go data structure.
data BEncode = BInt Integer
| BString L.ByteString
| BList [BEncode]
| BDict (Map String BEncode)
in C, we can do something like this
struct Bencoding;
typedef struct ListNode {
struct Bencoding *cargo;
struct ListNode *next;
} ListNode;
typedef struct DictNode {
char *key;
struct Bencoding *value;
struct DictNode *next;
} DictNode;
typedef struct Bencoding {
BType type;
union {
long long val; // used when type == BInt
ListNode *list; // used when type == BList
char *str; // used when type == BString
DictNode *dict;
} cargo; // data
} Bencoding;
what is the best way to define these kinds of data structures in Golang. Are there any patterns / good practices with Golang.