summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Symonds <dsymonds@golang.org>2009-05-24 15:04:43 -0700
committerDavid Symonds <dsymonds@golang.org>2009-05-24 15:04:43 -0700
commitef76cad303685617c3518d61d894b5f53a1a6c31 (patch)
tree002c1d117b2dfe8dcf638fcf681eeb2f098b275c /src
parent0c277f198ced8088fca5000f612e5e2a18bc357a (diff)
downloadgolang-ef76cad303685617c3518d61d894b5f53a1a6c31.tar.gz
Add exvar.FuncInt for exporting indirect integer variables.
R=r APPROVED=r DELTA=21 (21 added, 0 deleted, 0 changed) OCL=29320 CL=29338
Diffstat (limited to 'src')
-rw-r--r--src/lib/exvar/exvar.go8
-rw-r--r--src/lib/exvar/exvar_test.go13
2 files changed, 21 insertions, 0 deletions
diff --git a/src/lib/exvar/exvar.go b/src/lib/exvar/exvar.go
index fea568337..6473f7af6 100644
--- a/src/lib/exvar/exvar.go
+++ b/src/lib/exvar/exvar.go
@@ -128,6 +128,14 @@ func (v *String) Set(value string) {
v.s = value;
}
+// IntFunc wraps a func() int64 to create a value that satisfies the Var interface.
+// The function will be called each time the Var is evaluated.
+type IntFunc func() int64;
+
+func (v IntFunc) String() string {
+ return strconv.Itoa64(v())
+}
+
// All published variables.
var vars map[string] Var = make(map[string] Var);
diff --git a/src/lib/exvar/exvar_test.go b/src/lib/exvar/exvar_test.go
index 28fbf3cf2..8b028bccb 100644
--- a/src/lib/exvar/exvar_test.go
+++ b/src/lib/exvar/exvar_test.go
@@ -78,3 +78,16 @@ func TestMapCounter(t *testing.T) {
t.Error("red = %v, want 3", x)
}
}
+
+func TestIntFunc(t *testing.T) {
+ x := int(4);
+ ix := IntFunc(func() int64 { return int64(x) });
+ if s := ix.String(); s != "4" {
+ t.Errorf("ix.String() = %v, want 4", s);
+ }
+
+ x++;
+ if s := ix.String(); s != "5" {
+ t.Errorf("ix.String() = %v, want 5", s);
+ }
+}