Golang Anonymous Struct

So with go exported structs it is not fair to say they can be used interchangeably if at any point that instance is used as a parameter, field, or variable that defines the type? In the examples given in the article, the thing that is used as parameters is the interface Client not the concrete type HTTPClient. Show how to make cross-domain requests by JSONP (JSON with Padding) technique, which allows data to be retrieved from servers of other domains. go pointer Exporting functions with anonymous struct as a parameter golang pass struct to function (2) Here is a piece of code play. Anonymous Structure and Field in Golang A structure or struct in Golang is a user-defined type, which allows us to create a group of elements of different types into a single unit. Anonymous Structs and Unions Sometimes, it's nice to control the layout of a struct with nested structs and unions. package reflect Golang reflect. go - Golang interface cast to embedded struct I want to implement a collision library using the interface Collidable type Collidable interface{ BoundingBox() (float64,float64,float64,float64) FastCollisionCheck(c2 Collidable) bool DoesCollide(c2 Collidable) bool Collide(c2 Collidable) }. < 2/27 > 2/27 > structs. The two pieces of code are not valid C nor valid C++. embedded fields in struct. go-model library provides handy methods to process struct with below highlighted features. The only difference between composition and inheritance in Go, is a struct which inherits from another struct can directly access the methods and fields of the parent struct. // Every Go program is made up of packages. Structs have fields. Go is a general-purpose language designed with systems programming in mind. Each generated message struct type embeds an anonymous XXX_InternalExtensions field, thus gaining the unexported 'extensions' method, which can be called only from the proto package. A struct is a group of values called fields, often of different types, that are collected together in a single object that can be treated as a unit. type Mammal struct {Lung string} type Fish struct {Gills string}. And we wanted to create a new Android struct. What makes Go language different from the crowd is that the built-in string type is a value type. Go で struct のタグ情報を取得する Go で struct に付けたタグ情報を取得してみる。忘れないようのメモ。 タグ情報を取得するには reflect パッケージを使ってやればよい。. package reflect Golang reflect. The Go Playground is a web service that runs on golang. I could have enumerated all possible versions and sizes, but in order to save space 12 I've used a sample. For more information and other documents, see golang. Anonymous fields - when naming conflicts arise What happens when more than one of the composed structs or the composing struct has the same field name. Constants in Go, when combined with iota, can be a nice way to use options and settings as a list. struct or a structure can be compared with class concept in Object Oriented Programming. There are two types of interfaces in GoLang: empty interface and non-empty one. When we add the struct the second way, we can just access that field by using the type directly with the dot syntax. package builtin. The below is a common pattern for firing multiple goroutines (as anonymous functions) and waiting for them to complete execution. On the other hand, Go’s encoding/json uses runtime reflection to iterate members of a struct and detect their types. One structure can be declared inside other structure as we declare structure members inside a structure. So, when a method with a value-receiver is used with defer, the receiver will be copied (in this case Car) at the time of registering and the changes to it wouldn’t be visible (Car. Golang transparently converts the value to a pointer when the method is invoked. This multi-line statement creates the table; it is an initializer expression, where the type is an anonymous struct. Fairly new to golang and my intention is to learn the language. Even that reflection is not idiomatic for Golang. You will know why later on this article. Standard Library Encoding and decoding JSON in Go is pretty straightforward since it's part of the standard library encoding/json: [code]package main import ( ";encoding/json" "log" "time" ) type Person struct { Name string. So you can pass Human as well as Coder’s object. Learn to work efficiently with Files. Anonymous struct (and its standard library friends) to the rescue! Interfaces can be anonymous, the most common being interface {}. For example in the case of the Person struct above, although the fields are anonymous, by default they take the name of the type of the fields. This is a very useful feature in Golang and, if needed, you can find more info about it here. a pointer to the underlying array length of the slice capacity of the slice You can see this in slice. The struct statement defines a new data type, with more than one member for your program. Unmarshal maps an XML element to a string or []byte by saving the concatenation of that element's character data in the string or []byte. Anonymous interface implementation in Golang. < 2/27 > 2/27 > structs. type Mute. Always use a channel (chan) or a struct with a chan to communicate with a go routine. We use the BroadcastTo method of socketio. In golang, the functions like extends and override are implemented through composite. Sizeof 메소드는 해당 변수의 크기값을 반환한다. ) The special prefix & returns a pointer to the struct value. To understand why GoLang handles concurrency better, you first need to know what concurrency exactly 1 is. Anonymous structures also have their benefits, for example when using the Golang templates: In this case, there’s no need to declare a named type for the data argument to pass to the Execute(io. It is packed with many features. [2] It is a statically-typed language with syntax loosely derived from that of C, adding automatic memory management, type safety, some dynamic-typing capabilities, additional built-in types such as variable-length arrays and key-value maps, and a large. Draft is a tool to streamline your Kubernetes development experience. It comes from a service that is not under your control, so you cannot do much about the schema. 原 golang 结构体 ; 8. A struct is an aggregate data structure - it allows you to aggregate together values of different types and hold them all in ONE value - a struct. Let's start by looking at the main data type, a struct with five functions. Functional programming (FP) is a programming paradigm, a style of building the structure and elements of computer programs, that treats computation as the evaluation of mathematical functions and avoids state and mutable data. 12 release branch is because a false positive was uncovered, which we want fixed for Go 1. type person struct { name string age int } func main() { // This syntax creates a new struct. Now I need to build the room, can you give me an idea about what I should do? Antworten Löschen. An anonymous reference to a function from within itself is named #0, arguments to that function are named #1,#2. 主要有两种方式,如下:第一种方式,通过 var 初始化 123var user struct{Name string;age int}user. The flag default key string is the struct field name but can be specified in the struct field's tag value. Anonymous fields in structs - like object composition Other topics in this series - Table of Contents Go allows you to define a struct that has fields but with no variable names. Anonymous structs are not allowed in C++. January 9, 2016 Prashant Thakkar array, Go, Golang, map, slice, struct Leave a comment Control Flows The best part of programming in GO is that there are not multiple ways of doing standard things and that makes reading code and understanding it easier. On the other side slice (array) and map are reference types "as usual":. We can define a function inline without having to name it. You can list just a subset of fields by using the Name: syntax. Structs are what you would use to create data structures in Go. In this example, Rectangle has an anonymous field of type Shape. This is an example of full-stack Go, which uses Golang to develop web applications in both front-end and backend. Types can also have zero or more anonymous fields. Anonymous Field. Thanks Evan, I was trying to redeclare the struct just once for all the array elements and I couldn't find a way that worked. This is not to say that Golang is a silver bullet for all our problems. Marshalling in GoLang. Rust和golang之结构体 ; 6. [FreeCourseSite. Whatever fields and methods Shape have will be visible on Rectangle objects. Dot Net Perls has example pages for many languages, with explanations and code side by side (for easy understanding). The same applies to GoLang. Tags are like metadata, and allow us to use the encoding/json package to directly unmarshal the API's response into our struct. Anonymous struct and union. Golang transparently converts the value to a pointer when the method is invoked. com] Udemy - Learn How To Code Google's Go (golang) Programming Language could be available for direct download. Build massively concurrent programs with Go Routines and Channels. JSON and struct composition in Go Say you are decoding a JSON object into a Go struct. Go-lang cho phép chúng ta định nghĩa 1 struct theo cách rất thông thường như ngôn ngữ C/C++. Since this is a C only feature, the C++ implementations don't allow to anonymous struct/union to have private or protected members, static members, and functions. Answer: Go programming provides another data type called interfaces which represents a set of method signatures. Golang has the ability to declare and create own data types by combining one or more types, including both built-in and user-defined types. Looks like removing the anonymous struct is the way to Go as everyone suggested. That's why very frequently used structs like Vector3 are implemented as structs instead of classes. A goroutine is a lightweight thread managed by the Go runtime. A struct is a collection of fields. If the program contains tests or examples and no main function, the service runs the tests. So you can pass Human as well as Coder's object. Rectangle has an anonymous. A value of // zero indicates that record processing is caught up, and there are no new // records to process at this moment. type person struct { name string age int } func main() { // This syntax creates a new struct. Anonymous struct fields are usually marshaled as if their inner exported fields were fields in the outer struct, subject to the usual Go visibility rules amended as described in the next paragraph. anonymous structs匿名结构体 ; 2. This program will make the learners proficient in golang. Go is an open source programming language that makes it easy to build simple, reliable, and efficient software. First I think is wrong to try to do something with something which is not equipped with functionality to do the thing in the first place, but I must agree is rather mind twisting. * A non-pointer anonymous struct field is handled as if the fields of its value were part of the outer struct. The same applies to GoLang. It comes from a service that is not under your control, so you cannot do much about the schema. Anonymous type. To me, Go’s support for anonymous functions is most reminiscent of the anonymous function support in JavaScript; it is not the flimsy kind of anonymous function support you get with Python’s lambdas (one statement only) or Ruby’s situation where there are multiple ways to create closures (I’m not a rubyist, so the whole proc/block/lambda/Method thing seems very convoluted to me). All programmers must know the control flows like if-else, switch case, for loop,break,continue,return. Golang long-polling: a tale of server timeouts I had to learn about Go struct embedding the other day and I wanted to document my fix. Remember that the passed params to a deferred func are saved aside immediately without waiting for the deferred func to be run. // Mutexes can be created as part of other structures; // the zero value for a Mutex is an unlocked mutex. How does the anonymous struct approach you've accepted differ from the suggestion that you were adamantly against? My apologies. A struct is a group of values called fields, often of different types, that are collected together in a single object that can be treated as a unit. You will know why later on this article. A Quick Guide to Golang for Java Developers In Java we have Classes, but in Go we have structs. Works: package main import "sync" type myLocker struct { sync. The C Way Before C11 C didn't allow for anonymous structs or unions, which meant that dummy member names were necessary:. type GetRecordsOutput struct { // The number of milliseconds the GetRecords response is from the tip of the // stream, indicating how far behind current time the consumer is. The structure variables can be a normal structure variable or a pointer variable to access the data. The same applies to GoLang. Move() } Note that calling Move() when the anonymous interface field is nil crashes the program. type Pet struct { name string } type Dog struct { Pet Breed string } func ( p * Pet ) Speak () string { return fmt. Anonymous struct type literals are also allowed to be used in composite literals. type Credentials ¶ type Credentials struct { // contains filtered or unexported fields} A Credentials provides concurrency safe retrieval of AWS credentials Value. Golang transparently converts the value to a pointer when the method is invoked. 7 Using Anonymous struct Declarations. go Syntax Imports. Target Audience: This masterclass is ideal for developers (or anyone) interested in making a career in GoLang. We can test a wide variety of cases in one function with an anonymous struct slice (thanks to Andrew Gerrand's talk and David Cheney's article on test tables for this idea). In reality Anonymous fields appear to be an is-a relationship by exposing embedded methods and properties as if they existed on the outer struct. Anonymous type. They’re useful for grouping data together to form records. struct or a structure can be compared with class concept in Object Oriented Programming. Reference. I want the first value to take precedence. go - Golang interface cast to embedded struct I want to implement a collision library using the interface Collidable type Collidable interface{ BoundingBox() (float64,float64,float64,float64) FastCollisionCheck(c2 Collidable) bool DoesCollide(c2 Collidable) bool Collide(c2 Collidable) }. Even that reflection is not idiomatic for Golang. How to convert a slice of bytes in uppercase in Golang? How to set the foreground color of the CheckBox in C#?. For example a struct defines String() method is considered as a Stringer interface and whenever an object of this struct is printed, the String() method would be called to print the data. Golang: Access anonymous fields in structs. So with go exported structs it is not fair to say they can be used interchangeably if at any point that instance is used as a parameter, field, or variable that defines the type? In the examples given in the article, the thing that is used as parameters is the interface Client not the concrete type HTTPClient. A slice is a structure of 3 fields. Object-oriented. Tag: Golang Uncategorized Memory management under the hood We can use anonymous structs to write very clear table tests that have multiple inputs and expected. In the past I've used C++ , a lot of Java and a bit of Scala. The golang control flow statements are used to break the flow of execution by branching,looping, decision making statements by enabling program to execute code based on the conditions. GitHub Gist: instantly share code, notes, and snippets. That means methods of anonymous interface fields are seen as if they are methods of the embedding struct. Currently it is not possible to write a struct literal without mentioning its type. Thanks Evan, I was trying to redeclare the struct just once for all the array elements and I couldn't find a way that worked. Generate Golang struct (model) from Postgres tables A handy Postgres SQL statement to generate Golang models (structs) for you. I want the first value to take precedence. There is no constructor construct in the Go language. You can embed anonymous types inside each other. Fortunately we did not have to come up with a solution that works for us from scratch but could just implement the concepts we build up in tidus in Golang. The package contains structs that allow you to obtain information about the application and to dynamically emits types, values, and objects to the program. This program is customized and can be tailored to suit specific project needs for corporate teams interested in partaking. To define a structure, you must use type and struct statements. Interfaces and dynamic typing¶ In Go there are no classes: data (structures, or more general types) and methods are treated orthogonally, they are much more loosely coupled. 请尽量让自己的回复能够对别人有帮助; 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码` 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet. This type of field is called an anonymous field. When the embedded field is a struct, all the fields in that struct will implicitly be the fields in the struct in which it has been embedded. Master the full power of Methods and Interfaces (Go OOP). When you want the equivalent of Java's dynamic method lookup, use an interface. I'm following your post to creat a simple chat server. When we add the struct the second way, we can just access that field by using the type directly with the dot syntax. Sizeof 메소드는 해당 변수의 크기값을 반환한다. Embedded/Anonymous struct Multi-level nested struct/map/slice Pointer and…. package main import "fmt" type Mover interface { Move() } type Car struct { Mover } But, what is embedded interface? Let’s add some more fields to Car and print it with %v. A value of // zero indicates that record processing is caught up, and there are no new // records to process at this moment. A struct (short for "structure") is a collection of data fields with declared data types. Off the bat, Go supports anonymous functions and closures. Here are a few examples in named and anonymous forms. Please try again later. package main import "fmt" // This `person` struct type has `name` and `age` fields. I wasn't aware of "anonymous structs" when I read your response, and I assumed that your proposal required explicitly creating a new named type. Concurrency is the composition of independently executing computations: better, is a way to write clean code that interacts well with the real world. This is a very useful feature in Golang and, if needed, you can find more info about it here. Here is a basic example of how an anonymous function, or lambda function, can be used with Go. Promoted methods. < 2/27 > 2/27 > structs. ctypes is a foreign function library for Python. Struct in Golang // Go's _structs_ are typed collections of fields. What is the meaning of anonymous interface Interface in struct reverse? nhannguyen09cntt October 12, 2019, 9:50am #2 In this way reverse implements the sort. The Go Playground is a web service that runs on golang. part of an external library) or maybe you want to serialize the same type in different kinds. Credentials will cache the credentials value until they expire. It comes from a service that is not under your control, so you cannot do much about the schema. You declare which package a source file is in (and all of its constants, types, functions, etc) by typing package at the top of the source file; however, unlike Java, you don’t put the full path (directory location), just the name. This is a cool feature of Go, in which you can pass the structs which are implementing that interface. I found the excellent. You can also use a pointer to a struct. 雖然 Golang 沒有類別,但是「建構體(Struct)」就十分地堪用了,首先你要知道在 Golang 中「類別」的成員還有方法都是在「類別」外面所定義的,這跟 PHP 在類別內定義的方式有所不同,在 Golang 中還有一點,那就是他們沒有 public、private、protected 的種類。. The Ultimate Comprehensive Course - Perfect for Both Beginners and Experienced Developers. golang类和结构体 ; 5. However this would mean we’d need a general Post struct type with the union of all possible properties on a Post across all post types. Is there any way to express the various paths and return possibilities for this function concisely in our unit tests? Certainly. It's followed by the name of the type (Circle), the keyword struct to indicate that we are defining a struct type and a list of fields inside of curly braces. I've just introduced to you how to define a struct with field names and type. It's born from typical need while developing Go application or utility. The empty struct is a struct type that has no fields. A struct is a collection of fields; Fields accessed using a dot; A package exports only names starting with a capital letter; type Vertex struct { X int Y int } func main() { v := Vertex{1, 2} v. Usually however you define the type of serialization via type tags as part of the struct declaration. A minor correction (this is also in the link you posted): One major difference between structs and classes is that the instances of structs live in the stack, while classes live in the heap. Go maps in action. // Programs start running in package main. The way anonymous field works is to embed a specific type into a field but does not give it a name. In case you are a Node. Then on line 110, a supply of nails is declared via the nails field. The struct statement defines a new data type, with more than one member for your program. You declare which package a source file is in (and all of its constants, types, functions, etc) by typing package at the top of the source file; however, unlike Java, you don’t put the full path (directory location), just the name. // Mutexes can be created as part of other structures; // the zero value for a Mutex is an unlocked mutex. type Pet struct { name string } type Dog struct { Pet Breed string } func ( p * Pet ) Speak () string { return fmt. Go functions may be closures. ; UnmarshalText in values and keys of maps. This post explores the properties of my favourite Go data type, the empty struct. A struct is a type which contains named fields. On the closest thing Golang has to a style guide found here, under Receiver Names this is written:. We can create anonymous. Looks like removing the anonymous struct is the way to Go as everyone suggested. org's servers. Types can also have zero or more anonymous fields. However, functional knowledge on GitHub, and new programming language is an added advantage. I want to create a function called merge() that takes in two values of the same struct, but of any struct, and returns the merged values of the two structs. The structure variables can be a normal structure variable or a pointer variable to access the data. Slices of struct{}s consume only the space for their slice header. This is a reference manual for the Go programming language. type Credentials ¶ type Credentials struct { // contains filtered or unexported fields} A Credentials provides concurrency safe retrieval of AWS credentials Value. Teknik ini cukup efisien untuk pembuatan variabel objek yang struct-nya hanya dipakai sekali. The structs that give access to the metadata of a running program are in the reflect package. ; UnmarshalText in values and keys of maps. Anonymous functions can accept inputs and return outputs, just as standard functions do. This program is customized and can be tailored to suit specific project needs for corporate teams interested in partaking. D provides a limited form of anonymous nested struct and union, but they can't be used to translate this C anonymous struct:. I have the following structures: type base interface { func1() func2() common_func() } type derived1 struct { base // anonymous meaning inheritence data DatumType } type derived2 struct { base // anonymous meaning inheritence data DatumType }. Unity is the ultimate game development platform. This program will make the learners proficient in golang. Go by Example: Closures Go supports anonymous functions , which can form closures. // They're useful for grouping data together to form // records. When the embedded field is a struct, all the fields in that struct will implicitly be the fields in the struct in which it has been embedded. In go lang, functions are surprising quite flexible, they can be used as values and passed around, and anonymous functions with closure are supported. go supports anonymous functions which can form closures. Functions (also known as procedures or subroutines) are often represented as a black box: (the black box represents the function). A person "is a" soccer player and Go supports these relationships with embedded types. Ultimate Go study guide, with heavily documented code and programs analysis all in 1 place → Ultimate Go If you're interested in weekly coding interview. To define a structure, you must use type and struct statements. Anonymous struct (and its standard library friends) to the rescue! Interfaces can be anonymous, the most common being interface {}. Well, we have covered some of the major Data Strucutres for Golang in this chapter. Of course, you can embed fields in an anonymous struct. When you want the equivalent of Java’s dynamic method lookup, use an interface. Also, while defining this struct, you are also mapping all properties of your struct into its JSON equivalent. golang 并发任务 数据结构 ; 3. In the past I've used C++ , a lot of Java and a bit of Scala. While not all of those have a database, some of them do. Did you know you can use anonymous structs in Go? A co-worker and I discovered this when trying to figure out an easy way to format data to send to the json Marshal method in the standard library. Anonymous functions are useful when you want to define a function inline without having to name it. In fact, Go supports fields without names, but with types. The Go Playground is a web service that runs on golang. 07 by Antti Holappa · golang, struct, anonymous I started learning Go when I joined Comptel FWD in January 2015. tag The type name given to the structure. Build massively concurrent programs with Go Routines and Channels. Golang has the ability to declare and create own data types by combining one or more types, including both built-in and user-defined types. go; Printf and reflection¶ Printf uses the reflection package to unpack it and discover the argument list, print. Prerequisites: familiarity with programming language. It comes from a service that is not under your control, so you cannot do much about the schema. Golang transparently converts the value to a pointer when the method is invoked. go), then we then fire off another, anonymous goroutine to send the received WorkRequest object to the worker. What makes Go language different from the crowd is that the built-in string type is a value type. Is there any way to express the various paths and return possibilities for this function concisely in our unit tests? Certainly. The variables are used to store some data at a particular memory address in the system. Published Sep 01, 2017. [FreeCourseSite. As mentioned in the cgo documentation: As Go doesn't have support for C's union type in the general case, C's union types are represented as a Go byte array with the same length. While not all of those have a database, some of them do. In your package you define an interface and a struct/implementation. This field denotes that post struct is composed of author. We can test a wide variety of cases in one function with an anonymous struct slice (thanks to Andrew Gerrand's talk and David Cheney's article on test tables for this idea). If you embed a nameless struct then the embedded struct provides its state (and methods) to the embedding struct directly. The service receives a Go program, vets , compiles, links, and runs the program inside a sandbox, then returns the output. We have also added details () method to the post struct which prints the title, content, fullName and bio of the author. A struct field that has no name is an embedded field. Since then we have implemented some of our new services in Golang. Also, notice that when we embed structs into other structs they inherent the methods as well. It is for this reason that we call them anonymous fields (the lack of a name). Rectangle has an anonymous. ↓↓↓↓↓↓双十一来了,京东图书满200减120! ↓↓↓↓↓↓ ↑↑↑↑↑↑双十一来了,京东图书满200减120!. It is a declarative programming paradigm, which means programming is done with expressions. “real life is full of extreme edge cases”. Person is added as an anonymous field in the SoccerPlayer struct. Anonymous structs Cheaper and safer than using map[string]interface{}. When you embed Mover interface in Car, type Car struct { Mover }. Golang is very handy and easy. go), then we then fire off another, anonymous goroutine to send the received WorkRequest object to the worker. Since then we have implemented some of our new services in Golang. type Football struct {*Ball} Because it’s a pointer, be aware of nil pointer panics. In Go language, you are allowed to create an anonymous structure. go, here https. type FlyingCreature struct { Creature WingSpan int }. // Programs start running in package main. The below is a common pattern for firing multiple goroutines (as anonymous functions) and waiting for them to complete execution. Always use a channel (chan) or a struct with a chan to communicate with a go routine. An anonymous struct field with a name given in its JSON tag is treated as having that name, rather than being anonymous. 예를들어 스트링변수라면 golang 1. This field denotes that post struct is composed of author. Thus you can do p. Functional programming (FP) is a programming paradigm, a style of building the structure and elements of computer programs, that treats computation as the evaluation of mathematical functions and avoids state and mutable data. Note that we send a message of type “message” so the client will have to check for “message” coming in as well. A struct is a collection of fields. type GetRecordsOutput struct { // The number of milliseconds the GetRecords response is from the tip of the // stream, indicating how far behind current time the consumer is. An internal anonymous goroutine sleeps some random time up to one second and then writes the sum to the channel, closes it, and returns it. org's servers. We will create simple employee struct, that have name, age and salary property. Something like this in Django is common where a context dictionary with multiple objects is passed back to the template for rendering:. The reason we want to disable this enhancement of the check in the Go 1. Handling 1 Million Requests per Minute with Go Jul 6, 2015. The structs that give access to the metadata of a running program are in the reflect package. When you want the equivalent of Java's dynamic method lookup, use an interface. A value of // zero indicates that record processing is caught up, and there are no new // records to process at this moment. It comes from a service that is not under your control, so you cannot do much about the schema. 12 release branch is because a false positive was uncovered, which we want fixed for Go 1. part of an external library) or maybe you want to serialize the same type in different kinds. There is no way to add additional methods onto an anonymous struct, however. The below is a common pattern for firing multiple goroutines (as anonymous functions) and waiting for them to complete execution. We call these embedded fields. type GetRecordsOutput struct { // The number of milliseconds the GetRecords response is from the tip of the // stream, indicating how far behind current time the consumer is. package main import "fmt" // This `person` struct type has `name` and `age` fields. Embedded/Anonymous struct Multi-level nested struct/map/slice Pointer and…. Using Anonymous Structs to pass data to templates in GoLang. Sure, it is possible to create a factory function that will initialize and return a struct, but you can't force a client to use it. Data Structures – Struct 304 Structs Introduction 305 OOP in Go 306 User-Defined Types 307 Composition 308 JSON Marshal 309 JSON Unmarshal 310 JSON Encode 311 JSON Decode. For more information, refer to the __declspec keyword. In golang, the functions like extends and override are implemented through composite. This post explores the properties of my favourite Go data type, the empty struct.