package fixture // Not compiled. mapRefusal echoes a refusal only where its case tests the // text against literals; the others do not. func refuse(w int, err error, other string) { jsonError(w, 409, mapRefusal(err)) jsonError(w, 409, unguarded(err)) jsonError(w, 409, badGuard(err, other)) } func mapRefusal(err error) string { msg := err.Error() switch { case msg == "no journaled move in flight", strings.HasPrefix(msg, "a move to ") && strings.Contains(msg, " is already "): return msg } return "this move's state does not allow that" } func unguarded(err error) string { msg := err.Error() if len(msg) > 3 { return msg } return "this move's state does not allow that" } func badGuard(err error, other string) string { msg := err.Error() switch { case msg == other: return msg } return "this move's state does not allow that" }