// Package updatewords holds every member-facing string the instance update // settings plans add (plans 2 to 5), as drafts with an ID and a context. The // copy review (plan 5, Task 1) exports All(), Paul rewrites them, and the // approved text replaces each Text; a test then pins them to the approved // record. Code reads a string only through Text, so a reviewed string has one // home. Each plan adds its own words_*.go file, so parallel branches never // edit the same lines. package updatewords import ( "fmt" "sort" ) // Draft is one string: Context says where it appears and what it does, for // the reviewer who cannot see the screen. type Draft struct{ ID, Text, Context string } var drafts = map[string]Draft{} // add registers drafts from a file's init. A duplicate ID is a programming // error and panics at start-up, never at the moment a member reads it. func add(ds ...Draft) { for _, d := range ds { if _, dup := drafts[d.ID]; dup { panic(fmt.Sprintf("updatewords: duplicate id %s", d.ID)) } drafts[d.ID] = d } } // Text is the string for id. An unknown id panics: it can only be a typo in // code, which the package's tests catch. func Text(id string) string { d, ok := drafts[id] if !ok { panic(fmt.Sprintf("updatewords: unknown id %s", id)) } return d.Text } // All is every draft, sorted by ID. func All() []Draft { out := make([]Draft, 0, len(drafts)) for _, d := range drafts { out = append(out, d) } sort.Slice(out, func(i, j int) bool { return out[i].ID < out[j].ID }) return out }