From 994720ab0741238acf9d7b1606a962875935b4f6 Mon Sep 17 00:00:00 2001 From: yifeng01 <58141251+yifeng01@users.noreply.github.com> Date: Tue, 26 Nov 2019 06:44:31 +0800 Subject: [PATCH] Chap19 738 (#740) * fix http response content-type error * fix_chap19_739 --- eBook/examples/chapter_19/goto_v1/main.go | 1 + eBook/examples/chapter_19/goto_v5/store.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/eBook/examples/chapter_19/goto_v1/main.go b/eBook/examples/chapter_19/goto_v1/main.go index 4666585..09420c2 100644 --- a/eBook/examples/chapter_19/goto_v1/main.go +++ b/eBook/examples/chapter_19/goto_v1/main.go @@ -33,6 +33,7 @@ func Redirect(w http.ResponseWriter, r *http.Request) { func Add(w http.ResponseWriter, r *http.Request) { url := r.FormValue("url") if url == "" { + w.Header().Set("Content-Type", "text/html") fmt.Fprint(w, AddForm) return } diff --git a/eBook/examples/chapter_19/goto_v5/store.go b/eBook/examples/chapter_19/goto_v5/store.go index 9ceb337..6fb535c 100644 --- a/eBook/examples/chapter_19/goto_v5/store.go +++ b/eBook/examples/chapter_19/goto_v5/store.go @@ -64,7 +64,7 @@ func (s *URLStore) Set(key, url *string) error { return nil } -func (s *URLStore) Count() int { +func (s *URLStore) count() int { s.mu.RLock() defer s.mu.RUnlock() return len(s.urls) @@ -72,7 +72,7 @@ func (s *URLStore) Count() int { func (s *URLStore) Put(url, key *string) error { for { - *key = genKey(s.Count()) + *key = genKey(s.count()) if err := s.Set(key, url); err == nil { break }