Skip to content

Commit c402d78

Browse files
committed
Add support for Go 1.8 compile only
Evergreen needs compile only support for 1.8. Since we use type aliases in bson.go, we've added a shim that redeclares the aliased types. Change-Id: I8044d6f85d66e6ff0630294086dce8f24e21aceb
1 parent 814b9f8 commit c402d78

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

bson/bson.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// Based on gopkg.in/mgo.v2/bson by Gustavo Niemeyer
88
// See THIRD-PARTY-NOTICES for original license terms.
99

10+
// +build go1.9
11+
1012
package bson
1113

1214
import (

bson/bson_1_8.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright (C) MongoDB, Inc. 2017-present.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
// +build !go1.9
8+
9+
package bson
10+
11+
import (
12+
"math"
13+
"strconv"
14+
"strings"
15+
)
16+
17+
// Zeroer allows custom struct types to implement a report of zero
18+
// state. All struct types that don't implement Zeroer or where IsZero
19+
// returns false are considered to be not zero.
20+
type Zeroer interface {
21+
IsZero() bool
22+
}
23+
24+
// D represents a BSON Document. This type can be used to represent BSON in a concise and readable
25+
// manner. It should generally be used when serializing to BSON. For deserializing, the Raw or
26+
// Document types should be used.
27+
//
28+
// Example usage:
29+
//
30+
// primitive.D{{"foo", "bar"}, {"hello", "world"}, {"pi", 3.14159}}
31+
//
32+
// This type should be used in situations where order matters, such as MongoDB commands. If the
33+
// order is not important, a map is more comfortable and concise.
34+
type D []E
35+
36+
// Map creates a map from the elements of the D.
37+
func (d D) Map() M {
38+
m := make(M, len(d))
39+
for _, e := range d {
40+
m[e.Key] = e.Value
41+
}
42+
return m
43+
}
44+
45+
// E represents a BSON element for a D. It is usually used inside a D.
46+
type E struct {
47+
Key string
48+
Value interface{}
49+
}
50+
51+
// M is an unordered, concise representation of a BSON Document. It should generally be used to
52+
// serialize BSON when the order of the elements of a BSON document do not matter. If the element
53+
// order matters, use a D instead.
54+
//
55+
// Example usage:
56+
//
57+
// primitive.M{"foo": "bar", "hello": "world", "pi": 3.14159}
58+
//
59+
// This type is handled in the encoders as a regular map[string]interface{}. The elements will be
60+
// serialized in an undefined, random order, and the order will be different each time.
61+
type M map[string]interface{}
62+
63+
// An A represents a BSON array. This type can be used to represent a BSON array in a concise and
64+
// readable manner. It should generally be used when serializing to BSON. For deserializing, the
65+
// RawArray or Array types should be used.
66+
//
67+
// Example usage:
68+
//
69+
// primitive.A{"bar", "world", 3.14159, primitive.D{{"qux", 12345}}}
70+
//
71+
type A []interface{}
72+
73+
func formatDouble(f float64) string {
74+
var s string
75+
if math.IsInf(f, 1) {
76+
s = "Infinity"
77+
} else if math.IsInf(f, -1) {
78+
s = "-Infinity"
79+
} else if math.IsNaN(f) {
80+
s = "NaN"
81+
} else {
82+
// Print exactly one decimalType place for integers; otherwise, print as many are necessary to
83+
// perfectly represent it.
84+
s = strconv.FormatFloat(f, 'G', -1, 64)
85+
if !strings.ContainsRune(s, '.') {
86+
s += ".0"
87+
}
88+
}
89+
90+
return s
91+
}

x/network/command/aggregate_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright (C) MongoDB, Inc. 2017-present.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
17
package command
28

39
import (

0 commit comments

Comments
 (0)