~samwhited/mux

928af790a883bfc9e5512087ee64c16b558dde88 — Sam Whited 1 year, 1 month ago 3ae41f5
mux: fixes to new normalization example

Minor fixes to the normalization example in the package level
documentation to make sure the code would actually build, make things
clearer by removing unnecessary parts of the code, and use PRECIS
instead of lowercasing as a comment in the code had previously
suggested.
1 files changed, 9 insertions(+), 6 deletions(-)

M doc.go
M doc.go => doc.go +9 -6
@@ 69,22 69,25 @@
// issued or some other corrective action can be applied.
//
//	serveMux := mux.New(
//		mux.Handle(http.MethodGet, "/profile/{username string}", func(w http.ResponseWriter, r *http.Request) {
//		mux.HandleFunc(http.MethodGet, "/profile/{username string}", func(w http.ResponseWriter, r *http.Request) {
//			username := mux.Param(r, "username")
//			// You probably want to use the Username Case Mapped profile from the
//			// golang.org/x/text/secure/precis package instead.
//			normalized := strings.ToLower(username.Raw)
//			// golang.org/x/text/secure/precis
//			normalized, err := precis.UsernameCaseMapped.String(username.Raw)
//			if err != nil {
//					…
//			}
//
//			if normalized != username.Raw {
//				r = mux.WithParam(r, username.Name, normalized)
//				newPath, err := mux.Path(r)
//				if err != nil {
//					panic(fmt.Errorf("mux_test: error creating canonicalized path: %w", err))
//					…
//				}
//				http.Redirect(w, r, newPath, http.StatusPermanentRedirect)
//				return
//			}
//
//			fmt.Fprintln(w, "The canonical username is:", pinfo.Raw)
//			fmt.Fprintln(w, "The canonical username is:", username.Raw)
//		}),
//	)
//