Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1614)

Side by Side Diff: src/pkg/http/triv.go

Issue 4239076: code review 4239076: http: change ResponseWriter.SetHeader(k,v) to Header() ... (Closed)
Patch Set: diff -r a5f4ae5ff5fa https://go.googlecode.com/hg/ Created 13 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/http/server.go ('k') | src/pkg/rpc/server.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "expvar" 9 "expvar"
10 "flag" 10 "flag"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 fmt.Fprint(w, "counter reset\n") 49 fmt.Fprint(w, "counter reset\n")
50 } 50 }
51 } 51 }
52 fmt.Fprintf(w, "counter = %d\n", ctr.n) 52 fmt.Fprintf(w, "counter = %d\n", ctr.n)
53 } 53 }
54 54
55 // simple flag server 55 // simple flag server
56 var booleanflag = flag.Bool("boolean", true, "another flag for testing") 56 var booleanflag = flag.Bool("boolean", true, "another flag for testing")
57 57
58 func FlagServer(w http.ResponseWriter, req *http.Request) { 58 func FlagServer(w http.ResponseWriter, req *http.Request) {
59 » w.SetHeader("content-type", "text/plain; charset=utf-8") 59 » w.Header.Set("Content-Type", "text/plain; charset=utf-8")
60 fmt.Fprint(w, "Flags:\n") 60 fmt.Fprint(w, "Flags:\n")
61 flag.VisitAll(func(f *flag.Flag) { 61 flag.VisitAll(func(f *flag.Flag) {
62 if f.Value.String() != f.DefValue { 62 if f.Value.String() != f.DefValue {
63 fmt.Fprintf(w, "%s = %s [default = %s]\n", f.Name, f.Val ue.String(), f.DefValue) 63 fmt.Fprintf(w, "%s = %s [default = %s]\n", f.Name, f.Val ue.String(), f.DefValue)
64 } else { 64 } else {
65 fmt.Fprintf(w, "%s = %s\n", f.Name, f.Value.String()) 65 fmt.Fprintf(w, "%s = %s\n", f.Name, f.Value.String())
66 } 66 }
67 }) 67 })
68 } 68 }
69 69
(...skipping 16 matching lines...) Expand all
86 }(c) 86 }(c)
87 return c 87 return c
88 } 88 }
89 89
90 func (ch Chan) ServeHTTP(w http.ResponseWriter, req *http.Request) { 90 func (ch Chan) ServeHTTP(w http.ResponseWriter, req *http.Request) {
91 io.WriteString(w, fmt.Sprintf("channel send #%d\n", <-ch)) 91 io.WriteString(w, fmt.Sprintf("channel send #%d\n", <-ch))
92 } 92 }
93 93
94 // exec a program, redirecting output 94 // exec a program, redirecting output
95 func DateServer(rw http.ResponseWriter, req *http.Request) { 95 func DateServer(rw http.ResponseWriter, req *http.Request) {
96 » rw.SetHeader("content-type", "text/plain; charset=utf-8") 96 » rw.Header().Set("Content-Type", "text/plain; charset=utf-8")
97 r, w, err := os.Pipe() 97 r, w, err := os.Pipe()
98 if err != nil { 98 if err != nil {
99 fmt.Fprintf(rw, "pipe: %s\n", err) 99 fmt.Fprintf(rw, "pipe: %s\n", err)
100 return 100 return
101 } 101 }
102 p, err := os.StartProcess("/bin/date", []string{"date"}, os.Environ(), " ", []*os.File{nil, w, w}) 102 p, err := os.StartProcess("/bin/date", []string{"date"}, os.Environ(), " ", []*os.File{nil, w, w})
103 defer r.Close() 103 defer r.Close()
104 w.Close() 104 w.Close()
105 if err != nil { 105 if err != nil {
106 fmt.Fprintf(rw, "fork/exec: %s\n", err) 106 fmt.Fprintf(rw, "fork/exec: %s\n", err)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 http.Handle("/flags", http.HandlerFunc(FlagServer)) 141 http.Handle("/flags", http.HandlerFunc(FlagServer))
142 http.Handle("/args", http.HandlerFunc(ArgServer)) 142 http.Handle("/args", http.HandlerFunc(ArgServer))
143 http.Handle("/go/hello", http.HandlerFunc(HelloServer)) 143 http.Handle("/go/hello", http.HandlerFunc(HelloServer))
144 http.Handle("/chan", ChanCreate()) 144 http.Handle("/chan", ChanCreate())
145 http.Handle("/date", http.HandlerFunc(DateServer)) 145 http.Handle("/date", http.HandlerFunc(DateServer))
146 err := http.ListenAndServe(":12345", nil) 146 err := http.ListenAndServe(":12345", nil)
147 if err != nil { 147 if err != nil {
148 log.Panicln("ListenAndServe:", err) 148 log.Panicln("ListenAndServe:", err)
149 } 149 }
150 } 150 }
OLDNEW
« no previous file with comments | « src/pkg/http/server.go ('k') | src/pkg/rpc/server.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b