Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
ae5cb2c5
Commit
ae5cb2c5
authored
Sep 30, 2010
by
Stephen Ma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http: fix http handler signature changes previously missed
R=adg, rsc CC=golang-dev
https://golang.org/cl/2303041
parent
a2332a32
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
26 deletions
+26
-26
src/pkg/http/server.go
src/pkg/http/server.go
+1
-1
src/pkg/http/triv.go
src/pkg/http/triv.go
+25
-25
No files found.
src/pkg/http/server.go
View file @
ae5cb2c5
...
...
@@ -426,7 +426,7 @@ func (w *response) Hijack() (rwc io.ReadWriteCloser, buf *bufio.ReadWriter, err
// Handler object that calls f.
type
HandlerFunc
func
(
ResponseWriter
,
*
Request
)
// ServeHTTP calls f(
c
, req).
// ServeHTTP calls f(
w
, req).
func
(
f
HandlerFunc
)
ServeHTTP
(
w
ResponseWriter
,
r
*
Request
)
{
f
(
w
,
r
)
}
...
...
src/pkg/http/triv.go
View file @
ae5cb2c5
...
...
@@ -20,9 +20,9 @@ import (
// hello world, the web server
var
helloRequests
=
expvar
.
NewInt
(
"hello-requests"
)
func
HelloServer
(
c
*
http
.
Conn
,
req
*
http
.
Request
)
{
func
HelloServer
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
helloRequests
.
Add
(
1
)
io
.
WriteString
(
c
,
"hello, world!
\n
"
)
io
.
WriteString
(
w
,
"hello, world!
\n
"
)
}
// Simple counter server. POSTing to it will set the value.
...
...
@@ -34,7 +34,7 @@ type Counter struct {
// it directly.
func
(
ctr
*
Counter
)
String
()
string
{
return
fmt
.
Sprintf
(
"%d"
,
ctr
.
n
)
}
func
(
ctr
*
Counter
)
ServeHTTP
(
c
*
http
.
Conn
,
req
*
http
.
Request
)
{
func
(
ctr
*
Counter
)
ServeHTTP
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
switch
req
.
Method
{
case
"GET"
:
ctr
.
n
++
...
...
@@ -43,34 +43,34 @@ func (ctr *Counter) ServeHTTP(c *http.Conn, req *http.Request) {
io
.
Copy
(
buf
,
req
.
Body
)
body
:=
buf
.
String
()
if
n
,
err
:=
strconv
.
Atoi
(
body
);
err
!=
nil
{
fmt
.
Fprintf
(
c
,
"bad POST: %v
\n
body: [%v]
\n
"
,
err
,
body
)
fmt
.
Fprintf
(
w
,
"bad POST: %v
\n
body: [%v]
\n
"
,
err
,
body
)
}
else
{
ctr
.
n
=
n
fmt
.
Fprint
(
c
,
"counter reset
\n
"
)
fmt
.
Fprint
(
w
,
"counter reset
\n
"
)
}
}
fmt
.
Fprintf
(
c
,
"counter = %d
\n
"
,
ctr
.
n
)
fmt
.
Fprintf
(
w
,
"counter = %d
\n
"
,
ctr
.
n
)
}
// simple flag server
var
booleanflag
=
flag
.
Bool
(
"boolean"
,
true
,
"another flag for testing"
)
func
FlagServer
(
c
*
http
.
Conn
,
req
*
http
.
Request
)
{
c
.
SetHeader
(
"content-type"
,
"text/plain; charset=utf-8"
)
fmt
.
Fprint
(
c
,
"Flags:
\n
"
)
func
FlagServer
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
w
.
SetHeader
(
"content-type"
,
"text/plain; charset=utf-8"
)
fmt
.
Fprint
(
w
,
"Flags:
\n
"
)
flag
.
VisitAll
(
func
(
f
*
flag
.
Flag
)
{
if
f
.
Value
.
String
()
!=
f
.
DefValue
{
fmt
.
Fprintf
(
c
,
"%s = %s [default = %s]
\n
"
,
f
.
Name
,
f
.
Value
.
String
(),
f
.
DefValue
)
fmt
.
Fprintf
(
w
,
"%s = %s [default = %s]
\n
"
,
f
.
Name
,
f
.
Value
.
String
(),
f
.
DefValue
)
}
else
{
fmt
.
Fprintf
(
c
,
"%s = %s
\n
"
,
f
.
Name
,
f
.
Value
.
String
())
fmt
.
Fprintf
(
w
,
"%s = %s
\n
"
,
f
.
Name
,
f
.
Value
.
String
())
}
})
}
// simple argument server
func
ArgServer
(
c
*
http
.
Conn
,
req
*
http
.
Request
)
{
func
ArgServer
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
for
_
,
s
:=
range
os
.
Args
{
fmt
.
Fprint
(
c
,
s
,
" "
)
fmt
.
Fprint
(
w
,
s
,
" "
)
}
}
...
...
@@ -87,41 +87,41 @@ func ChanCreate() Chan {
return
c
}
func
(
ch
Chan
)
ServeHTTP
(
c
*
http
.
Conn
,
req
*
http
.
Request
)
{
io
.
WriteString
(
c
,
fmt
.
Sprintf
(
"channel send #%d
\n
"
,
<-
ch
))
func
(
ch
Chan
)
ServeHTTP
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
io
.
WriteString
(
w
,
fmt
.
Sprintf
(
"channel send #%d
\n
"
,
<-
ch
))
}
// exec a program, redirecting output
func
DateServer
(
c
*
http
.
Conn
,
req
*
http
.
Request
)
{
c
.
SetHeader
(
"content-type"
,
"text/plain; charset=utf-8"
)
func
DateServer
(
rw
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
rw
.
SetHeader
(
"content-type"
,
"text/plain; charset=utf-8"
)
r
,
w
,
err
:=
os
.
Pipe
()
if
err
!=
nil
{
fmt
.
Fprintf
(
c
,
"pipe: %s
\n
"
,
err
)
fmt
.
Fprintf
(
rw
,
"pipe: %s
\n
"
,
err
)
return
}
pid
,
err
:=
os
.
ForkExec
(
"/bin/date"
,
[]
string
{
"date"
},
os
.
Environ
(),
""
,
[]
*
os
.
File
{
nil
,
w
,
w
})
defer
r
.
Close
()
w
.
Close
()
if
err
!=
nil
{
fmt
.
Fprintf
(
c
,
"fork/exec: %s
\n
"
,
err
)
fmt
.
Fprintf
(
rw
,
"fork/exec: %s
\n
"
,
err
)
return
}
io
.
Copy
(
c
,
r
)
io
.
Copy
(
rw
,
r
)
wait
,
err
:=
os
.
Wait
(
pid
,
0
)
if
err
!=
nil
{
fmt
.
Fprintf
(
c
,
"wait: %s
\n
"
,
err
)
fmt
.
Fprintf
(
rw
,
"wait: %s
\n
"
,
err
)
return
}
if
!
wait
.
Exited
()
||
wait
.
ExitStatus
()
!=
0
{
fmt
.
Fprintf
(
c
,
"date: %v
\n
"
,
wait
)
fmt
.
Fprintf
(
rw
,
"date: %v
\n
"
,
wait
)
return
}
}
func
Logger
(
c
*
http
.
Conn
,
req
*
http
.
Request
)
{
func
Logger
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
log
.
Stdout
(
req
.
URL
.
Raw
)
c
.
WriteHeader
(
404
)
c
.
Write
([]
byte
(
"oops"
))
w
.
WriteHeader
(
404
)
w
.
Write
([]
byte
(
"oops"
))
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment