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..e8635da9d8b1b1f801ebe56e8fad0d030df580a7 100644 |
--- a/go/src/infra/appengine/test-results/model/common.go |
+++ b/go/src/infra/appengine/test-results/model/common.go |
@@ -2,39 +2,37 @@ package model |
import ( |
"bytes" |
- "math" |
"strconv" |
) |
-func round(f float64) int { |
- if math.Abs(f) < 0.5 { |
- return 0 |
- } |
- 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, |
+// 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 |
} |