Overview

We can have an unexported struct with exported fields. For example, consider the following declaration:

package foo
 
type s struct {
	I int
}
 
func F() s {
	return s{}
}

This struct can be accessed in another package as follows:

package main
 
func main() {
	a:=foo.F()
	a.I=1
	_=foo.F().I
}

This technique is commonly used, when declaring structs in handlers for encoding/decoding to/from JSON

References