Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
ed1d1dad
Commit
ed1d1dad
authored
Dec 05, 2016
by
Fabiano Franz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bump(github.com/docker/go-units): e30f1e79f3cd72542f2026ceec18d3bd67ab859c
parent
6c4033ee
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
24 deletions
+37
-24
Godeps.json
Godeps/Godeps.json
+2
-2
LICENSES
Godeps/LICENSES
+1
-1
LICENSE
vendor/github.com/docker/go-units/LICENSE
+0
-0
LICENSE.docs
vendor/github.com/docker/go-units/LICENSE.docs
+0
-0
README.md
vendor/github.com/docker/go-units/README.md
+4
-6
duration.go
vendor/github.com/docker/go-units/duration.go
+5
-3
size.go
vendor/github.com/docker/go-units/size.go
+25
-12
No files found.
Godeps/Godeps.json
View file @
ed1d1dad
...
...
@@ -865,8 +865,8 @@
},
{
"ImportPath"
:
"github.com/docker/go-units"
,
"Comment"
:
"v0.
1.0-21-g0bbddae
"
,
"Rev"
:
"
0bbddae09c5a5419a8c6dcdd7ff90da3d450393b
"
"Comment"
:
"v0.
3.1-10-ge30f1e7
"
,
"Rev"
:
"
e30f1e79f3cd72542f2026ceec18d3bd67ab859c
"
},
{
"ImportPath"
:
"github.com/docker/spdystream"
,
...
...
Godeps/LICENSES
View file @
ed1d1dad
...
...
@@ -30858,7 +30858,7 @@ Apache License
See the License for the specific language governing permissions and
limitations under the License.
= vendor/github.com/docker/go-units/LICENSE
.code
04424bc6f5a5be60691b9824d65c2ad8 -
= vendor/github.com/docker/go-units/LICENSE 04424bc6f5a5be60691b9824d65c2ad8 -
================================================================================
vendor/github.com/docker/go-units/LICENSE
.code
→
vendor/github.com/docker/go-units/LICENSE
View file @
ed1d1dad
File moved
vendor/github.com/docker/go-units/LICENSE.docs
deleted
100644 → 0
View file @
6c4033ee
This diff is collapsed.
Click to expand it.
vendor/github.com/docker/go-units/README.md
View file @
ed1d1dad
...
...
@@ -10,9 +10,7 @@ See the [docs in godoc](https://godoc.org/github.com/docker/go-units) for exampl
## Copyright and license
Copyright © 2015 Docker, Inc. All rights reserved, except as follows. Code
is released under the Apache 2.0 license. The README.md file, and files in the
"docs" folder are licensed under the Creative Commons Attribution 4.0
International License under the terms and conditions set forth in the file
"LICENSE.docs". You may obtain a duplicate copy of the same license, titled
CC-BY-SA-4.0, at http://creativecommons.org/licenses/by/4.0/.
Copyright © 2015 Docker, Inc.
go-units is licensed under the Apache License, Version 2.0.
See
[
LICENSE
](
LICENSE
)
for the full text of the license.
vendor/github.com/docker/go-units/duration.go
View file @
ed1d1dad
...
...
@@ -12,19 +12,21 @@ import (
func
HumanDuration
(
d
time
.
Duration
)
string
{
if
seconds
:=
int
(
d
.
Seconds
());
seconds
<
1
{
return
"Less than a second"
}
else
if
seconds
==
1
{
return
"1 second"
}
else
if
seconds
<
60
{
return
fmt
.
Sprintf
(
"%d seconds"
,
seconds
)
}
else
if
minutes
:=
int
(
d
.
Minutes
());
minutes
==
1
{
return
"About a minute"
}
else
if
minutes
<
60
{
}
else
if
minutes
<
46
{
return
fmt
.
Sprintf
(
"%d minutes"
,
minutes
)
}
else
if
hours
:=
int
(
d
.
Hours
());
hours
==
1
{
}
else
if
hours
:=
int
(
d
.
Hours
()
+
0.5
);
hours
==
1
{
return
"About an hour"
}
else
if
hours
<
48
{
return
fmt
.
Sprintf
(
"%d hours"
,
hours
)
}
else
if
hours
<
24
*
7
*
2
{
return
fmt
.
Sprintf
(
"%d days"
,
hours
/
24
)
}
else
if
hours
<
24
*
30
*
3
{
}
else
if
hours
<
24
*
30
*
2
{
return
fmt
.
Sprintf
(
"%d weeks"
,
hours
/
24
/
7
)
}
else
if
hours
<
24
*
365
*
2
{
return
fmt
.
Sprintf
(
"%d months"
,
hours
/
24
/
30
)
...
...
vendor/github.com/docker/go-units/size.go
View file @
ed1d1dad
...
...
@@ -31,27 +31,40 @@ type unitMap map[string]int64
var
(
decimalMap
=
unitMap
{
"k"
:
KB
,
"m"
:
MB
,
"g"
:
GB
,
"t"
:
TB
,
"p"
:
PB
}
binaryMap
=
unitMap
{
"k"
:
KiB
,
"m"
:
MiB
,
"g"
:
GiB
,
"t"
:
TiB
,
"p"
:
PiB
}
sizeRegex
=
regexp
.
MustCompile
(
`^(\d+
)
([kKmMgGtTpP])?[bB]?$`
)
sizeRegex
=
regexp
.
MustCompile
(
`^(\d+
(\.\d+)*) ?
([kKmMgGtTpP])?[bB]?$`
)
)
var
decimapAbbrs
=
[]
string
{
"B"
,
"kB"
,
"MB"
,
"GB"
,
"TB"
,
"PB"
,
"EB"
,
"ZB"
,
"YB"
}
var
binaryAbbrs
=
[]
string
{
"B"
,
"KiB"
,
"MiB"
,
"GiB"
,
"TiB"
,
"PiB"
,
"EiB"
,
"ZiB"
,
"YiB"
}
// CustomSize returns a human-readable approximation of a size
// using custom format.
func
CustomSize
(
format
string
,
size
float64
,
base
float64
,
_map
[]
string
)
string
{
func
getSizeAndUnit
(
size
float64
,
base
float64
,
_map
[]
string
)
(
float64
,
string
)
{
i
:=
0
for
size
>=
base
{
unitsLimit
:=
len
(
_map
)
-
1
for
size
>=
base
&&
i
<
unitsLimit
{
size
=
size
/
base
i
++
}
return
fmt
.
Sprintf
(
format
,
size
,
_map
[
i
])
return
size
,
_map
[
i
]
}
// CustomSize returns a human-readable approximation of a size
// using custom format.
func
CustomSize
(
format
string
,
size
float64
,
base
float64
,
_map
[]
string
)
string
{
size
,
unit
:=
getSizeAndUnit
(
size
,
base
,
_map
)
return
fmt
.
Sprintf
(
format
,
size
,
unit
)
}
// HumanSizeWithPrecision allows the size to be in any precision,
// instead of 4 digit precision used in units.HumanSize.
func
HumanSizeWithPrecision
(
size
float64
,
precision
int
)
string
{
size
,
unit
:=
getSizeAndUnit
(
size
,
1000.0
,
decimapAbbrs
)
return
fmt
.
Sprintf
(
"%.*g %s"
,
precision
,
size
,
unit
)
}
// HumanSize returns a human-readable approximation of a size
// capped at 4 valid numbers (eg. "2.746 MB", "796 KB").
func
HumanSize
(
size
float64
)
string
{
return
CustomSize
(
"%.4g %s"
,
size
,
1000.0
,
decimapAbbrs
)
return
HumanSizeWithPrecision
(
size
,
4
)
}
// BytesSize returns a human-readable size in bytes, kibibytes,
...
...
@@ -77,19 +90,19 @@ func RAMInBytes(size string) (int64, error) {
// Parses the human-readable size string into the amount it represents.
func
parseSize
(
sizeStr
string
,
uMap
unitMap
)
(
int64
,
error
)
{
matches
:=
sizeRegex
.
FindStringSubmatch
(
sizeStr
)
if
len
(
matches
)
!=
3
{
if
len
(
matches
)
!=
4
{
return
-
1
,
fmt
.
Errorf
(
"invalid size: '%s'"
,
sizeStr
)
}
size
,
err
:=
strconv
.
Parse
Int
(
matches
[
1
],
10
,
0
)
size
,
err
:=
strconv
.
Parse
Float
(
matches
[
1
],
64
)
if
err
!=
nil
{
return
-
1
,
err
}
unitPrefix
:=
strings
.
ToLower
(
matches
[
2
])
unitPrefix
:=
strings
.
ToLower
(
matches
[
3
])
if
mul
,
ok
:=
uMap
[
unitPrefix
];
ok
{
size
*=
mul
size
*=
float64
(
mul
)
}
return
size
,
nil
return
int64
(
size
)
,
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment