godep: updated
Henry committed
Apr 28, 2015 at 13:12 UTC
f20c4566ec3d470fdd309a6bb99907f70e7f7a53
59 files changed
+1006
-204
Godeps/Godeps.json
+18
-18
@@ -25,8 +25,8 @@
25
},
26
{
27
"ImportPath": "github.com/Sirupsen/logrus",
28
- "Comment": "v0.7.1",
29
- "Rev": "3fc34d061b9c78a70db853c7cb6b0576b6d4f32d"
28
+ "Comment": "v0.7.3-2-g26709e2",
29
+ "Rev": "26709e2714106fb8ad40b773b711ebce25b78914"
30
},
31
{
32
"ImportPath": "github.com/braintree/manners",
@@ -71,7 +71,7 @@
71
},
72
{
73
"ImportPath": "github.com/dustin/go-humanize",
74
- "Rev": "b198514c204f20799b91c93b6ffd8b26be04c2c9"
74
+ "Rev": "00897f070f09f194c26d65afae734ba4c32404e8"
75
},
76
{
77
"ImportPath": "github.com/facebookgo/atomicfile",
@@ -170,16 +170,16 @@
170
},
171
{
172
"ImportPath": "github.com/jbenet/go-multiaddr-net",
173
- "Rev": "eae26b653a87d02193bb261ae5c5e1f39cc033d6"
173
+ "Rev": "62d4c740c29c00a47ef7f670208022940d245eef"
174
},
175
{
176
"ImportPath": "github.com/jbenet/go-multihash",
177
- "Comment": "0.1.0-36-g87e53a9",
178
- "Rev": "87e53a9d2875a18a7863b351d22f912545e6b3a3"
177
+ "Comment": "0.1.0-39-ge8d2374",
178
+ "Rev": "e8d2374934f16a971d1e94a864514a21ac74bf7f"
179
},
180
{
181
"ImportPath": "github.com/jbenet/go-os-rename",
182
- "Rev": "2d93ae970ba96c41f717036a5bf5494faf1f38c0"
182
+ "Rev": "3ac97f61ef67a6b87b95c1282f6c317ed0e693c2"
183
},
184
{
185
"ImportPath": "github.com/jbenet/go-peerstream",
@@ -187,11 +187,11 @@
187
},
188
{
189
"ImportPath": "github.com/jbenet/go-random",
190
- "Rev": "c50d0ce235bacde481d3e885b5dfd562c75c981a"
190
+ "Rev": "cd535bd25356746b9b1e824871dda7da932460e2"
191
},
192
{
193
"ImportPath": "github.com/jbenet/go-reuseport",
194
- "Rev": "c71a70ef82a7acb87ad77704de1be7b9cd776a55"
194
+ "Rev": "48959f1fad204b6cf2c0e8d086ef69f03f2de961"
195
},
196
{
197
"ImportPath": "github.com/jbenet/go-sockaddr/net",
@@ -199,7 +199,7 @@
199
},
200
{
201
"ImportPath": "github.com/jbenet/go-temp-err-catcher",
202
- "Rev": "c531232018e678b2a702cfb86b5c3f68d1c8beb8"
202
+ "Rev": "aac704a3f4f27190b4ccc05f303a4931fd1241ff"
203
},
204
{
205
"ImportPath": "github.com/jbenet/goprocess",
@@ -207,7 +207,7 @@
207
},
208
{
209
"ImportPath": "github.com/kardianos/osext",
210
- "Rev": "efacde03154693404c65e7aa7d461ac9014acd0c"
210
+ "Rev": "8fef92e41e22a70e700a96b29f066cda30ea24ef"
211
},
212
{
213
"ImportPath": "github.com/kr/binarydist",
@@ -215,11 +215,11 @@
215
},
216
{
217
"ImportPath": "github.com/miekg/dns",
218
- "Rev": "5a357a6fc5e85268b929350aa6423e2d56dcc4ff"
218
+ "Rev": "82ffc45b1f84ff71bd1cebed8b210118ce3d181e"
219
},
220
{
221
"ImportPath": "github.com/mitchellh/go-homedir",
222
- "Rev": "7d2d8c8a4e078ce3c58736ab521a40b37a504c52"
222
+ "Rev": "1f6da4a72e57d4e7edd4a7295a585e0a3999a2d4"
223
},
224
{
225
"ImportPath": "github.com/mtchavez/jenkins",
@@ -232,7 +232,7 @@
232
},
233
{
234
"ImportPath": "github.com/syndtr/goleveldb/leveldb",
235
- "Rev": "87e4e645d80ae9c537e8f2dee52b28036a5dd75e"
235
+ "Rev": "4875955338b0a434238a31165cb87255ab6e9e4a"
236
},
237
{
238
"ImportPath": "github.com/syndtr/gosnappy/snappy",
@@ -248,19 +248,19 @@
248
},
249
{
250
"ImportPath": "github.com/whyrusleeping/iptb",
251
- "Rev": "7f5790b9a136aca057bc8f1dc711e204c6343504"
251
+ "Rev": "4fa36405d0baea7773676f83fba9695e9a560473"
252
},
253
{
254
"ImportPath": "golang.org/x/crypto/blowfish",
255
- "Rev": "b7d6bf2c61544745a02f83dec90393985fc3a065"
255
+ "Rev": "c84e1f8e3a7e322d497cd16c0e8a13c7e127baf3"
256
},
257
{
258
"ImportPath": "golang.org/x/crypto/sha3",
259
- "Rev": "b7d6bf2c61544745a02f83dec90393985fc3a065"
259
+ "Rev": "c84e1f8e3a7e322d497cd16c0e8a13c7e127baf3"
260
},
261
{
262
"ImportPath": "golang.org/x/net/context",
263
- "Rev": "7dbad50ab5b31073856416cdcfeb2796d682f844"
263
+ "Rev": "ff8eb9a34a5cbb9941ffc6f84a19a8014c2646ad"
264
},
265
{
266
"ImportPath": "gopkg.in/fsnotify.v1",
Godeps/_workspace/src/github.com/Sirupsen/logrus/CHANGELOG.md
new
+7
@@ -0,0 +1,7 @@
1
+# 0.7.3
2
+
3
+formatter/\*: allow configuration of timestamp layout
4
+
5
+# 0.7.2
6
+
7
+formatter/text: Add configuration option for time format (#158)
Godeps/_workspace/src/github.com/Sirupsen/logrus/README.md
+28
-29
@@ -37,11 +37,13 @@ attached, the output is compatible with the
37
[logfmt](http://godoc.org/github.com/kr/logfmt) format:
38
39
```text
40
-time="2014-04-20 15:36:23.830442383 -0400 EDT" level="info" msg="A group of walrus emerges from the ocean" animal="walrus" size=10
41
-time="2014-04-20 15:36:23.830584199 -0400 EDT" level="warning" msg="The group's number increased tremendously!" omg=true number=122
42
-time="2014-04-20 15:36:23.830596521 -0400 EDT" level="info" msg="A giant walrus appears!" animal="walrus" size=10
43
-time="2014-04-20 15:36:23.830611837 -0400 EDT" level="info" msg="Tremendously sized cow enters the ocean." animal="walrus" size=9
44
-time="2014-04-20 15:36:23.830626464 -0400 EDT" level="fatal" msg="The ice breaks!" omg=true number=100
40
+time="2015-03-26T01:27:38-04:00" level=debug msg="Started observing beach" animal=walrus number=8
41
+time="2015-03-26T01:27:38-04:00" level=info msg="A group of walrus emerges from the ocean" animal=walrus size=10
42
+time="2015-03-26T01:27:38-04:00" level=warning msg="The group's number increased tremendously!" number=122 omg=true
43
+time="2015-03-26T01:27:38-04:00" level=debug msg="Temperature changes" temperature=-4
44
+time="2015-03-26T01:27:38-04:00" level=panic msg="It's over 9000!" animal=orca size=9009
45
+time="2015-03-26T01:27:38-04:00" level=fatal msg="The ice breaks!" err=&{0x2082280c0 map[animal:orca size:9009] 2015-03-26 01:27:38.441574009 -0400 EDT panic It's over 9000!} number=100 omg=true
46
+exit status 1
47
```
48
49
#### Example
@@ -106,6 +108,16 @@ func main() {
108
"omg": true,
109
"number": 100,
110
}).Fatal("The ice breaks!")
111
+
112
+ // A common pattern is to re-use fields between logging statements by re-using
113
+ // the logrus.Entry returned from WithFields()
114
+ contextLogger := log.WithFields(log.Fields{
115
+ "common": "this is a common field",
116
+ "other": "I also should be logged always",
117
+ })
118
+
119
+ contextLogger.Info("I'll be logged with common and other field")
120
+ contextLogger.Info("Me too")
121
}
122
```
123
@@ -187,31 +199,18 @@ func init() {
199
}
200
```
201
190
-* [`github.com/Sirupsen/logrus/hooks/airbrake`](https://github.com/Sirupsen/logrus/blob/master/hooks/airbrake/airbrake.go)
191
- Send errors to an exception tracking service compatible with the Airbrake API.
192
- Uses [`airbrake-go`](https://github.com/tobi/airbrake-go) behind the scenes.
193
-
194
-* [`github.com/Sirupsen/logrus/hooks/papertrail`](https://github.com/Sirupsen/logrus/blob/master/hooks/papertrail/papertrail.go)
195
- Send errors to the Papertrail hosted logging service via UDP.
196
-
197
-* [`github.com/Sirupsen/logrus/hooks/syslog`](https://github.com/Sirupsen/logrus/blob/master/hooks/syslog/syslog.go)
198
- Send errors to remote syslog server.
199
- Uses standard library `log/syslog` behind the scenes.
200
-
201
-* [`github.com/Sirupsen/logrus/hooks/bugsnag`](https://github.com/Sirupsen/logrus/blob/master/hooks/bugsnag/bugsnag.go)
202
- Send errors to the Bugsnag exception tracking service.
203
-
204
-* [`github.com/nubo/hiprus`](https://github.com/nubo/hiprus)
205
- Send errors to a channel in hipchat.
206
-
207
-* [`github.com/sebest/logrusly`](https://github.com/sebest/logrusly)
208
- Send logs to Loggly (https://www.loggly.com/)
209
-
210
-* [`github.com/johntdyer/slackrus`](https://github.com/johntdyer/slackrus)
211
- Hook for Slack chat.
202
213
-* [`github.com/wercker/journalhook`](https://github.com/wercker/journalhook).
214
- Hook for logging to `systemd-journald`.
203
+| Hook | Description |
204
+| ----- | ----------- |
205
+| [Airbrake](https://github.com/Sirupsen/logrus/blob/master/hooks/airbrake/airbrake.go) | Send errors to an exception tracking service compatible with the Airbrake API. Uses [`airbrake-go`](https://github.com/tobi/airbrake-go) behind the scenes. |
206
+| [Papertrail](https://github.com/Sirupsen/logrus/blob/master/hooks/papertrail/papertrail.go) | Send errors to the Papertrail hosted logging service via UDP. |
207
+| [Syslog](https://github.com/Sirupsen/logrus/blob/master/hooks/syslog/syslog.go) | Send errors to remote syslog server. Uses standard library `log/syslog` behind the scenes. |
208
+| [BugSnag](https://github.com/Sirupsen/logrus/blob/master/hooks/bugsnag/bugsnag.go) | Send errors to the Bugsnag exception tracking service. |
209
+| [Hiprus](https://github.com/nubo/hiprus) | Send errors to a channel in hipchat. |
210
+| [Logrusly](https://github.com/sebest/logrusly) | Send logs to [Loggly](https://www.loggly.com/) |
211
+| [Slackrus](https://github.com/johntdyer/slackrus) | Hook for Slack chat. |
212
+| [Journalhook](https://github.com/wercker/journalhook) | Hook for logging to `systemd-journald` |
213
+| [Graylog](https://github.com/gemnasium/logrus-hooks/tree/master/graylog) | Hook for logging to [Graylog](http://graylog2.org/) |
214
215
#### Level logging
216
Godeps/_workspace/src/github.com/Sirupsen/logrus/examples/hook/hook.go
+2
-2
@@ -8,8 +8,8 @@ import (
8
var log = logrus.New()
9
10
func init() {
11
- log.Formatter = // default
12
- new(logrus.TextFormatter)
11
+ log. // default
12
+ Formatter = new(logrus.TextFormatter)
13
log.Hooks.Add(airbrake.NewHook("https://example.com", "xyz", "development"))
14
}
15
Godeps/_workspace/src/github.com/Sirupsen/logrus/formatter.go
+4
@@ -1,5 +1,9 @@
1
package logrus
2
3
+import "time"
4
+
5
+const DefaultTimestampFormat = time.RFC3339
6
+
7
// The Formatter interface is used to implement a custom Formatter. It takes an
8
// `Entry`. It exposes all the fields, including the default ones:
9
//
Godeps/_workspace/src/github.com/Sirupsen/logrus/formatters/logstash/logstash.go
+10
-2
@@ -3,19 +3,27 @@ package logstash
3
import (
4
"encoding/json"
5
"fmt"
6
+
7
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/Sirupsen/logrus"
7
- "time"
8
)
9
10
// Formatter generates json in logstash format.
11
// Logstash site: http://logstash.net/
12
type LogstashFormatter struct {
13
Type string // if not empty use for logstash type field.
14
+
15
+ // TimestampFormat sets the format used for timestamps.
16
+ TimestampFormat string
17
}
18
19
func (f *LogstashFormatter) Format(entry *logrus.Entry) ([]byte, error) {
20
entry.Data["@version"] = 1
18
- entry.Data["@timestamp"] = entry.Time.Format(time.RFC3339)
21
+
22
+ if f.TimestampFormat == "" {
23
+ f.TimestampFormat = logrus.DefaultTimestampFormat
24
+ }
25
+
26
+ entry.Data["@timestamp"] = entry.Time.Format(f.TimestampFormat)
27
28
// set message field
29
v, ok := entry.Data["message"]
Godeps/_workspace/src/github.com/Sirupsen/logrus/json_formatter.go
+10
-3
@@ -3,10 +3,12 @@ package logrus
3
import (
4
"encoding/json"
5
"fmt"
6
- "time"
6
)
7
9
-type JSONFormatter struct{}
8
+type JSONFormatter struct {
9
+ // TimestampFormat sets the format used for marshaling timestamps.
10
+ TimestampFormat string
11
+}
12
13
func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
14
data := make(Fields, len(entry.Data)+3)
@@ -21,7 +23,12 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
23
}
24
}
25
prefixFieldClashes(data)
24
- data["time"] = entry.Time.Format(time.RFC3339)
26
+
27
+ if f.TimestampFormat == "" {
28
+ f.TimestampFormat = DefaultTimestampFormat
29
+ }
30
+
31
+ data["time"] = entry.Time.Format(f.TimestampFormat)
32
data["msg"] = entry.Message
33
data["level"] = entry.Level.String()
34
Godeps/_workspace/src/github.com/Sirupsen/logrus/logrus_test.go
+1
-1
@@ -191,7 +191,7 @@ func TestUserSuppliedLevelFieldHasPrefix(t *testing.T) {
191
log.WithField("level", 1).Info("test")
192
}, func(fields Fields) {
193
assert.Equal(t, fields["level"], "info")
194
- assert.Equal(t, fields["fields.level"], 1)
194
+ assert.Equal(t, fields["fields.level"], 1.0) // JSON has floats only
195
})
196
}
197
Godeps/_workspace/src/github.com/Sirupsen/logrus/text_formatter.go
+8
-2
@@ -46,6 +46,9 @@ type TextFormatter struct {
46
// the time passed since beginning of execution.
47
FullTimestamp bool
48
49
+ // TimestampFormat to use for display when a full timestamp is printed
50
+ TimestampFormat string
51
+
52
// The fields are sorted by default for a consistent output. For applications
53
// that log extremely frequently and don't use the JSON formatter this may not
54
// be desired.
@@ -68,11 +71,14 @@ func (f *TextFormatter) Format(entry *Entry) ([]byte, error) {
71
72
isColored := (f.ForceColors || isTerminal) && !f.DisableColors
73
74
+ if f.TimestampFormat == "" {
75
+ f.TimestampFormat = DefaultTimestampFormat
76
+ }
77
if isColored {
78
f.printColored(b, entry, keys)
79
} else {
80
if !f.DisableTimestamp {
75
- f.appendKeyValue(b, "time", entry.Time.Format(time.RFC3339))
81
+ f.appendKeyValue(b, "time", entry.Time.Format(f.TimestampFormat))
82
}
83
f.appendKeyValue(b, "level", entry.Level.String())
84
f.appendKeyValue(b, "msg", entry.Message)
@@ -103,7 +109,7 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []strin
109
if !f.FullTimestamp {
110
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d] %-44s ", levelColor, levelText, miniTS(), entry.Message)
111
} else {
106
- fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %-44s ", levelColor, levelText, entry.Time.Format(time.RFC3339), entry.Message)
112
+ fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %-44s ", levelColor, levelText, entry.Time.Format(f.TimestampFormat), entry.Message)
113
}
114
for _, k := range keys {
115
v := entry.Data[k]
Godeps/_workspace/src/github.com/Sirupsen/logrus/text_formatter_test.go
+25
-1
@@ -3,8 +3,8 @@ package logrus
3
import (
4
"bytes"
5
"errors"
6
-
6
"testing"
7
+ "time"
8
)
9
10
func TestQuoting(t *testing.T) {
@@ -33,5 +33,29 @@ func TestQuoting(t *testing.T) {
33
checkQuoting(true, errors.New("invalid argument"))
34
}
35
36
+func TestTimestampFormat(t *testing.T) {
37
+ checkTimeStr := func(format string) {
38
+ customFormatter := &TextFormatter{DisableColors: true, TimestampFormat: format}
39
+ customStr, _ := customFormatter.Format(WithField("test", "test"))
40
+ timeStart := bytes.Index(customStr, ([]byte)("time="))
41
+ timeEnd := bytes.Index(customStr, ([]byte)("level="))
42
+ timeStr := customStr[timeStart+5 : timeEnd-1]
43
+ if timeStr[0] == '"' && timeStr[len(timeStr)-1] == '"' {
44
+ timeStr = timeStr[1 : len(timeStr)-1]
45
+ }
46
+ if format == "" {
47
+ format = time.RFC3339
48
+ }
49
+ _, e := time.Parse(format, (string)(timeStr))
50
+ if e != nil {
51
+ t.Errorf("time string \"%s\" did not match provided time format \"%s\": %s", timeStr, format, e)
52
+ }
53
+ }
54
+
55
+ checkTimeStr("2006-01-02T15:04:05.000000000Z07:00")
56
+ checkTimeStr("Mon Jan _2 15:04:05 2006")
57
+ checkTimeStr("")
58
+}
59
+
60
// TODO add tests for sorting etc., this requires a parser for the text
61
// formatter output.
Godeps/_workspace/src/github.com/cheggaaa/pb/example/copy/copy.go
+4
-4
@@ -1,14 +1,14 @@
1
package main
2
3
import (
4
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/cheggaaa/pb"
5
- "os"
4
"fmt"
5
+ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/cheggaaa/pb"
6
"io"
8
- "time"
9
- "strings"
7
"net/http"
8
+ "os"
9
"strconv"
10
+ "strings"
11
+ "time"
12
)
13
14
func main() {
Godeps/_workspace/src/github.com/cheggaaa/pb/pb_solaris.go
+1
-1
@@ -2,4 +2,4 @@
2
3
package pb
4
5
-const sys_ioctl = 54
\ No newline at end of file
5
+const sys_ioctl = 54
Godeps/_workspace/src/github.com/cheggaaa/pb/reader.go
+1
-1
@@ -14,4 +14,4 @@ func (r *Reader) Read(p []byte) (n int, err error) {
14
n, err = r.Reader.Read(p)
15
r.bar.Add(n)
16
return
17
-}
\ No newline at end of file
17
+}
Godeps/_workspace/src/github.com/crowdmob/goamz/aws/aws_test.go
+2
-2
@@ -104,11 +104,11 @@ func (s *S) TestCredentialsFileAuth(c *check.C) {
104
105
[default] ; comment 123
106
aws_access_key_id = keyid1 ;comment
107
-aws_secret_access_key=key1
107
+aws_secret_access_key=key1
108
109
[profile2]
110
aws_access_key_id = keyid2 ;comment
111
- aws_secret_access_key=key2
111
+ aws_secret_access_key=key2
112
aws_session_token=token1
113
114
`
Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes.go
+6
@@ -111,6 +111,8 @@ func humanateBigBytes(s, base *big.Int, sizes []string) string {
111
112
// BigBytes produces a human readable representation of an SI size.
113
//
114
+// See also: ParseBigBytes.
115
+//
116
// BigBytes(82854982) -> 83MB
117
func BigBytes(s *big.Int) string {
118
sizes := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
@@ -119,6 +121,8 @@ func BigBytes(s *big.Int) string {
121
122
// BigIBytes produces a human readable representation of an IEC size.
123
//
124
+// See also: ParseBigBytes.
125
+//
126
// BigIBytes(82854982) -> 79MiB
127
func BigIBytes(s *big.Int) string {
128
sizes := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"}
@@ -128,6 +132,8 @@ func BigIBytes(s *big.Int) string {
132
// ParseBigBytes parses a string representation of bytes into the number
133
// of bytes it represents.
134
//
135
+// See also: BigBytes, BigIBytes.
136
+//
137
// ParseBigBytes("42MB") -> 42000000, nil
138
// ParseBigBytes("42mib") -> 44040192, nil
139
func ParseBigBytes(s string) (*big.Int, error) {
Godeps/_workspace/src/github.com/dustin/go-humanize/bytes.go
+6
@@ -82,6 +82,8 @@ func humanateBytes(s uint64, base float64, sizes []string) string {
82
83
// Bytes produces a human readable representation of an SI size.
84
//
85
+// See also: ParseBytes.
86
+//
87
// Bytes(82854982) -> 83MB
88
func Bytes(s uint64) string {
89
sizes := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB"}
@@ -90,6 +92,8 @@ func Bytes(s uint64) string {
92
93
// IBytes produces a human readable representation of an IEC size.
94
//
95
+// See also: ParseBytes.
96
+//
97
// IBytes(82854982) -> 79MiB
98
func IBytes(s uint64) string {
99
sizes := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"}
@@ -99,6 +103,8 @@ func IBytes(s uint64) string {
103
// ParseBytes parses a string representation of bytes into the number
104
// of bytes it represents.
105
//
106
+// See Also: Bytes, IBytes.
107
+//
108
// ParseBytes("42MB") -> 42000000, nil
109
// ParseBytes("42mib") -> 44040192, nil
110
func ParseBytes(s string) (uint64, error) {
Godeps/_workspace/src/github.com/dustin/go-humanize/comma.go
+34
@@ -1,6 +1,7 @@
1
package humanize
2
3
import (
4
+ "bytes"
5
"math/big"
6
"strconv"
7
"strings"
@@ -35,6 +36,39 @@ func Comma(v int64) string {
36
return sign + strings.Join(parts[j:len(parts)], ",")
37
}
38
39
+// Commaf produces a string form of the given number in base 10 with
40
+// commas after every three orders of magnitude.
41
+//
42
+// e.g. Comma(834142.32) -> 834,142.32
43
+func Commaf(v float64) string {
44
+ buf := &bytes.Buffer{}
45
+ if v < 0 {
46
+ buf.Write([]byte{'-'})
47
+ v = 0 - v
48
+ }
49
+
50
+ comma := []byte{','}
51
+
52
+ parts := strings.Split(strconv.FormatFloat(v, 'f', -1, 64), ".")
53
+ pos := 0
54
+ if len(parts[0])%3 != 0 {
55
+ pos += len(parts[0]) % 3
56
+ buf.WriteString(parts[0][:pos])
57
+ buf.Write(comma)
58
+ }
59
+ for ; pos < len(parts[0]); pos += 3 {
60
+ buf.WriteString(parts[0][pos : pos+3])
61
+ buf.Write(comma)
62
+ }
63
+ buf.Truncate(buf.Len() - 1)
64
+
65
+ if len(parts) > 1 {
66
+ buf.Write([]byte{'.'})
67
+ buf.WriteString(parts[1])
68
+ }
69
+ return buf.String()
70
+}
71
+
72
// BigComma produces a string form of the given big.Int in base 10
73
// with commas after every three orders of magnitude.
74
func BigComma(b *big.Int) string {
Godeps/_workspace/src/github.com/dustin/go-humanize/comma_test.go
+36
@@ -1,6 +1,7 @@
1
package humanize
2
3
import (
4
+ "math"
5
"math/big"
6
"testing"
7
)
@@ -33,12 +34,47 @@ func TestCommas(t *testing.T) {
34
}.validate(t)
35
}
36
37
+func TestCommafs(t *testing.T) {
38
+ testList{
39
+ {"0", Commaf(0), "0"},
40
+ {"10.11", Commaf(10.11), "10.11"},
41
+ {"100", Commaf(100), "100"},
42
+ {"1,000", Commaf(1000), "1,000"},
43
+ {"10,000", Commaf(10000), "10,000"},
44
+ {"100,000", Commaf(100000), "100,000"},
45
+ {"834,142.32", Commaf(834142.32), "834,142.32"},
46
+ {"10,000,000", Commaf(10000000), "10,000,000"},
47
+ {"10,100,000", Commaf(10100000), "10,100,000"},
48
+ {"10,010,000", Commaf(10010000), "10,010,000"},
49
+ {"10,001,000", Commaf(10001000), "10,001,000"},
50
+ {"123,456,789", Commaf(123456789), "123,456,789"},
51
+ {"maxf64", Commaf(math.MaxFloat64), "179,769,313,486,231,570,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000"},
52
+ {"minf64", Commaf(math.SmallestNonzeroFloat64), "0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005"},
53
+ {"-123,456,789", Commaf(-123456789), "-123,456,789"},
54
+ {"-10,100,000", Commaf(-10100000), "-10,100,000"},
55
+ {"-10,010,000", Commaf(-10010000), "-10,010,000"},
56
+ {"-10,001,000", Commaf(-10001000), "-10,001,000"},
57
+ {"-10,000,000", Commaf(-10000000), "-10,000,000"},
58
+ {"-100,000", Commaf(-100000), "-100,000"},
59
+ {"-10,000", Commaf(-10000), "-10,000"},
60
+ {"-1,000", Commaf(-1000), "-1,000"},
61
+ {"-100.11", Commaf(-100.11), "-100.11"},
62
+ {"-10", Commaf(-10), "-10"},
63
+ }.validate(t)
64
+}
65
+
66
func BenchmarkCommas(b *testing.B) {
67
for i := 0; i < b.N; i++ {
68
Comma(1234567890)
69
}
70
}
71
72
+func BenchmarkCommaf(b *testing.B) {
73
+ for i := 0; i < b.N; i++ {
74
+ Commaf(1234567890.83584)
75
+ }
76
+}
77
+
78
func BenchmarkBigCommas(b *testing.B) {
79
for i := 0; i < b.N; i++ {
80
BigComma(big.NewInt(1234567890))
Godeps/_workspace/src/github.com/dustin/go-humanize/humanize.go
+1
-1
@@ -1,5 +1,5 @@
1
/*
2
-Package humanize converts boring ugly numbers to human-friendly strings.
2
+Package humanize converts boring ugly numbers to human-friendly strings and back.
3
4
Durations can be turned into strings such as "3 days ago", numbers
5
representing sizes like 82854982 into useful strings like, "83MB" or
Godeps/_workspace/src/github.com/dustin/go-humanize/number.go
new
+192
@@ -0,0 +1,192 @@
1
+package humanize
2
+
3
+/*
4
+Slightly adapted from the source to fit go-humanize.
5
+
6
+Author: https://github.com/gorhill
7
+Source: https://gist.github.com/gorhill/5285193
8
+
9
+*/
10
+
11
+import (
12
+ "math"
13
+ "strconv"
14
+)
15
+
16
+var (
17
+ renderFloatPrecisionMultipliers = [...]float64{
18
+ 1,
19
+ 10,
20
+ 100,
21
+ 1000,
22
+ 10000,
23
+ 100000,
24
+ 1000000,
25
+ 10000000,
26
+ 100000000,
27
+ 1000000000,
28
+ }
29
+
30
+ renderFloatPrecisionRounders = [...]float64{
31
+ 0.5,
32
+ 0.05,
33
+ 0.005,
34
+ 0.0005,
35
+ 0.00005,
36
+ 0.000005,
37
+ 0.0000005,
38
+ 0.00000005,
39
+ 0.000000005,
40
+ 0.0000000005,
41
+ }
42
+)
43
+
44
+// FormatFloat produces a formatted number as string based on the following user-specified criteria:
45
+// * thousands separator
46
+// * decimal separator
47
+// * decimal precision
48
+//
49
+// Usage: s := RenderFloat(format, n)
50
+// The format parameter tells how to render the number n.
51
+//
52
+// See examples: http://play.golang.org/p/LXc1Ddm1lJ
53
+//
54
+// Examples of format strings, given n = 12345.6789:
55
+// "#,###.##" => "12,345.67"
56
+// "#,###." => "12,345"
57
+// "#,###" => "12345,678"
58
+// "#\u202F###,##" => "12 345,68"
59
+// "#.###,###### => 12.345,678900
60
+// "" (aka default format) => 12,345.67
61
+//
62
+// The highest precision allowed is 9 digits after the decimal symbol.
63
+// There is also a version for integer number, FormatInteger(),
64
+// which is convenient for calls within template.
65
+func FormatFloat(format string, n float64) string {
66
+ // Special cases:
67
+ // NaN = "NaN"
68
+ // +Inf = "+Infinity"
69
+ // -Inf = "-Infinity"
70
+ if math.IsNaN(n) {
71
+ return "NaN"
72
+ }
73
+ if n > math.MaxFloat64 {
74
+ return "Infinity"
75
+ }
76
+ if n < -math.MaxFloat64 {
77
+ return "-Infinity"
78
+ }
79
+
80
+ // default format
81
+ precision := 2
82
+ decimalStr := "."
83
+ thousandStr := ","
84
+ positiveStr := ""
85
+ negativeStr := "-"
86
+
87
+ if len(format) > 0 {
88
+ format := []rune(format)
89
+
90
+ // If there is an explicit format directive,
91
+ // then default values are these:
92
+ precision = 9
93
+ thousandStr = ""
94
+
95
+ // collect indices of meaningful formatting directives
96
+ formatIndx := []int{}
97
+ for i, char := range format {
98
+ if char != '#' && char != '0' {
99
+ formatIndx = append(formatIndx, i)
100
+ }
101
+ }
102
+
103
+ if len(formatIndx) > 0 {
104
+ // Directive at index 0:
105
+ // Must be a '+'
106
+ // Raise an error if not the case
107
+ // index: 0123456789
108
+ // +0.000,000
109
+ // +000,000.0
110
+ // +0000.00
111
+ // +0000
112
+ if formatIndx[0] == 0 {
113
+ if format[formatIndx[0]] != '+' {
114
+ panic("RenderFloat(): invalid positive sign directive")
115
+ }
116
+ positiveStr = "+"
117
+ formatIndx = formatIndx[1:]
118
+ }
119
+
120
+ // Two directives:
121
+ // First is thousands separator
122
+ // Raise an error if not followed by 3-digit
123
+ // 0123456789
124
+ // 0.000,000
125
+ // 000,000.00
126
+ if len(formatIndx) == 2 {
127
+ if (formatIndx[1] - formatIndx[0]) != 4 {
128
+ panic("RenderFloat(): thousands separator directive must be followed by 3 digit-specifiers")
129
+ }
130
+ thousandStr = string(format[formatIndx[0]])
131
+ formatIndx = formatIndx[1:]
132
+ }
133
+
134
+ // One directive:
135
+ // Directive is decimal separator
136
+ // The number of digit-specifier following the separator indicates wanted precision
137
+ // 0123456789
138
+ // 0.00
139
+ // 000,0000
140
+ if len(formatIndx) == 1 {
141
+ decimalStr = string(format[formatIndx[0]])
142
+ precision = len(format) - formatIndx[0] - 1
143
+ }
144
+ }
145
+ }
146
+
147
+ // generate sign part
148
+ var signStr string
149
+ if n >= 0.000000001 {
150
+ signStr = positiveStr
151
+ } else if n <= -0.000000001 {
152
+ signStr = negativeStr
153
+ n = -n
154
+ } else {
155
+ signStr = ""
156
+ n = 0.0
157
+ }
158
+
159
+ // split number into integer and fractional parts
160
+ intf, fracf := math.Modf(n + renderFloatPrecisionRounders[precision])
161
+
162
+ // generate integer part string
163
+ intStr := strconv.Itoa(int(intf))
164
+
165
+ // add thousand separator if required
166
+ if len(thousandStr) > 0 {
167
+ for i := len(intStr); i > 3; {
168
+ i -= 3
169
+ intStr = intStr[:i] + thousandStr + intStr[i:]
170
+ }
171
+ }
172
+
173
+ // no fractional part, we can leave now
174
+ if precision == 0 {
175
+ return signStr + intStr
176
+ }
177
+
178
+ // generate fractional part
179
+ fracStr := strconv.Itoa(int(fracf * renderFloatPrecisionMultipliers[precision]))
180
+ // may need padding
181
+ if len(fracStr) < precision {
182
+ fracStr = "000000000000000"[:precision-len(fracStr)] + fracStr
183
+ }
184
+
185
+ return signStr + intStr + decimalStr + fracStr
186
+}
187
+
188
+// FormatInteger produces a formatted number as string.
189
+// See FormatFloat.
190
+func FormatInteger(format string, n int) string {
191
+ return FormatFloat(format, float64(n))
192
+}
Godeps/_workspace/src/github.com/dustin/go-humanize/number_test.go
new
+78
@@ -0,0 +1,78 @@
1
+package humanize
2
+
3
+import (
4
+ "math"
5
+ "testing"
6
+)
7
+
8
+type TestStruct struct {
9
+ name string
10
+ format string
11
+ num float64
12
+ formatted string
13
+}
14
+
15
+func TestFormatFloat(t *testing.T) {
16
+ tests := []TestStruct{
17
+ {"default", "", 12345.6789, "12,345.68"},
18
+ {"#", "#", 12345.6789, "12345.678900000"},
19
+ {"#.", "#.", 12345.6789, "12346"},
20
+ {"#,#", "#,#", 12345.6789, "12345,7"},
21
+ {"#,##", "#,##", 12345.6789, "12345,68"},
22
+ {"#,###", "#,###", 12345.6789, "12345,679"},
23
+ {"#,###.", "#,###.", 12345.6789, "12,346"},
24
+ {"#,###.##", "#,###.##", 12345.6789, "12,345.68"},
25
+ {"#,###.###", "#,###.###", 12345.6789, "12,345.679"},
26
+ {"#,###.####", "#,###.####", 12345.6789, "12,345.6789"},
27
+ {"#.###,######", "#.###,######", 12345.6789, "12.345,678900"},
28
+ {"#\u202f###,##", "#\u202f###,##", 12345.6789, "12 345,68"},
29
+
30
+ // special cases
31
+ {"NaN", "#", math.NaN(), "NaN"},
32
+ {"+Inf", "#", math.Inf(1), "Infinity"},
33
+ {"-Inf", "#", math.Inf(-1), "-Infinity"},
34
+ {"signStr <= -0.000000001", "", -0.000000002, "-0.00"},
35
+ {"signStr = 0", "", 0, "0.00"},
36
+ {"Format directive must start with +", "+000", 12345.6789, "+12345.678900000"},
37
+ }
38
+
39
+ for _, test := range tests {
40
+ got := FormatFloat(test.format, test.num)
41
+ if got != test.formatted {
42
+ t.Errorf("On %v (%v, %v), got %v, wanted %v",
43
+ test.name, test.format, test.num, got, test.formatted)
44
+ }
45
+ }
46
+ // Test a single integer
47
+ got := FormatInteger("#", 12345)
48
+ if got != "12345.000000000" {
49
+ t.Errorf("On %v (%v, %v), got %v, wanted %v",
50
+ "integerTest", "#", 12345, got, "12345.000000000")
51
+ }
52
+ // Test the things that could panic
53
+ panictests := []TestStruct{
54
+ {"RenderFloat(): invalid positive sign directive", "-", 12345.6789, "12,345.68"},
55
+ {"RenderFloat(): thousands separator directive must be followed by 3 digit-specifiers", "0.01", 12345.6789, "12,345.68"},
56
+ }
57
+ for _, test := range panictests {
58
+ didPanic := false
59
+ var message interface{}
60
+ func() {
61
+
62
+ defer func() {
63
+ if message = recover(); message != nil {
64
+ didPanic = true
65
+ }
66
+ }()
67
+
68
+ // call the target function
69
+ _ = FormatFloat(test.format, test.num)
70
+
71
+ }()
72
+ if didPanic != true {
73
+ t.Errorf("On %v, should have panic and did not.",
74
+ test.name)
75
+ }
76
+ }
77
+
78
+}
Godeps/_workspace/src/github.com/dustin/go-humanize/si.go
+6
@@ -54,6 +54,8 @@ func init() {
54
// and returns the prefix along with the value adjusted to be within
55
// that prefix.
56
//
57
+// See also: SI, ParseSI.
58
+//
59
// e.g. ComputeSI(2.2345e-12) -> (2.2345, "p")
60
func ComputeSI(input float64) (float64, string) {
61
if input == 0 {
@@ -79,6 +81,8 @@ func ComputeSI(input float64) (float64, string) {
81
//
82
// SI uses Ftoa to format float value, removing trailing zeros.
83
//
84
+// See also: ComputeSI, ParseSI.
85
+//
86
// e.g. SI(1000000, B) -> 1MB
87
// e.g. SI(2.2345e-12, "F") -> 2.2345pF
88
func SI(input float64, unit string) string {
@@ -90,6 +94,8 @@ var errInvalid = errors.New("invalid input")
94
95
// ParseSI parses an SI string back into the number and unit.
96
//
97
+// See also: SI, ComputeSI.
98
+//
99
// e.g. ParseSI(2.2345pF) -> (2.2345e-12, "F", nil)
100
func ParseSI(input string) (float64, string, error) {
101
found := riParseRegex.FindStringSubmatch(input)
Godeps/_workspace/src/github.com/jbenet/go-fuse-version/version.go
+2
-2
@@ -1,7 +1,7 @@
1
// package fuseversion simply exposes the version of FUSE installed
2
// in the user's machine. For reasoning, see:
3
-// - https://github.com/ipfs/go-ipfs/issues/177
4
-// - https://github.com/ipfs/go-ipfs/issues/202
3
+// - https://github.com/jbenet/go-ipfs/issues/177
4
+// - https://github.com/jbenet/go-ipfs/issues/202
5
// - https://github.com/osxfuse/osxfuse/issues/175#issuecomment-61888505
6
package fuseversion
7
Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net/Godeps/Godeps.json
+17
-4
@@ -1,18 +1,31 @@
1
{
2
"ImportPath": "github.com/jbenet/go-multiaddr-net",
3
- "GoVersion": "go1.3",
3
+ "GoVersion": "go1.4.2",
4
"Packages": [
5
"./..."
6
],
7
"Deps": [
8
{
9
"ImportPath": "github.com/h2so5/utp",
10
- "Rev": "654d875bb65e96729678180215cf080fe2810371"
10
+ "Rev": "5288a05e1781334589c4b8806bcfb1e69f5b5d63"
11
+ },
12
+ {
13
+ "ImportPath": "github.com/jbenet/go-base58",
14
+ "Rev": "568a28d73fd97651d3442392036a658b6976eed5"
15
},
16
{
17
"ImportPath": "github.com/jbenet/go-multiaddr",
14
- "Comment": "0.1.2-34-g0d7b54b",
15
- "Rev": "0d7b54ba432fda14bac37cdad717bd6270eacc85"
18
+ "Comment": "0.1.2-38-gc13f11b",
19
+ "Rev": "c13f11bbfe6439771f4df7bfb330f686826144e8"
20
+ },
21
+ {
22
+ "ImportPath": "github.com/jbenet/go-multihash",
23
+ "Comment": "0.1.0-36-g87e53a9",
24
+ "Rev": "87e53a9d2875a18a7863b351d22f912545e6b3a3"
25
+ },
26
+ {
27
+ "ImportPath": "golang.org/x/crypto/sha3",
28
+ "Rev": "1351f936d976c60a0a48d728281922cf63eafb8d"
29
}
30
]
31
}
Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net/Makefile
+1
-1
@@ -13,7 +13,7 @@ install: dep
13
cd multiaddr && go install
14
15
test:
16
- go test ./...
16
+ go test -race -cpu=5 -v ./...
17
18
dep:
19
cd multiaddr && go get ./...
Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net/convert.go
+2
-2
@@ -57,7 +57,7 @@ func FromNetAddr(a net.Addr) (ma.Multiaddr, error) {
57
return ipm.Encapsulate(udpm), nil
58
59
case "utp", "utp4", "utp6":
60
- acc, ok := a.(*utp.UTPAddr)
60
+ acc, ok := a.(*utp.Addr)
61
if !ok {
62
return nil, errIncorrectNetAddr
63
}
@@ -117,7 +117,7 @@ func ToNetAddr(maddr ma.Multiaddr) (net.Addr, error) {
117
case "udp", "udp4", "udp6":
118
return net.ResolveUDPAddr(network, host)
119
case "utp", "utp4", "utp6":
120
- return utp.ResolveUTPAddr(network, host)
120
+ return utp.ResolveAddr(network, host)
121
case "ip", "ip4", "ip6":
122
return net.ResolveIPAddr(network, host)
123
}
Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net/convert_test.go
+1
-1
@@ -91,7 +91,7 @@ func TestFromUDP(t *testing.T) {
91
92
func TestFromUTP(t *testing.T) {
93
testConvert(t, "/ip4/10.20.30.40/udp/1234/utp", func() (ma.Multiaddr, error) {
94
- return FromNetAddr(&utp.UTPAddr{
94
+ return FromNetAddr(&utp.Addr{
95
Addr: &net.UDPAddr{
96
IP: net.ParseIP("10.20.30.40"),
97
Port: 1234,
Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net/ip.go
+1
@@ -53,6 +53,7 @@ func IsThinWaist(m ma.Multiaddr) bool {
53
54
// IsIPLoopback returns whether a Multiaddr is a "Loopback" IP address
55
// This means either /ip4/127.0.0.1 or /ip6/::1
56
+// TODO: differentiate IsIPLoopback and OverIPLoopback
57
func IsIPLoopback(m ma.Multiaddr) bool {
58
b := m.Bytes()
59
Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net/multiaddr/multiaddr
Binary files a/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net/multiaddr/multiaddr and /dev/null differ
Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net/multiaddr/multiaddr.go
+1
-1
@@ -11,7 +11,7 @@ import (
11
)
12
13
var formats = []string{"string", "bytes", // flags
14
- "hex", "slice"}
14
+"hex", "slice"}
15
var format string
16
var hideLoopback bool
17
Godeps/_workspace/src/github.com/jbenet/go-multihash/multihash/.gobuilder.yml
new
+5
@@ -0,0 +1,5 @@
1
+---
2
+artifacts:
3
+ - LICENSE
4
+ - README.md
5
+ - install.dist.sh
Godeps/_workspace/src/github.com/jbenet/go-multihash/multihash/LICENSE
new
+21
@@ -0,0 +1,21 @@
1
+The MIT License (MIT)
2
+
3
+Copyright (c) 2014 Juan Batiz-Benet
4
+
5
+Permission is hereby granted, free of charge, to any person obtaining a copy
6
+of this software and associated documentation files (the "Software"), to deal
7
+in the Software without restriction, including without limitation the rights
8
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+copies of the Software, and to permit persons to whom the Software is
10
+furnished to do so, subject to the following conditions:
11
+
12
+The above copyright notice and this permission notice shall be included in
13
+all copies or substantial portions of the Software.
14
+
15
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+THE SOFTWARE.
Godeps/_workspace/src/github.com/jbenet/go-multihash/multihash/README.md
+5
-3
@@ -6,9 +6,11 @@ Warning: this is a **multihash** tool! Its digests follow the [multihash](https:
6
7
### Install
8
9
-```
10
-go get github.com/jbenet/go-multihash/multihash
11
-```
9
+- From Source:
10
+ ```
11
+ go get github.com/jbenet/go-multihash/multihash
12
+ ```
13
+- Precompiled Binaries: https://gobuilder.me/github.com/jbenet/go-multihash/multihash
14
15
### Usage
16
Godeps/_workspace/src/github.com/jbenet/go-multihash/multihash/install.dist.sh
new
+21
@@ -0,0 +1,21 @@
1
+#!/bin/sh
2
+
3
+bin=multihash
4
+
5
+# this script is currently brain dead.
6
+# it merely tries two locations.
7
+# in the future maybe use value of $PATH.
8
+
9
+binpath=/usr/local/bin
10
+if [ -d "$binpath" ]; then
11
+ mv "$bin" "$binpath/$bin"
12
+ echo "installed $binpath/$bin"
13
+ exit 0
14
+fi
15
+
16
+binpath=/usr/bin
17
+if [ -d "$binpath" ]; then
18
+ mv "$bin" "$binpath/$bin"
19
+ echo "installed $binpath/$bin"
20
+ exit 0
21
+fi
Godeps/_workspace/src/github.com/jbenet/go-multihash/multihash/main.go
+16
-92
@@ -1,15 +1,13 @@
1
package main
2
3
import (
4
- "bytes"
4
"flag"
5
"fmt"
6
"io"
8
- "io/ioutil"
7
"os"
10
- "strings"
8
9
mh "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
10
+ mhopts "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash/opts"
11
)
12
13
var usage = `usage: %s [options] [FILE]
@@ -20,91 +18,43 @@ Options:
18
`
19
20
// flags
23
-var encodings = []string{"raw", "hex", "base58", "base64"}
24
-var algorithms = []string{"sha1", "sha2-256", "sha2-512", "sha3"}
25
-var encoding string
26
-var algorithm string
27
-var algorithmCode int
28
-var length int
21
+var opts *mhopts.Options
22
var checkRaw string
23
var checkMh mh.Multihash
24
var inputFilename string
25
var quiet bool
26
34
-// joined names
35
-var algoStr string
36
-var encStr string
37
-
27
func init() {
28
flag.Usage = func() {
29
fmt.Fprintf(os.Stderr, usage, os.Args[0])
30
flag.PrintDefaults()
31
}
32
44
- algoStr = "one of: " + strings.Join(algorithms, ", ")
45
- flag.StringVar(&algorithm, "algorithm", "sha2-256", algoStr)
46
- flag.StringVar(&algorithm, "a", "sha2-256", algoStr+" (shorthand)")
47
-
48
- encStr = "one of: " + strings.Join(encodings, ", ")
49
- flag.StringVar(&encoding, "encoding", "base58", encStr)
50
- flag.StringVar(&encoding, "e", "base58", encStr+" (shorthand)")
33
+ opts = mhopts.SetupFlags(flag.CommandLine)
34
35
checkStr := "check checksum matches"
36
flag.StringVar(&checkRaw, "check", "", checkStr)
37
flag.StringVar(&checkRaw, "c", "", checkStr+" (shorthand)")
38
56
- lengthStr := "checksums length in bits (truncate). -1 is default"
57
- flag.IntVar(&length, "length", -1, lengthStr)
58
- flag.IntVar(&length, "l", -1, lengthStr+" (shorthand)")
59
-
39
quietStr := "quiet output (no newline on checksum, no error text)"
40
flag.BoolVar(&quiet, "quiet", false, quietStr)
41
flag.BoolVar(&quiet, "q", false, quietStr+" (shorthand)")
42
}
43
65
-func strIn(a string, set []string) bool {
66
- for _, s := range set {
67
- if s == a {
68
- return true
69
- }
70
- }
71
- return false
72
-}
73
-
74
-func parseFlags() error {
44
+func parseFlags(o *mhopts.Options) error {
45
flag.Parse()
76
-
77
- if !strIn(algorithm, algorithms) {
78
- return fmt.Errorf("algorithm '%s' not %s", algorithm, algoStr)
79
- }
80
- var found bool
81
- algorithmCode, found = mh.Names[algorithm]
82
- if !found {
83
- return fmt.Errorf("algorithm '%s' not found (lib error, pls report).")
84
- }
85
-
86
- if !strIn(encoding, encodings) {
87
- return fmt.Errorf("encoding '%s' not %s", encoding, encStr)
46
+ if err := o.ParseError(); err != nil {
47
+ return err
48
}
49
50
if checkRaw != "" {
51
var err error
92
- checkMh, err = Decode(encoding, checkRaw)
52
+ checkMh, err = mhopts.Decode(o.Encoding, checkRaw)
53
if err != nil {
54
return fmt.Errorf("fail to decode check '%s': %s", checkRaw, err)
55
}
56
}
57
98
- if length >= 0 {
99
- if length%8 != 0 {
100
- return fmt.Errorf("length must be multiple of 8")
101
- }
102
- length = length / 8
103
-
104
- if length > mh.DefaultLengths[algorithmCode] {
105
- length = mh.DefaultLengths[algorithmCode]
106
- }
107
- }
58
return nil
59
}
60
@@ -127,42 +77,13 @@ func getInput() (io.ReadCloser, error) {
77
return f, nil
78
}
79
}
130
-
131
-func check(h1 mh.Multihash, r io.Reader) error {
132
- h2, err := hash(r)
80
+func printHash(o *mhopts.Options, r io.Reader) error {
81
+ h, err := o.Multihash(r)
82
if err != nil {
83
return err
84
}
85
137
- if !bytes.Equal(h1, h2) {
138
- if quiet {
139
- os.Exit(1)
140
- }
141
- return fmt.Errorf("computed checksum did not match (-q for no output)")
142
- }
143
-
144
- if !quiet {
145
- fmt.Println("OK checksums match (-q for no output)")
146
- }
147
- return nil
148
-}
149
-
150
-func hash(r io.Reader) (mh.Multihash, error) {
151
- b, err := ioutil.ReadAll(r)
152
- if err != nil {
153
- return nil, err
154
- }
155
-
156
- return mh.Sum(b, algorithmCode, length)
157
-}
158
-
159
-func printHash(r io.Reader) error {
160
- h, err := hash(r)
161
- if err != nil {
162
- return err
163
- }
164
-
165
- s, err := Encode(encoding, h)
86
+ s, err := mhopts.Encode(o.Encoding, h)
87
if err != nil {
88
return err
89
}
@@ -182,17 +103,20 @@ func main() {
103
}
104
}
105
185
- err := parseFlags()
106
+ err := parseFlags(opts)
107
checkErr(err)
108
109
inp, err := getInput()
110
checkErr(err)
111
112
if checkMh != nil {
192
- err = check(checkMh, inp)
113
+ err = opts.Check(inp, checkMh)
114
checkErr(err)
115
+ if !quiet {
116
+ fmt.Println("OK checksums match (-q for no output)")
117
+ }
118
} else {
195
- err = printHash(inp)
119
+ err = printHash(opts, inp)
120
checkErr(err)
121
}
122
inp.Close()
Godeps/_workspace/src/github.com/jbenet/go-multihash/opts/README.md
new
+9
@@ -0,0 +1,9 @@
1
+# mhopts - multihash options for writing commands
2
+
3
+`mhopts` is a small package that helps to write commands which
4
+may take multihash options. Check it out in action:
5
+
6
+- [multihash](../multihash)
7
+- [hashpipe](https://github.com/jbenet/go-hashpipe)
8
+
9
+Godoc: [https://godoc.org/github.com/jbenet/go-multihash/opts](https://godoc.org/github.com/jbenet/go-multihash/opts)
Godeps/_workspace/src/github.com/jbenet/go-multihash/opts/coding.go
renamed
+1
-1
@@ -1,4 +1,4 @@
1
-package main
1
+package opts
2
3
import (
4
"encoding/base64"
Godeps/_workspace/src/github.com/jbenet/go-multihash/opts/opts.go
new
+131
@@ -0,0 +1,131 @@
1
+// Package opts helps to write commands which may take multihash
2
+// options.
3
+package opts
4
+
5
+import (
6
+ "bytes"
7
+ "errors"
8
+ "flag"
9
+ "fmt"
10
+ "io"
11
+ "io/ioutil"
12
+ "strings"
13
+
14
+ mh "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
15
+)
16
+
17
+// package errors
18
+var (
19
+ ErrMatch = errors.New("multihash checksums did not match")
20
+)
21
+
22
+// Options is a struct used to parse cli flags.
23
+type Options struct {
24
+ Encoding string
25
+ Algorithm string
26
+ AlgorithmCode int
27
+ Length int
28
+
29
+ fs *flag.FlagSet
30
+}
31
+
32
+// FlagValues are the values the various option flags can take.
33
+var FlagValues = struct {
34
+ Encodings []string
35
+ Algorithms []string
36
+}{
37
+ Encodings: []string{"raw", "hex", "base58", "base64"},
38
+ Algorithms: []string{"sha1", "sha2-256", "sha2-512", "sha3"},
39
+}
40
+
41
+// SetupFlags adds multihash related options to given flagset.
42
+func SetupFlags(f *flag.FlagSet) *Options {
43
+ // TODO: add arg for adding opt prefix and/or overriding opts
44
+
45
+ o := new(Options)
46
+ algoStr := "one of: " + strings.Join(FlagValues.Algorithms, ", ")
47
+ f.StringVar(&o.Algorithm, "algorithm", "sha2-256", algoStr)
48
+ f.StringVar(&o.Algorithm, "a", "sha2-256", algoStr+" (shorthand)")
49
+
50
+ encStr := "one of: " + strings.Join(FlagValues.Encodings, ", ")
51
+ f.StringVar(&o.Encoding, "encoding", "base58", encStr)
52
+ f.StringVar(&o.Encoding, "e", "base58", encStr+" (shorthand)")
53
+
54
+ lengthStr := "checksums length in bits (truncate). -1 is default"
55
+ f.IntVar(&o.Length, "length", -1, lengthStr)
56
+ f.IntVar(&o.Length, "l", -1, lengthStr+" (shorthand)")
57
+ return o
58
+}
59
+
60
+// Parse parses the values of flags from given argument slice.
61
+// It is equivalent to flags.Parse(args)
62
+func (o *Options) Parse(args []string) error {
63
+ if err := o.fs.Parse(args); err != nil {
64
+ return err
65
+ }
66
+ return o.ParseError()
67
+}
68
+
69
+// ParseError checks the parsed options for errors.
70
+func (o *Options) ParseError() error {
71
+ if !strIn(o.Encoding, FlagValues.Encodings) {
72
+ return fmt.Errorf("encoding '%s' not %s", o.Encoding, FlagValues.Encodings)
73
+ }
74
+
75
+ if !strIn(o.Algorithm, FlagValues.Algorithms) {
76
+ return fmt.Errorf("algorithm '%s' not %s", o.Algorithm, FlagValues.Algorithms)
77
+ }
78
+
79
+ var found bool
80
+ o.AlgorithmCode, found = mh.Names[o.Algorithm]
81
+ if !found {
82
+ return fmt.Errorf("algorithm '%s' not found (lib error, pls report).", o.Algorithm)
83
+ }
84
+
85
+ if o.Length >= 0 {
86
+ if o.Length%8 != 0 {
87
+ return fmt.Errorf("length must be multiple of 8")
88
+ }
89
+ o.Length = o.Length / 8
90
+
91
+ if o.Length > mh.DefaultLengths[o.AlgorithmCode] {
92
+ o.Length = mh.DefaultLengths[o.AlgorithmCode]
93
+ }
94
+ }
95
+ return nil
96
+}
97
+
98
+// strIn checks wither string a is in set.
99
+func strIn(a string, set []string) bool {
100
+ for _, s := range set {
101
+ if s == a {
102
+ return true
103
+ }
104
+ }
105
+ return false
106
+}
107
+
108
+// Check reads all the data in r, calculates its multihash,
109
+// and checks it matches h1
110
+func (o *Options) Check(r io.Reader, h1 mh.Multihash) error {
111
+ h2, err := o.Multihash(r)
112
+ if err != nil {
113
+ return err
114
+ }
115
+
116
+ if !bytes.Equal(h1, h2) {
117
+ return fmt.Errorf("computed checksum did not match")
118
+ }
119
+
120
+ return nil
121
+}
122
+
123
+// Multihash reads all the data in r and calculates its multihash.
124
+func (o *Options) Multihash(r io.Reader) (mh.Multihash, error) {
125
+ b, err := ioutil.ReadAll(r)
126
+ if err != nil {
127
+ return nil, err
128
+ }
129
+
130
+ return mh.Sum(b, o.AlgorithmCode, o.Length)
131
+}
Godeps/_workspace/src/github.com/jbenet/go-os-rename/rename_test.go
new
+60
@@ -0,0 +1,60 @@
1
+package osrename_test
2
+
3
+import (
4
+ "bytes"
5
+ rn "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-os-rename"
6
+ "io/ioutil"
7
+ "os"
8
+ "testing"
9
+)
10
+
11
+func tempdir(t testing.TB) (path string, cleanup func()) {
12
+ path, err := ioutil.TempDir("", "test-windows-rename")
13
+ if err != nil {
14
+ t.Fatalf("cannot create temp directory: %v", err)
15
+ }
16
+
17
+ cleanup = func() {
18
+ if err := os.RemoveAll(path); err != nil {
19
+ t.Errorf("tempdir cleanup failed: %v", err)
20
+ }
21
+ }
22
+ return path, cleanup
23
+}
24
+
25
+func TestAtomicRename(t *testing.T) {
26
+ dirBase, cleanup := tempdir(t)
27
+ defer cleanup()
28
+
29
+ // Create base file
30
+ origFilePath := dirBase + "original.txt"
31
+ err := ioutil.WriteFile(origFilePath, []byte("tests"), 0644)
32
+
33
+ if err != nil {
34
+ t.Fatalf("Could not write original test file")
35
+ }
36
+
37
+ // Create secondary file
38
+ tempFilePath := dirBase + "newTempFile.txt"
39
+ err = ioutil.WriteFile(tempFilePath, []byte("success"), 0644)
40
+ if err != nil {
41
+ t.Fatalf("Could not write temp file")
42
+ }
43
+
44
+ // Execute our magic rename function
45
+ err = rn.Rename(tempFilePath, origFilePath)
46
+ if err != nil {
47
+ t.Fatalf("Could not rename temp file")
48
+ }
49
+
50
+ // Let's read the renamed file and ensure that we get data
51
+ renamedFileBytes, err := ioutil.ReadFile(origFilePath)
52
+ if err != nil {
53
+ t.Fatalf("Could not read renamed file")
54
+ }
55
+
56
+ // Let's compare the bytes of the renamed file
57
+ if bytes.Compare(renamedFileBytes, []byte("success")) != 0 {
58
+ t.Fatalf("Did not find expected bytes in renamed file %d vs %d", renamedFileBytes, []byte("success"))
59
+ }
60
+}
Godeps/_workspace/src/github.com/jbenet/go-peerstream/example/example
Binary files a/Godeps/_workspace/src/github.com/jbenet/go-peerstream/example/example and /dev/null differ
Godeps/_workspace/src/github.com/jbenet/go-random/.travis.yml
+2
-1
@@ -6,6 +6,7 @@ go:
6
- tip
7
8
script:
9
- - go test ./...
9
+ - go test -race -cpu=5 -v ./...
10
+ - cd random && go build
11
12
env: TEST_VERBOSE=1
Godeps/_workspace/src/github.com/jbenet/go-reuseport/poll/poll_bsd.go
+1
-1
@@ -1,4 +1,4 @@
1
-// +build darwin,amd64 freebsd dragonfly netbsd openbsd
1
+// +build darwin,amd64 darwin,arm64 freebsd dragonfly netbsd openbsd
2
3
package poll
4
Godeps/_workspace/src/github.com/jbenet/go-temp-err-catcher/.travis.yml
+1
-1
@@ -6,4 +6,4 @@ go:
6
- tip
7
8
script:
9
- - go test -v
9
+ - go test -race -cpu=5 -v ./...
Godeps/_workspace/src/github.com/jbenet/go-temp-err-catcher/LICENSE
new
+21
@@ -0,0 +1,21 @@
1
+The MIT License (MIT)
2
+
3
+Copyright (c) 2014 Juan Batiz-Benet
4
+
5
+Permission is hereby granted, free of charge, to any person obtaining a copy
6
+of this software and associated documentation files (the "Software"), to deal
7
+in the Software without restriction, including without limitation the rights
8
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+copies of the Software, and to permit persons to whom the Software is
10
+furnished to do so, subject to the following conditions:
11
+
12
+The above copyright notice and this permission notice shall be included in
13
+all copies or substantial portions of the Software.
14
+
15
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+THE SOFTWARE.
Godeps/_workspace/src/github.com/jbenet/go-temp-err-catcher/tec_test.go
+2
-2
@@ -76,7 +76,7 @@ func TestDoubles(t *testing.T) {
76
77
testDiff := func(low, hi time.Duration) {
78
d := diff()
79
- grace := time.Duration(time.Microsecond)
79
+ grace := time.Duration(50 * time.Microsecond)
80
if (d + grace) < low {
81
t.Error("time difference is smaller than", low, d)
82
}
@@ -106,7 +106,7 @@ func TestDifferentStart(t *testing.T) {
106
107
testDiff := func(low, hi time.Duration) {
108
d := diff()
109
- grace := time.Duration(time.Microsecond)
109
+ grace := time.Duration(50 * time.Microsecond)
110
if (d + grace) < low {
111
t.Error("time difference is smaller than", low, d)
112
}
Godeps/_workspace/src/github.com/kardianos/osext/osext_procfs.go
+4
-2
@@ -17,12 +17,14 @@ import (
17
func executable() (string, error) {
18
switch runtime.GOOS {
19
case "linux":
20
- const deletedSuffix = " (deleted)"
20
+ const deletedTag = " (deleted)"
21
execpath, err := os.Readlink("/proc/self/exe")
22
if err != nil {
23
return execpath, err
24
}
25
- return strings.TrimSuffix(execpath, deletedSuffix), nil
25
+ execpath = strings.TrimSuffix(execpath, deletedTag)
26
+ execpath = strings.TrimPrefix(execpath, deletedTag)
27
+ return execpath, nil
28
case "netbsd":
29
return os.Readlink("/proc/curproc/exe")
30
case "openbsd", "dragonfly":
Godeps/_workspace/src/github.com/miekg/dns/README.md
+1
@@ -36,6 +36,7 @@ A not-so-up-to-date-list-that-may-be-actually-current:
36
* https://github.com/duedil-ltd/discodns
37
* https://github.com/StalkR/dns-reverse-proxy
38
* https://github.com/tianon/rawdns
39
+* https://mesosphere.github.io/mesos-dns/
40
41
Send pull request if you want to be listed here.
42
Godeps/_workspace/src/github.com/mitchellh/go-homedir/homedir.go
+2
-1
@@ -5,6 +5,7 @@ import (
5
"errors"
6
"os"
7
"os/exec"
8
+ "path/filepath"
9
"runtime"
10
"strings"
11
)
@@ -43,7 +44,7 @@ func Expand(path string) (string, error) {
44
return "", err
45
}
46
46
- return dir + path[1:], nil
47
+ return filepath.Join(dir, path[1:]), nil
48
}
49
50
func dirUnix() (string, error) {
Godeps/_workspace/src/github.com/mitchellh/go-homedir/homedir_test.go
+22
-1
@@ -2,10 +2,21 @@ package homedir
2
3
import (
4
"fmt"
5
+ "os"
6
"os/user"
7
"testing"
8
)
9
10
+func patchEnv(key, value string) func() {
11
+ bck := os.Getenv(key)
12
+ deferFunc := func() {
13
+ os.Setenv(key, bck)
14
+ }
15
+
16
+ os.Setenv(key, value)
17
+ return deferFunc
18
+}
19
+
20
func TestDir(t *testing.T) {
21
u, err := user.Current()
22
if err != nil {
@@ -44,7 +55,7 @@ func TestExpand(t *testing.T) {
55
fmt.Sprintf("%s/foo", u.HomeDir),
56
false,
57
},
47
-
58
+
59
{
60
"",
61
"",
@@ -74,4 +85,14 @@ func TestExpand(t *testing.T) {
85
t.Fatalf("Input: %#v\n\nOutput: %#v", tc.Input, actual)
86
}
87
}
88
+
89
+ defer patchEnv("HOME", "/custom/path/")()
90
+ expected := "/custom/path/foo/bar"
91
+ actual, err := Expand("~/foo/bar")
92
+
93
+ if err != nil {
94
+ t.Errorf("No error is expected, got: %v", err)
95
+ } else if actual != "/custom/path/foo/bar" {
96
+ t.Errorf("Expected: %v; actual: %v", expected, actual)
97
+ }
98
}
Godeps/_workspace/src/github.com/steakknife/hamming/README.md
+1
-1
@@ -37,7 +37,7 @@ See help in the [docs](https://godoc.org/github.com/steakknife/hamming)
37
38
- [Issues](https://github.com/steakknife/hamming/issues)
39
40
-## License
40
+## License
41
42
[MIT license](MIT-LICENSE.txt)
43
Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/db.go
+2
-1
@@ -27,7 +27,8 @@ import (
27
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/util"
28
)
29
30
-type DB struct { // DB is a LevelDB database.
30
+type DB struct // DB is a LevelDB database.
31
+{
32
// Need 64-bit alignment.
33
seq uint64
34
Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/db_iter.go
+23
-5
@@ -8,6 +8,7 @@ package leveldb
8
9
import (
10
"errors"
11
+ "math/rand"
12
"runtime"
13
"sync"
14
"sync/atomic"
@@ -80,6 +81,10 @@ func (db *DB) newIterator(seq uint64, slice *util.Range, ro *opt.ReadOptions) *d
81
return iter
82
}
83
84
+func (db *DB) iterSamplingRate() int {
85
+ return rand.Intn(2 * db.s.o.GetIteratorSamplingRate())
86
+}
87
+
88
type dir int
89
90
const (
@@ -98,11 +103,21 @@ type dbIter struct {
103
seq uint64
104
strict bool
105
101
- dir dir
102
- key []byte
103
- value []byte
104
- err error
105
- releaser util.Releaser
106
+ smaplingGap int
107
+ dir dir
108
+ key []byte
109
+ value []byte
110
+ err error
111
+ releaser util.Releaser
112
+}
113
+
114
+func (i *dbIter) sampleSeek() {
115
+ ikey := i.iter.Key()
116
+ i.smaplingGap -= len(ikey) + len(i.iter.Value())
117
+ for i.smaplingGap < 0 {
118
+ i.smaplingGap += i.db.iterSamplingRate()
119
+ i.db.sampleSeek(ikey)
120
+ }
121
}
122
123
func (i *dbIter) setErr(err error) {
@@ -175,6 +190,7 @@ func (i *dbIter) Seek(key []byte) bool {
190
func (i *dbIter) next() bool {
191
for {
192
if ukey, seq, kt, kerr := parseIkey(i.iter.Key()); kerr == nil {
193
+ i.sampleSeek()
194
if seq <= i.seq {
195
switch kt {
196
case ktDel:
@@ -225,6 +241,7 @@ func (i *dbIter) prev() bool {
241
if i.iter.Valid() {
242
for {
243
if ukey, seq, kt, kerr := parseIkey(i.iter.Key()); kerr == nil {
244
+ i.sampleSeek()
245
if seq <= i.seq {
246
if !del && i.icmp.uCompare(ukey, i.key) < 0 {
247
return true
@@ -266,6 +283,7 @@ func (i *dbIter) Prev() bool {
283
case dirForward:
284
for i.iter.Prev() {
285
if ukey, _, _, kerr := parseIkey(i.iter.Key()); kerr == nil {
286
+ i.sampleSeek()
287
if i.icmp.uCompare(ukey, i.key) < 0 {
288
goto cont
289
}
Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/db_state.go
+9
@@ -48,6 +48,15 @@ func (db *DB) addSeq(delta uint64) {
48
atomic.AddUint64(&db.seq, delta)
49
}
50
51
+func (db *DB) sampleSeek(ikey iKey) {
52
+ v := db.s.version()
53
+ if v.sampleSeek(ikey) {
54
+ // Trigger table compaction.
55
+ db.compSendTrigger(db.tcompCmdC)
56
+ }
57
+ v.release()
58
+}
59
+
60
func (db *DB) mpoolPut(mem *memdb.DB) {
61
defer func() {
62
recover()
Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/db_test.go
+95
-9
@@ -405,19 +405,21 @@ func (h *dbHarness) compactRange(min, max string) {
405
t.Log("DB range compaction done")
406
}
407
408
-func (h *dbHarness) sizeAssert(start, limit string, low, hi uint64) {
409
- t := h.t
410
- db := h.db
411
-
412
- s, err := db.SizeOf([]util.Range{
408
+func (h *dbHarness) sizeOf(start, limit string) uint64 {
409
+ sz, err := h.db.SizeOf([]util.Range{
410
{[]byte(start), []byte(limit)},
411
})
412
if err != nil {
416
- t.Error("SizeOf: got error: ", err)
413
+ h.t.Error("SizeOf: got error: ", err)
414
}
418
- if s.Sum() < low || s.Sum() > hi {
419
- t.Errorf("sizeof %q to %q not in range, want %d - %d, got %d",
420
- shorten(start), shorten(limit), low, hi, s.Sum())
415
+ return sz.Sum()
416
+}
417
+
418
+func (h *dbHarness) sizeAssert(start, limit string, low, hi uint64) {
419
+ sz := h.sizeOf(start, limit)
420
+ if sz < low || sz > hi {
421
+ h.t.Errorf("sizeOf %q to %q not in range, want %d - %d, got %d",
422
+ shorten(start), shorten(limit), low, hi, sz)
423
}
424
}
425
@@ -2577,3 +2579,87 @@ func TestDB_TableCompactionBuilder(t *testing.T) {
2579
}
2580
v.release()
2581
}
2582
+
2583
+func testDB_IterTriggeredCompaction(t *testing.T, limitDiv int) {
2584
+ const (
2585
+ vSize = 200 * opt.KiB
2586
+ tSize = 100 * opt.MiB
2587
+ mIter = 100
2588
+ n = tSize / vSize
2589
+ )
2590
+
2591
+ h := newDbHarnessWopt(t, &opt.Options{
2592
+ Compression: opt.NoCompression,
2593
+ DisableBlockCache: true,
2594
+ })
2595
+ defer h.close()
2596
+
2597
+ key := func(x int) string {
2598
+ return fmt.Sprintf("v%06d", x)
2599
+ }
2600
+
2601
+ // Fill.
2602
+ value := strings.Repeat("x", vSize)
2603
+ for i := 0; i < n; i++ {
2604
+ h.put(key(i), value)
2605
+ }
2606
+ h.compactMem()
2607
+
2608
+ // Delete all.
2609
+ for i := 0; i < n; i++ {
2610
+ h.delete(key(i))
2611
+ }
2612
+ h.compactMem()
2613
+
2614
+ var (
2615
+ limit = n / limitDiv
2616
+
2617
+ startKey = key(0)
2618
+ limitKey = key(limit)
2619
+ maxKey = key(n)
2620
+ slice = &util.Range{Limit: []byte(limitKey)}
2621
+
2622
+ initialSize0 = h.sizeOf(startKey, limitKey)
2623
+ initialSize1 = h.sizeOf(limitKey, maxKey)
2624
+ )
2625
+
2626
+ t.Logf("inital size %s [rest %s]", shortenb(int(initialSize0)), shortenb(int(initialSize1)))
2627
+
2628
+ for r := 0; true; r++ {
2629
+ if r >= mIter {
2630
+ t.Fatal("taking too long to compact")
2631
+ }
2632
+
2633
+ // Iterates.
2634
+ iter := h.db.NewIterator(slice, h.ro)
2635
+ for iter.Next() {
2636
+ }
2637
+ if err := iter.Error(); err != nil {
2638
+ t.Fatalf("Iter err: %v", err)
2639
+ }
2640
+ iter.Release()
2641
+
2642
+ // Wait compaction.
2643
+ h.waitCompaction()
2644
+
2645
+ // Check size.
2646
+ size0 := h.sizeOf(startKey, limitKey)
2647
+ size1 := h.sizeOf(limitKey, maxKey)
2648
+ t.Logf("#%03d size %s [rest %s]", r, shortenb(int(size0)), shortenb(int(size1)))
2649
+ if size0 < initialSize0/10 {
2650
+ break
2651
+ }
2652
+ }
2653
+
2654
+ if initialSize1 > 0 {
2655
+ h.sizeAssert(limitKey, maxKey, initialSize1/4-opt.MiB, initialSize1+opt.MiB)
2656
+ }
2657
+}
2658
+
2659
+func TestDB_IterTriggeredCompaction(t *testing.T) {
2660
+ testDB_IterTriggeredCompaction(t, 1)
2661
+}
2662
+
2663
+func TestDB_IterTriggeredCompactionHalf(t *testing.T) {
2664
+ testDB_IterTriggeredCompaction(t, 2)
2665
+}
Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/opt/options.go
+17
-2
@@ -34,10 +34,11 @@ var (
34
DefaultCompactionTotalSize = 10 * MiB
35
DefaultCompactionTotalSizeMultiplier = 10.0
36
DefaultCompressionType = SnappyCompression
37
- DefaultOpenFilesCacher = LRUCacher
38
- DefaultOpenFilesCacheCapacity = 500
37
+ DefaultIteratorSamplingRate = 1 * MiB
38
DefaultMaxMemCompationLevel = 2
39
DefaultNumLevel = 7
40
+ DefaultOpenFilesCacher = LRUCacher
41
+ DefaultOpenFilesCacheCapacity = 500
42
DefaultWriteBuffer = 4 * MiB
43
DefaultWriteL0PauseTrigger = 12
44
DefaultWriteL0SlowdownTrigger = 8
@@ -288,6 +289,13 @@ type Options struct {
289
// The default value is nil.
290
Filter filter.Filter
291
292
+ // IteratorSamplingRate defines approximate gap (in bytes) between read
293
+ // sampling of an iterator. The samples will be used to determine when
294
+ // compaction should be triggered.
295
+ //
296
+ // The default is 1MiB.
297
+ IteratorSamplingRate int
298
+
299
// MaxMemCompationLevel defines maximum level a newly compacted 'memdb'
300
// will be pushed into if doesn't creates overlap. This should less than
301
// NumLevel. Use -1 for level-0.
@@ -492,6 +500,13 @@ func (o *Options) GetFilter() filter.Filter {
500
return o.Filter
501
}
502
503
+func (o *Options) GetIteratorSamplingRate() int {
504
+ if o == nil || o.IteratorSamplingRate <= 0 {
505
+ return DefaultIteratorSamplingRate
506
+ }
507
+ return o.IteratorSamplingRate
508
+}
509
+
510
func (o *Options) GetMaxMemCompationLevel() int {
511
level := DefaultMaxMemCompationLevel
512
if o != nil {
Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/version.go
+23
-2
@@ -136,9 +136,8 @@ func (v *version) get(ikey iKey, ro *opt.ReadOptions, noValue bool) (value []byt
136
if !tseek {
137
if tset == nil {
138
tset = &tSet{level, t}
139
- } else if tset.table.consumeSeek() <= 0 {
139
+ } else {
140
tseek = true
141
- tcomp = atomic.CompareAndSwapPointer(&v.cSeek, nil, unsafe.Pointer(tset))
141
}
142
}
143
@@ -203,6 +202,28 @@ func (v *version) get(ikey iKey, ro *opt.ReadOptions, noValue bool) (value []byt
202
return true
203
})
204
205
+ if tseek && tset.table.consumeSeek() <= 0 {
206
+ tcomp = atomic.CompareAndSwapPointer(&v.cSeek, nil, unsafe.Pointer(tset))
207
+ }
208
+
209
+ return
210
+}
211
+
212
+func (v *version) sampleSeek(ikey iKey) (tcomp bool) {
213
+ var tset *tSet
214
+
215
+ v.walkOverlapping(ikey, func(level int, t *tFile) bool {
216
+ if tset == nil {
217
+ tset = &tSet{level, t}
218
+ return true
219
+ } else {
220
+ if tset.table.consumeSeek() <= 0 {
221
+ tcomp = atomic.CompareAndSwapPointer(&v.cSeek, nil, unsafe.Pointer(tset))
222
+ }
223
+ return false
224
+ }
225
+ }, nil)
226
+
227
return
228
}
229
Godeps/_workspace/src/github.com/whyrusleeping/go-metrics/opentsdb_test.go
+1
@@ -19,3 +19,4 @@ func ExampleOpenTSDBWithConfig() {
19
DurationUnit: time.Millisecond,
20
})
21
}
22
+
Godeps/_workspace/src/github.com/whyrusleeping/iptb/README.md
+4
@@ -26,6 +26,10 @@ easy!
26
- IPFS_PATH - set to testbed node n's IPFS_PATH
27
- NODE[x] - set to the peer ID of node x
28
29
+- get [attr] [n]
30
+ - gets the specified attribute from then given node
31
+ - available attributes: id
32
+
33
### Configuration
34
By default, iptb uses `$HOME/testbed` to store created nodes. This path is
35
configurable via the environment variables `IPTB_ROOT`.
Godeps/_workspace/src/golang.org/x/crypto/sha3/sha3_test.go
+1
-1
@@ -159,7 +159,7 @@ func TestAppend(t *testing.T) {
159
testUnalignedAndGeneric(t, func(impl string) {
160
d := New224()
161
162
- for capacity := 2; capacity < 64; capacity += 64 {
162
+ for capacity := 2; capacity <= 66; capacity += 64 {
163
// The first time around the loop, Sum will have to reallocate.
164
// The second time, it will not.
165
buf := make([]byte, 2, capacity)