mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 05:11:49 +08:00
Chap19 738 (#740)
* fix http response content-type error * fix_chap19_739
This commit is contained in:
@@ -33,6 +33,7 @@ func Redirect(w http.ResponseWriter, r *http.Request) {
|
|||||||
func Add(w http.ResponseWriter, r *http.Request) {
|
func Add(w http.ResponseWriter, r *http.Request) {
|
||||||
url := r.FormValue("url")
|
url := r.FormValue("url")
|
||||||
if url == "" {
|
if url == "" {
|
||||||
|
w.Header().Set("Content-Type", "text/html")
|
||||||
fmt.Fprint(w, AddForm)
|
fmt.Fprint(w, AddForm)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@@ -64,7 +64,7 @@ func (s *URLStore) Set(key, url *string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *URLStore) Count() int {
|
func (s *URLStore) count() int {
|
||||||
s.mu.RLock()
|
s.mu.RLock()
|
||||||
defer s.mu.RUnlock()
|
defer s.mu.RUnlock()
|
||||||
return len(s.urls)
|
return len(s.urls)
|
||||||
@@ -72,7 +72,7 @@ func (s *URLStore) Count() int {
|
|||||||
|
|
||||||
func (s *URLStore) Put(url, key *string) error {
|
func (s *URLStore) Put(url, key *string) error {
|
||||||
for {
|
for {
|
||||||
*key = genKey(s.Count())
|
*key = genKey(s.count())
|
||||||
if err := s.Set(key, url); err == nil {
|
if err := s.Set(key, url); err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user