Browse code

update go-units vendor to newest version

Signed-off-by: allencloud <allen.sun@daocloud.io>

allencloud authored on 2016/08/09 01:10:19
Showing 9 changed files
... ...
@@ -20,7 +20,7 @@ Each repo should:
20 20
 github releases file.
21 21
 
22 22
 The goal here is for consuming repos to be able to use the tag version and
23
-changelog updates to determine whether the vendoring will cause any  breaking or
23
+changelog updates to determine whether the vendoring will cause any breaking or
24 24
 backward incompatible changes. This also means that repos can specify having
25 25
 dependency on a package of a specific version or greater up to the next major
26 26
 release, without encountering breaking changes.
... ...
@@ -119,7 +119,7 @@ You can also filter for a substring in a name as this shows:
119 119
 $ docker ps --filter "name=nostalgic"
120 120
 
121 121
 CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
122
-715ebfcee040        busybox             "top"               3 seconds ago       Up 1 seconds                            i_am_nostalgic
122
+715ebfcee040        busybox             "top"               3 seconds ago       Up 1 second                             i_am_nostalgic
123 123
 9b6247364a03        busybox             "top"               7 minutes ago       Up 7 minutes                            nostalgic_stallman
124 124
 673394ef1d4c        busybox             "top"               38 minutes ago      Up 38 minutes                           nostalgic_shockley
125 125
 ```
... ...
@@ -58,7 +58,7 @@ clone git github.com/vdemeester/shakers 24d7f1d6a71aa5d9cbe7390e4afb66b7eef9e1b3
58 58
 # forked golang.org/x/net package includes a patch for lazy loading trace templates
59 59
 clone git golang.org/x/net 2beffdc2e92c8a3027590f898fe88f69af48a3f8 https://github.com/tonistiigi/net.git
60 60
 clone git golang.org/x/sys eb2c74142fd19a79b3f237334c7384d5167b1b46 https://github.com/golang/sys.git
61
-clone git github.com/docker/go-units 651fc226e7441360384da338d0fd37f2440ffbe3
61
+clone git github.com/docker/go-units eb879ae3e2b84e2a142af415b679ddeda47ec71c
62 62
 clone git github.com/docker/go-connections fa2850ff103453a9ad190da0df0af134f0314b3d
63 63
 
64 64
 clone git github.com/docker/engine-api 603ec41824c63d1e6498a22271987fa1f268c0c0
65 65
new file mode 100644
... ...
@@ -0,0 +1,67 @@
0
+# Contributing to go-units
1
+
2
+Want to hack on go-units? Awesome! Here are instructions to get you started.
3
+
4
+go-units is a part of the [Docker](https://www.docker.com) project, and follows
5
+the same rules and principles. If you're already familiar with the way
6
+Docker does things, you'll feel right at home.
7
+
8
+Otherwise, go read Docker's
9
+[contributions guidelines](https://github.com/docker/docker/blob/master/CONTRIBUTING.md),
10
+[issue triaging](https://github.com/docker/docker/blob/master/project/ISSUE-TRIAGE.md),
11
+[review process](https://github.com/docker/docker/blob/master/project/REVIEWING.md) and
12
+[branches and tags](https://github.com/docker/docker/blob/master/project/BRANCHES-AND-TAGS.md).
13
+
14
+### Sign your work
15
+
16
+The sign-off is a simple line at the end of the explanation for the patch. Your
17
+signature certifies that you wrote the patch or otherwise have the right to pass
18
+it on as an open-source patch. The rules are pretty simple: if you can certify
19
+the below (from [developercertificate.org](http://developercertificate.org/)):
20
+
21
+```
22
+Developer Certificate of Origin
23
+Version 1.1
24
+
25
+Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
26
+660 York Street, Suite 102,
27
+San Francisco, CA 94110 USA
28
+
29
+Everyone is permitted to copy and distribute verbatim copies of this
30
+license document, but changing it is not allowed.
31
+
32
+Developer's Certificate of Origin 1.1
33
+
34
+By making a contribution to this project, I certify that:
35
+
36
+(a) The contribution was created in whole or in part by me and I
37
+    have the right to submit it under the open source license
38
+    indicated in the file; or
39
+
40
+(b) The contribution is based upon previous work that, to the best
41
+    of my knowledge, is covered under an appropriate open source
42
+    license and I have the right under that license to submit that
43
+    work with modifications, whether created in whole or in part
44
+    by me, under the same open source license (unless I am
45
+    permitted to submit under a different license), as indicated
46
+    in the file; or
47
+
48
+(c) The contribution was provided directly to me by some other
49
+    person who certified (a), (b) or (c) and I have not modified
50
+    it.
51
+
52
+(d) I understand and agree that this project and the contribution
53
+    are public and that a record of the contribution (including all
54
+    personal information I submit with it, including my sign-off) is
55
+    maintained indefinitely and may be redistributed consistent with
56
+    this project or the open source license(s) involved.
57
+```
58
+
59
+Then you just add a line to every git commit message:
60
+
61
+    Signed-off-by: Joe Smith <joe.smith@email.com>
62
+
63
+Use your real name (sorry, no pseudonyms or anonymous contributions.)
64
+
65
+If you set your `user.name` and `user.email` git configs, you can sign your
66
+commit automatically with `git commit -s`.
0 67
new file mode 100644
... ...
@@ -0,0 +1,27 @@
0
+# go-connections maintainers file
1
+#
2
+# This file describes who runs the docker/go-connections project and how.
3
+# This is a living document - if you see something out of date or missing, speak up!
4
+#
5
+# It is structured to be consumable by both humans and programs.
6
+# To extract its contents programmatically, use any TOML-compliant parser.
7
+#
8
+# This file is compiled into the MAINTAINERS file in docker/opensource.
9
+#
10
+[Org]
11
+	[Org."Core maintainers"]
12
+		people = [
13
+			"calavera",
14
+		]
15
+
16
+[people]
17
+
18
+# A reference list of all people associated with the project.
19
+# All other sections should refer to people by their canonical key
20
+# in the people section.
21
+
22
+	# ADD YOURSELF HERE IN ALPHABETICAL ORDER
23
+	[people.calavera]
24
+	Name = "David Calavera"
25
+	Email = "david.calavera@gmail.com"
26
+	GitHub = "calavera"
... ...
@@ -8,6 +8,9 @@ go-units is a library to transform human friendly measurements into machine frie
8 8
 
9 9
 See the [docs in godoc](https://godoc.org/github.com/docker/go-units) for examples and documentation.
10 10
 
11
-## License
11
+## Copyright and license
12 12
 
13
-go-units is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full license text.
13
+Copyright © 2015 Docker, Inc.
14
+
15
+go-units is licensed under the Apache License, Version 2.0.
16
+See [LICENSE](LICENSE) for the full text of the license.
... ...
@@ -12,6 +12,8 @@ import (
12 12
 func HumanDuration(d time.Duration) string {
13 13
 	if seconds := int(d.Seconds()); seconds < 1 {
14 14
 		return "Less than a second"
15
+	} else if seconds == 1 {
16
+		return "1 second"
15 17
 	} else if seconds < 60 {
16 18
 		return fmt.Sprintf("%d seconds", seconds)
17 19
 	} else if minutes := int(d.Minutes()); minutes == 1 {
... ...
@@ -31,7 +31,7 @@ type unitMap map[string]int64
31 31
 var (
32 32
 	decimalMap = unitMap{"k": KB, "m": MB, "g": GB, "t": TB, "p": PB}
33 33
 	binaryMap  = unitMap{"k": KiB, "m": MiB, "g": GiB, "t": TiB, "p": PiB}
34
-	sizeRegex  = regexp.MustCompile(`^(\d+)([kKmMgGtTpP])?[bB]?$`)
34
+	sizeRegex  = regexp.MustCompile(`^(\d+(\.\d+)*) ?([kKmMgGtTpP])?[bB]?$`)
35 35
 )
36 36
 
37 37
 var decimapAbbrs = []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
... ...
@@ -41,7 +41,8 @@ var binaryAbbrs = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB",
41 41
 // using custom format.
42 42
 func CustomSize(format string, size float64, base float64, _map []string) string {
43 43
 	i := 0
44
-	for size >= base {
44
+	unitsLimit := len(_map) - 1
45
+	for size >= base && i < unitsLimit {
45 46
 		size = size / base
46 47
 		i++
47 48
 	}
... ...
@@ -77,19 +78,19 @@ func RAMInBytes(size string) (int64, error) {
77 77
 // Parses the human-readable size string into the amount it represents.
78 78
 func parseSize(sizeStr string, uMap unitMap) (int64, error) {
79 79
 	matches := sizeRegex.FindStringSubmatch(sizeStr)
80
-	if len(matches) != 3 {
80
+	if len(matches) != 4 {
81 81
 		return -1, fmt.Errorf("invalid size: '%s'", sizeStr)
82 82
 	}
83 83
 
84
-	size, err := strconv.ParseInt(matches[1], 10, 0)
84
+	size, err := strconv.ParseFloat(matches[1], 64)
85 85
 	if err != nil {
86 86
 		return -1, err
87 87
 	}
88 88
 
89
-	unitPrefix := strings.ToLower(matches[2])
89
+	unitPrefix := strings.ToLower(matches[3])
90 90
 	if mul, ok := uMap[unitPrefix]; ok {
91
-		size *= mul
91
+		size *= float64(mul)
92 92
 	}
93 93
 
94
-	return size, nil
94
+	return int64(size), nil
95 95
 }
... ...
@@ -73,25 +73,34 @@ func ParseUlimit(val string) (*Ulimit, error) {
73 73
 		return nil, fmt.Errorf("invalid ulimit type: %s", parts[0])
74 74
 	}
75 75
 
76
-	limitVals := strings.SplitN(parts[1], ":", 2)
77
-	if len(limitVals) > 2 {
76
+	var (
77
+		soft int64
78
+		hard = &soft // default to soft in case no hard was set
79
+		temp int64
80
+		err  error
81
+	)
82
+	switch limitVals := strings.Split(parts[1], ":"); len(limitVals) {
83
+	case 2:
84
+		temp, err = strconv.ParseInt(limitVals[1], 10, 64)
85
+		if err != nil {
86
+			return nil, err
87
+		}
88
+		hard = &temp
89
+		fallthrough
90
+	case 1:
91
+		soft, err = strconv.ParseInt(limitVals[0], 10, 64)
92
+		if err != nil {
93
+			return nil, err
94
+		}
95
+	default:
78 96
 		return nil, fmt.Errorf("too many limit value arguments - %s, can only have up to two, `soft[:hard]`", parts[1])
79 97
 	}
80 98
 
81
-	soft, err := strconv.ParseInt(limitVals[0], 10, 64)
82
-	if err != nil {
83
-		return nil, err
99
+	if soft > *hard {
100
+		return nil, fmt.Errorf("ulimit soft limit must be less than or equal to hard limit: %d > %d", soft, *hard)
84 101
 	}
85 102
 
86
-	hard := soft // in case no hard was set
87
-	if len(limitVals) == 2 {
88
-		hard, err = strconv.ParseInt(limitVals[1], 10, 64)
89
-	}
90
-	if soft > hard {
91
-		return nil, fmt.Errorf("ulimit soft limit must be less than or equal to hard limit: %d > %d", soft, hard)
92
-	}
93
-
94
-	return &Ulimit{Name: parts[0], Soft: soft, Hard: hard}, nil
103
+	return &Ulimit{Name: parts[0], Soft: soft, Hard: *hard}, nil
95 104
 }
96 105
 
97 106
 // GetRlimit returns the RLimit corresponding to Ulimit.