How to lock concurrent access to all struct fields internally? Let's say I have a struct:
type Data struct {
ID string
Size int
//... and more fields
}
That will be used in another struct:
type Project struct {
mu sync.Mutex
MetaData Data
//... and more fields
}
How could I modify/get MetaData struct and use mutex for that while not exposing its mutex to the outer packages? I know I could use Get/Set methods, but what if I needed to modify one field of Data struct (it wouldn't be very good/clean if every field had a get/set method with the same shared mutex)? Could you recommend a way/pattern to have a struct-wise mutex that would be locked/unlocked internally?