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
03d6909f
Commit
03d6909f
authored
Feb 17, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more fun with triv.go: flags and arguments
R=rsc DELTA=23 (23 added, 0 deleted, 0 changed) OCL=25088 CL=25134
parent
d0424faf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
src/lib/http/triv.go
src/lib/http/triv.go
+23
-0
No files found.
src/lib/http/triv.go
View file @
03d6909f
...
@@ -45,6 +45,27 @@ func FileServer(c *http.Conn, req *http.Request) {
...
@@ -45,6 +45,27 @@ func FileServer(c *http.Conn, req *http.Request) {
fmt
.
Fprintf
(
c
,
"[%d bytes]
\n
"
,
n
);
fmt
.
Fprintf
(
c
,
"[%d bytes]
\n
"
,
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
"
);
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
);
}
else
{
fmt
.
Fprintf
(
c
,
"%s = %s
\n
"
,
f
.
Name
,
f
.
Value
.
String
());
}
});
}
// simple argument server
func
ArgServer
(
c
*
http
.
Conn
,
req
*
http
.
Request
)
{
for
i
,
s
:=
range
sys
.
Args
{
fmt
.
Fprint
(
c
,
s
,
" "
);
}
}
// a channel (just for the fun of it)
// a channel (just for the fun of it)
type
Chan
chan
int
type
Chan
chan
int
...
@@ -66,6 +87,8 @@ func main() {
...
@@ -66,6 +87,8 @@ func main() {
flag
.
Parse
();
flag
.
Parse
();
http
.
Handle
(
"/counter"
,
new
(
Counter
));
http
.
Handle
(
"/counter"
,
new
(
Counter
));
http
.
Handle
(
"/go/"
,
http
.
HandlerFunc
(
FileServer
));
http
.
Handle
(
"/go/"
,
http
.
HandlerFunc
(
FileServer
));
http
.
Handle
(
"/flags/"
,
http
.
HandlerFunc
(
FlagServer
));
http
.
Handle
(
"/args/"
,
http
.
HandlerFunc
(
ArgServer
));
http
.
Handle
(
"/go/hello"
,
http
.
HandlerFunc
(
HelloServer
));
http
.
Handle
(
"/go/hello"
,
http
.
HandlerFunc
(
HelloServer
));
http
.
Handle
(
"/chan"
,
ChanCreate
());
http
.
Handle
(
"/chan"
,
ChanCreate
());
err
:=
http
.
ListenAndServe
(
":12345"
,
nil
);
err
:=
http
.
ListenAndServe
(
":12345"
,
nil
);
...
...
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