Index: go/src/infra/appengine/test-results/model/common.go |
diff --git a/go/src/infra/appengine/test-results/model/common.go b/go/src/infra/appengine/test-results/model/common.go |
index 3e2040bfc2d19ede29216a191297ebe333cc8d24..644e87883feeedca48ae833dc842273067c697e0 100644 |
--- a/go/src/infra/appengine/test-results/model/common.go |
+++ b/go/src/infra/appengine/test-results/model/common.go |
@@ -13,28 +13,34 @@ func round(f float64) int { |
return int(f + math.Copysign(0.5, f)) |
} |
-// TestNode is a node in a Tests tree. |
-type TestNode interface { |
- // Children returns a map of a TestNode's children. |
- Children() map[string]TestNode |
- |
- testnode() |
+// Node is a node in a Tests tree. |
+// |
+// In reality, it as almost as weak as empty interface, |
estaab
2016/08/12 15:17:20
Interesting, is this a common pattern in go?
nishanths
2016/08/12 16:45:58
I may have seen it elsewhere, but don't remember w
|
+// but the unexported method allow the package to achieve |
+// type safety internally. |
+type Node interface { |
+ node() |
} |
-// number is an integer that supports JSON unmarshaling from a string |
+// Number is an integer that supports JSON unmarshaling from a string |
// and marshaling back to a string. |
-type number int |
+type Number int |
-func (n *number) UnmarshalJSON(data []byte) error { |
+// UnmarshalJSON unmarshals data into n. |
+// data is expected to be a JSON string. If the string |
+// fails to parse to an integer, UnmarshalJSON returns |
+// an error. |
+func (n *Number) UnmarshalJSON(data []byte) error { |
data = bytes.Trim(data, `"`) |
num, err := strconv.Atoi(string(data)) |
if err != nil { |
return err |
} |
- *n = number(num) |
+ *n = Number(num) |
return nil |
} |
-func (n *number) MarshalJSON() ([]byte, error) { |
+// MarshalJSON marshals n into JSON string. |
+func (n *Number) MarshalJSON() ([]byte, error) { |
return []byte(strconv.Itoa(int(*n))), nil |
} |