aboutsummaryrefslogtreecommitdiff
path: root/src/lib/http
diff options
context:
space:
mode:
authorDavid Symonds <dsymonds@golang.org>2009-04-19 21:17:27 -0700
committerDavid Symonds <dsymonds@golang.org>2009-04-19 21:17:27 -0700
commit3cc702ba60587aaefbc953e93eedbe1f9dd9166e (patch)
treecfa851901e36a3a35b7d9ba6555c957f97308ac5 /src/lib/http
parentf1820b50ff31435f237e706edb39166c6097ada5 (diff)
downloadgo-3cc702ba60587aaefbc953e93eedbe1f9dd9166e.tar.xz
Initial cut at an "exported variables" (exvar) package.
This handles integer-valued vars in a singleton struct, and exports functions for incrementing, setting and getting those vars, as well as rendering all the vars in a standard format. Demonstrate the use of the exvar package in the http/triv server. R=dcross,r APPROVED=r DELTA=122 (122 added, 0 deleted, 0 changed) OCL=27617 CL=27622
Diffstat (limited to 'src/lib/http')
-rw-r--r--src/lib/http/triv.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/lib/http/triv.go b/src/lib/http/triv.go
index daf5eb8c0c..48e345e5e8 100644
--- a/src/lib/http/triv.go
+++ b/src/lib/http/triv.go
@@ -6,6 +6,7 @@ package main
import (
"bufio";
+ "exvar";
"flag";
"fmt";
"http";
@@ -17,15 +18,23 @@ import (
// hello world, the web server
func HelloServer(c *http.Conn, req *http.Request) {
+ exvar.Increment("hello-requests", 1);
io.WriteString(c, "hello, world!\n");
}
+// Handler for /exvar requests.
+func ExvarServer(c *http.Conn, req *http.Request) {
+ c.SetHeader("content-type", "text/plain; charset=utf-8");
+ io.WriteString(c, exvar.String());
+}
+
// simple counter server
type Counter struct {
n int;
}
func (ctr *Counter) ServeHTTP(c *http.Conn, req *http.Request) {
+ exvar.Increment("counter-requests", 1);
fmt.Fprintf(c, "counter = %d\n", ctr.n);
ctr.n++;
}
@@ -92,6 +101,7 @@ func main() {
http.Handle("/args", http.HandlerFunc(ArgServer));
http.Handle("/go/hello", http.HandlerFunc(HelloServer));
http.Handle("/chan", ChanCreate());
+ http.Handle("/exvar", http.HandlerFunc(ExvarServer));
err := http.ListenAndServe(":12345", nil);
if err != nil {
panic("ListenAndServe: ", err.String())