Review this generated profile model against the stated task.
Support concurrent profile renames and return a JSON response snapshot whose roles cannot mutate internal state and which never exposes the API key.
Go
type Profile struct {
mu sync.Mutex
ID string
DisplayName string
Roles []string
apiKey string
}
type ProfileView struct {
ID string `json:"id"`
DisplayName string `json:"display_name"`
Roles []string `json:"roles"`
APIKey string `json:"api_key"`
}
func (p Profile) Rename(name string) {
p.mu.Lock()
defer p.mu.Unlock()
p.DisplayName = name
}
func (p *Profile) Snapshot() ProfileView {
return ProfileView{p.ID, p.DisplayName, p.Roles, p.apiKey}
}
generated code is illustrative, not from any one model