package fixture // Not compiled. Every sink here takes a sentence the gate can read. const noKey = "this box has no secrets key" func literal(w int) { jsonError(w, 400, "invalid region") } func constant(w int) { jsonError(w, 400, noKey) } func concat(w int, to string) { jsonError(w, 400, "region "+to+" is not armed") } func sprintf(w int, n int, region string) { jsonError(w, 400, fmt.Sprintf("%d boxes publish %s", n, region)) } func viaHelper(w int, n int) { jsonError(w, 400, tooMany(n)) } func tooMany(n int) string { if n > 1 { return fmt.Sprintf("%d boxes is too many", n) } return "one box is too few" } // A local whose every assignment is a sentence. func localLiteral(w int, bad bool) { msg := "that region is not armed" if bad { msg = "that region is not hosting" } jsonError(w, 400, msg) } // A multi-value helper whose string results are all sentences. func multi(w int) { text, _ := explain(1) jsonError(w, 400, text) } func explain(n int) (string, bool) { if n > 0 { return "the app is not enabled", true } return fmt.Sprintf("%d apps are not enabled", n), false } // A parameter whose every call site passes a sentence. func viaParam(w int) { jsonError(w, 400, wrapOK("first")) } func wrapOK(m string) string { return m } func callsAreLiterals() string { return wrapOK("second") } // A field whose every write, in the struct that is read, is a sentence. type Check struct{ Reason string } func makeCheck() Check { return Check{Reason: "this box has no secrets key"} } func viaField(w int, c Check) { jsonError(w, 400, c.Reason) } // An error that only selects among sentences, and is never spoken. func selects(w int, err error) { jsonError(w, 400, pick(err)) } func pick(err error) string { if err == nil { return "the copy is fine" } return "the copy is not fine" } // A placeholder that is data, not an error. func dataPlaceholder(w int, host string) { jsonError(w, 400, fmt.Sprintf("host %s is not armed", host)) } // A method on a receiver declared once. type local struct{} func (local) Message() string { return "the app is not enabled" } func viaMethod(w int, m local) { jsonError(w, 400, m.Message()) } // A helper that dresses data, and a string field written from data: both // stand for a row's . func label(host string) string { return "host " + host } func viaLabel(w int, h string) { jsonError(w, 400, fmt.Sprintf("%s has no seat", label(h))) } type target struct{ Name string } func makeTarget(n string) target { return target{Name: n} } func viaDataField(w int, t target) { jsonError(w, 400, fmt.Sprintf("region %s is gone", t.Name)) } // A helper that joins data (stagingCodes' shape): the gate cannot derive it, // and it carries no error's text, so it stands for a . func joined(codes []string) string { return strings.Join(codes, ", ") } func viaJoined(w int, codes []string) { jsonError(w, 400, fmt.Sprintf("the staging codes are %s", joined(codes))) }