mirror of
https://github.com/mochi-mqtt/server.git
synced 2025-10-07 00:53:01 +08:00
Update go mod to ensure bolt is using 1.3.5
Bolt 1.3.6 fails to build correctly and has been removed, so rollback to bolt 1.3.5. Also upgrade to Go 1.18
This commit is contained in:
12
go.mod
12
go.mod
@@ -1,16 +1,16 @@
|
|||||||
module github.com/mochi-co/mqtt
|
module github.com/mochi-co/mqtt
|
||||||
|
|
||||||
go 1.17
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/asdine/storm v2.1.2+incompatible
|
github.com/asdine/storm v2.1.2+incompatible
|
||||||
github.com/asdine/storm/v3 v3.2.1
|
github.com/asdine/storm/v3 v3.2.1
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.5.0
|
||||||
github.com/jinzhu/copier v0.3.4
|
github.com/jinzhu/copier v0.3.5
|
||||||
github.com/logrusorgru/aurora v2.0.3+incompatible
|
github.com/logrusorgru/aurora v2.0.3+incompatible
|
||||||
github.com/rs/xid v1.3.0
|
github.com/rs/xid v1.4.0
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.7.1
|
||||||
go.etcd.io/bbolt v1.3.6
|
go.etcd.io/bbolt v1.3.5
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
20
go.sum
20
go.sum
@@ -14,10 +14,10 @@ github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs
|
|||||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
|
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
|
||||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/jinzhu/copier v0.3.4 h1:mfU6jI9PtCeUjkjQ322dlff9ELjGDu975C2p/nrubVI=
|
github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg=
|
||||||
github.com/jinzhu/copier v0.3.4/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
|
github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
@@ -27,17 +27,17 @@ github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczG
|
|||||||
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/rs/xid v1.3.0 h1:6NjYksEUlhurdVehpc7S7dk6DAmcKv8V9gG0FsVN2U4=
|
github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY=
|
||||||
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
|
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
|
||||||
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
|
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
|
||||||
go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
||||||
go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU=
|
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
|
||||||
go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4=
|
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||||
golang.org/x/net v0.0.0-20191105084925-a882066a44e0 h1:QPlSTtPE2k6PZPasQUbzuK3p9JbS+vMXYVto8g/yrsg=
|
golang.org/x/net v0.0.0-20191105084925-a882066a44e0 h1:QPlSTtPE2k6PZPasQUbzuK3p9JbS+vMXYVto8g/yrsg=
|
||||||
|
39
vendor/github.com/gorilla/websocket/README.md
generated
vendored
39
vendor/github.com/gorilla/websocket/README.md
generated
vendored
@@ -6,6 +6,13 @@
|
|||||||
Gorilla WebSocket is a [Go](http://golang.org/) implementation of the
|
Gorilla WebSocket is a [Go](http://golang.org/) implementation of the
|
||||||
[WebSocket](http://www.rfc-editor.org/rfc/rfc6455.txt) protocol.
|
[WebSocket](http://www.rfc-editor.org/rfc/rfc6455.txt) protocol.
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
⚠️ **[The Gorilla WebSocket Package is looking for a new maintainer](https://github.com/gorilla/websocket/issues/370)**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
|
|
||||||
* [API Reference](https://pkg.go.dev/github.com/gorilla/websocket?tab=doc)
|
* [API Reference](https://pkg.go.dev/github.com/gorilla/websocket?tab=doc)
|
||||||
@@ -30,35 +37,3 @@ The Gorilla WebSocket package passes the server tests in the [Autobahn Test
|
|||||||
Suite](https://github.com/crossbario/autobahn-testsuite) using the application in the [examples/autobahn
|
Suite](https://github.com/crossbario/autobahn-testsuite) using the application in the [examples/autobahn
|
||||||
subdirectory](https://github.com/gorilla/websocket/tree/master/examples/autobahn).
|
subdirectory](https://github.com/gorilla/websocket/tree/master/examples/autobahn).
|
||||||
|
|
||||||
### Gorilla WebSocket compared with other packages
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<tr>
|
|
||||||
<th></th>
|
|
||||||
<th><a href="http://godoc.org/github.com/gorilla/websocket">github.com/gorilla</a></th>
|
|
||||||
<th><a href="http://godoc.org/golang.org/x/net/websocket">golang.org/x/net</a></th>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<tr><td colspan="3"><a href="http://tools.ietf.org/html/rfc6455">RFC 6455</a> Features</td></tr>
|
|
||||||
<tr><td>Passes <a href="https://github.com/crossbario/autobahn-testsuite">Autobahn Test Suite</a></td><td><a href="https://github.com/gorilla/websocket/tree/master/examples/autobahn">Yes</a></td><td>No</td></tr>
|
|
||||||
<tr><td>Receive <a href="https://tools.ietf.org/html/rfc6455#section-5.4">fragmented</a> message<td>Yes</td><td><a href="https://code.google.com/p/go/issues/detail?id=7632">No</a>, see note 1</td></tr>
|
|
||||||
<tr><td>Send <a href="https://tools.ietf.org/html/rfc6455#section-5.5.1">close</a> message</td><td><a href="http://godoc.org/github.com/gorilla/websocket#hdr-Control_Messages">Yes</a></td><td><a href="https://code.google.com/p/go/issues/detail?id=4588">No</a></td></tr>
|
|
||||||
<tr><td>Send <a href="https://tools.ietf.org/html/rfc6455#section-5.5.2">pings</a> and receive <a href="https://tools.ietf.org/html/rfc6455#section-5.5.3">pongs</a></td><td><a href="http://godoc.org/github.com/gorilla/websocket#hdr-Control_Messages">Yes</a></td><td>No</td></tr>
|
|
||||||
<tr><td>Get the <a href="https://tools.ietf.org/html/rfc6455#section-5.6">type</a> of a received data message</td><td>Yes</td><td>Yes, see note 2</td></tr>
|
|
||||||
<tr><td colspan="3">Other Features</tr></td>
|
|
||||||
<tr><td><a href="https://tools.ietf.org/html/rfc7692">Compression Extensions</a></td><td>Experimental</td><td>No</td></tr>
|
|
||||||
<tr><td>Read message using io.Reader</td><td><a href="http://godoc.org/github.com/gorilla/websocket#Conn.NextReader">Yes</a></td><td>No, see note 3</td></tr>
|
|
||||||
<tr><td>Write message using io.WriteCloser</td><td><a href="http://godoc.org/github.com/gorilla/websocket#Conn.NextWriter">Yes</a></td><td>No, see note 3</td></tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
Notes:
|
|
||||||
|
|
||||||
1. Large messages are fragmented in [Chrome's new WebSocket implementation](http://www.ietf.org/mail-archive/web/hybi/current/msg10503.html).
|
|
||||||
2. The application can get the type of a received data message by implementing
|
|
||||||
a [Codec marshal](http://godoc.org/golang.org/x/net/websocket#Codec.Marshal)
|
|
||||||
function.
|
|
||||||
3. The go.net io.Reader and io.Writer operate across WebSocket frame boundaries.
|
|
||||||
Read returns when the input buffer is full or a frame boundary is
|
|
||||||
encountered. Each call to Write sends a single frame message. The Gorilla
|
|
||||||
io.Reader and io.WriteCloser operate on a single WebSocket message.
|
|
||||||
|
|
||||||
|
77
vendor/github.com/gorilla/websocket/client.go
generated
vendored
77
vendor/github.com/gorilla/websocket/client.go
generated
vendored
@@ -48,15 +48,23 @@ func NewClient(netConn net.Conn, u *url.URL, requestHeader http.Header, readBufS
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A Dialer contains options for connecting to WebSocket server.
|
// A Dialer contains options for connecting to WebSocket server.
|
||||||
|
//
|
||||||
|
// It is safe to call Dialer's methods concurrently.
|
||||||
type Dialer struct {
|
type Dialer struct {
|
||||||
// NetDial specifies the dial function for creating TCP connections. If
|
// NetDial specifies the dial function for creating TCP connections. If
|
||||||
// NetDial is nil, net.Dial is used.
|
// NetDial is nil, net.Dial is used.
|
||||||
NetDial func(network, addr string) (net.Conn, error)
|
NetDial func(network, addr string) (net.Conn, error)
|
||||||
|
|
||||||
// NetDialContext specifies the dial function for creating TCP connections. If
|
// NetDialContext specifies the dial function for creating TCP connections. If
|
||||||
// NetDialContext is nil, net.DialContext is used.
|
// NetDialContext is nil, NetDial is used.
|
||||||
NetDialContext func(ctx context.Context, network, addr string) (net.Conn, error)
|
NetDialContext func(ctx context.Context, network, addr string) (net.Conn, error)
|
||||||
|
|
||||||
|
// NetDialTLSContext specifies the dial function for creating TLS/TCP connections. If
|
||||||
|
// NetDialTLSContext is nil, NetDialContext is used.
|
||||||
|
// If NetDialTLSContext is set, Dial assumes the TLS handshake is done there and
|
||||||
|
// TLSClientConfig is ignored.
|
||||||
|
NetDialTLSContext func(ctx context.Context, network, addr string) (net.Conn, error)
|
||||||
|
|
||||||
// Proxy specifies a function to return a proxy for a given
|
// Proxy specifies a function to return a proxy for a given
|
||||||
// Request. If the function returns a non-nil error, the
|
// Request. If the function returns a non-nil error, the
|
||||||
// request is aborted with the provided error.
|
// request is aborted with the provided error.
|
||||||
@@ -65,6 +73,8 @@ type Dialer struct {
|
|||||||
|
|
||||||
// TLSClientConfig specifies the TLS configuration to use with tls.Client.
|
// TLSClientConfig specifies the TLS configuration to use with tls.Client.
|
||||||
// If nil, the default configuration is used.
|
// If nil, the default configuration is used.
|
||||||
|
// If either NetDialTLS or NetDialTLSContext are set, Dial assumes the TLS handshake
|
||||||
|
// is done there and TLSClientConfig is ignored.
|
||||||
TLSClientConfig *tls.Config
|
TLSClientConfig *tls.Config
|
||||||
|
|
||||||
// HandshakeTimeout specifies the duration for the handshake to complete.
|
// HandshakeTimeout specifies the duration for the handshake to complete.
|
||||||
@@ -176,7 +186,7 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
|
|||||||
}
|
}
|
||||||
|
|
||||||
req := &http.Request{
|
req := &http.Request{
|
||||||
Method: "GET",
|
Method: http.MethodGet,
|
||||||
URL: u,
|
URL: u,
|
||||||
Proto: "HTTP/1.1",
|
Proto: "HTTP/1.1",
|
||||||
ProtoMajor: 1,
|
ProtoMajor: 1,
|
||||||
@@ -237,13 +247,32 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
|
|||||||
// Get network dial function.
|
// Get network dial function.
|
||||||
var netDial func(network, add string) (net.Conn, error)
|
var netDial func(network, add string) (net.Conn, error)
|
||||||
|
|
||||||
if d.NetDialContext != nil {
|
switch u.Scheme {
|
||||||
netDial = func(network, addr string) (net.Conn, error) {
|
case "http":
|
||||||
return d.NetDialContext(ctx, network, addr)
|
if d.NetDialContext != nil {
|
||||||
|
netDial = func(network, addr string) (net.Conn, error) {
|
||||||
|
return d.NetDialContext(ctx, network, addr)
|
||||||
|
}
|
||||||
|
} else if d.NetDial != nil {
|
||||||
|
netDial = d.NetDial
|
||||||
}
|
}
|
||||||
} else if d.NetDial != nil {
|
case "https":
|
||||||
netDial = d.NetDial
|
if d.NetDialTLSContext != nil {
|
||||||
} else {
|
netDial = func(network, addr string) (net.Conn, error) {
|
||||||
|
return d.NetDialTLSContext(ctx, network, addr)
|
||||||
|
}
|
||||||
|
} else if d.NetDialContext != nil {
|
||||||
|
netDial = func(network, addr string) (net.Conn, error) {
|
||||||
|
return d.NetDialContext(ctx, network, addr)
|
||||||
|
}
|
||||||
|
} else if d.NetDial != nil {
|
||||||
|
netDial = d.NetDial
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return nil, nil, errMalformedURL
|
||||||
|
}
|
||||||
|
|
||||||
|
if netDial == nil {
|
||||||
netDialer := &net.Dialer{}
|
netDialer := &net.Dialer{}
|
||||||
netDial = func(network, addr string) (net.Conn, error) {
|
netDial = func(network, addr string) (net.Conn, error) {
|
||||||
return netDialer.DialContext(ctx, network, addr)
|
return netDialer.DialContext(ctx, network, addr)
|
||||||
@@ -304,7 +333,9 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if u.Scheme == "https" {
|
if u.Scheme == "https" && d.NetDialTLSContext == nil {
|
||||||
|
// If NetDialTLSContext is set, assume that the TLS handshake has already been done
|
||||||
|
|
||||||
cfg := cloneTLSConfig(d.TLSClientConfig)
|
cfg := cloneTLSConfig(d.TLSClientConfig)
|
||||||
if cfg.ServerName == "" {
|
if cfg.ServerName == "" {
|
||||||
cfg.ServerName = hostNoPort
|
cfg.ServerName = hostNoPort
|
||||||
@@ -312,11 +343,12 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
|
|||||||
tlsConn := tls.Client(netConn, cfg)
|
tlsConn := tls.Client(netConn, cfg)
|
||||||
netConn = tlsConn
|
netConn = tlsConn
|
||||||
|
|
||||||
var err error
|
if trace != nil && trace.TLSHandshakeStart != nil {
|
||||||
if trace != nil {
|
trace.TLSHandshakeStart()
|
||||||
err = doHandshakeWithTrace(trace, tlsConn, cfg)
|
}
|
||||||
} else {
|
err := doHandshake(ctx, tlsConn, cfg)
|
||||||
err = doHandshake(tlsConn, cfg)
|
if trace != nil && trace.TLSHandshakeDone != nil {
|
||||||
|
trace.TLSHandshakeDone(tlsConn.ConnectionState(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -348,8 +380,8 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
|
|||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode != 101 ||
|
if resp.StatusCode != 101 ||
|
||||||
!strings.EqualFold(resp.Header.Get("Upgrade"), "websocket") ||
|
!tokenListContainsValue(resp.Header, "Upgrade", "websocket") ||
|
||||||
!strings.EqualFold(resp.Header.Get("Connection"), "upgrade") ||
|
!tokenListContainsValue(resp.Header, "Connection", "upgrade") ||
|
||||||
resp.Header.Get("Sec-Websocket-Accept") != computeAcceptKey(challengeKey) {
|
resp.Header.Get("Sec-Websocket-Accept") != computeAcceptKey(challengeKey) {
|
||||||
// Before closing the network connection on return from this
|
// Before closing the network connection on return from this
|
||||||
// function, slurp up some of the response to aid application
|
// function, slurp up some of the response to aid application
|
||||||
@@ -382,14 +414,9 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
|
|||||||
return conn, resp, nil
|
return conn, resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func doHandshake(tlsConn *tls.Conn, cfg *tls.Config) error {
|
func cloneTLSConfig(cfg *tls.Config) *tls.Config {
|
||||||
if err := tlsConn.Handshake(); err != nil {
|
if cfg == nil {
|
||||||
return err
|
return &tls.Config{}
|
||||||
}
|
}
|
||||||
if !cfg.InsecureSkipVerify {
|
return cfg.Clone()
|
||||||
if err := tlsConn.VerifyHostname(cfg.ServerName); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
16
vendor/github.com/gorilla/websocket/client_clone.go
generated
vendored
16
vendor/github.com/gorilla/websocket/client_clone.go
generated
vendored
@@ -1,16 +0,0 @@
|
|||||||
// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build go1.8
|
|
||||||
|
|
||||||
package websocket
|
|
||||||
|
|
||||||
import "crypto/tls"
|
|
||||||
|
|
||||||
func cloneTLSConfig(cfg *tls.Config) *tls.Config {
|
|
||||||
if cfg == nil {
|
|
||||||
return &tls.Config{}
|
|
||||||
}
|
|
||||||
return cfg.Clone()
|
|
||||||
}
|
|
38
vendor/github.com/gorilla/websocket/client_clone_legacy.go
generated
vendored
38
vendor/github.com/gorilla/websocket/client_clone_legacy.go
generated
vendored
@@ -1,38 +0,0 @@
|
|||||||
// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build !go1.8
|
|
||||||
|
|
||||||
package websocket
|
|
||||||
|
|
||||||
import "crypto/tls"
|
|
||||||
|
|
||||||
// cloneTLSConfig clones all public fields except the fields
|
|
||||||
// SessionTicketsDisabled and SessionTicketKey. This avoids copying the
|
|
||||||
// sync.Mutex in the sync.Once and makes it safe to call cloneTLSConfig on a
|
|
||||||
// config in active use.
|
|
||||||
func cloneTLSConfig(cfg *tls.Config) *tls.Config {
|
|
||||||
if cfg == nil {
|
|
||||||
return &tls.Config{}
|
|
||||||
}
|
|
||||||
return &tls.Config{
|
|
||||||
Rand: cfg.Rand,
|
|
||||||
Time: cfg.Time,
|
|
||||||
Certificates: cfg.Certificates,
|
|
||||||
NameToCertificate: cfg.NameToCertificate,
|
|
||||||
GetCertificate: cfg.GetCertificate,
|
|
||||||
RootCAs: cfg.RootCAs,
|
|
||||||
NextProtos: cfg.NextProtos,
|
|
||||||
ServerName: cfg.ServerName,
|
|
||||||
ClientAuth: cfg.ClientAuth,
|
|
||||||
ClientCAs: cfg.ClientCAs,
|
|
||||||
InsecureSkipVerify: cfg.InsecureSkipVerify,
|
|
||||||
CipherSuites: cfg.CipherSuites,
|
|
||||||
PreferServerCipherSuites: cfg.PreferServerCipherSuites,
|
|
||||||
ClientSessionCache: cfg.ClientSessionCache,
|
|
||||||
MinVersion: cfg.MinVersion,
|
|
||||||
MaxVersion: cfg.MaxVersion,
|
|
||||||
CurvePreferences: cfg.CurvePreferences,
|
|
||||||
}
|
|
||||||
}
|
|
63
vendor/github.com/gorilla/websocket/conn.go
generated
vendored
63
vendor/github.com/gorilla/websocket/conn.go
generated
vendored
@@ -13,6 +13,7 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
@@ -401,6 +402,12 @@ func (c *Conn) write(frameType int, deadline time.Time, buf0, buf1 []byte) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Conn) writeBufs(bufs ...[]byte) error {
|
||||||
|
b := net.Buffers(bufs)
|
||||||
|
_, err := b.WriteTo(c.conn)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// WriteControl writes a control message with the given deadline. The allowed
|
// WriteControl writes a control message with the given deadline. The allowed
|
||||||
// message types are CloseMessage, PingMessage and PongMessage.
|
// message types are CloseMessage, PingMessage and PongMessage.
|
||||||
func (c *Conn) WriteControl(messageType int, data []byte, deadline time.Time) error {
|
func (c *Conn) WriteControl(messageType int, data []byte, deadline time.Time) error {
|
||||||
@@ -794,47 +801,69 @@ func (c *Conn) advanceFrame() (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. Read and parse first two bytes of frame header.
|
// 2. Read and parse first two bytes of frame header.
|
||||||
|
// To aid debugging, collect and report all errors in the first two bytes
|
||||||
|
// of the header.
|
||||||
|
|
||||||
|
var errors []string
|
||||||
|
|
||||||
p, err := c.read(2)
|
p, err := c.read(2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return noFrame, err
|
return noFrame, err
|
||||||
}
|
}
|
||||||
|
|
||||||
final := p[0]&finalBit != 0
|
|
||||||
frameType := int(p[0] & 0xf)
|
frameType := int(p[0] & 0xf)
|
||||||
|
final := p[0]&finalBit != 0
|
||||||
|
rsv1 := p[0]&rsv1Bit != 0
|
||||||
|
rsv2 := p[0]&rsv2Bit != 0
|
||||||
|
rsv3 := p[0]&rsv3Bit != 0
|
||||||
mask := p[1]&maskBit != 0
|
mask := p[1]&maskBit != 0
|
||||||
c.setReadRemaining(int64(p[1] & 0x7f))
|
c.setReadRemaining(int64(p[1] & 0x7f))
|
||||||
|
|
||||||
c.readDecompress = false
|
c.readDecompress = false
|
||||||
if c.newDecompressionReader != nil && (p[0]&rsv1Bit) != 0 {
|
if rsv1 {
|
||||||
c.readDecompress = true
|
if c.newDecompressionReader != nil {
|
||||||
p[0] &^= rsv1Bit
|
c.readDecompress = true
|
||||||
|
} else {
|
||||||
|
errors = append(errors, "RSV1 set")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if rsv := p[0] & (rsv1Bit | rsv2Bit | rsv3Bit); rsv != 0 {
|
if rsv2 {
|
||||||
return noFrame, c.handleProtocolError("unexpected reserved bits 0x" + strconv.FormatInt(int64(rsv), 16))
|
errors = append(errors, "RSV2 set")
|
||||||
|
}
|
||||||
|
|
||||||
|
if rsv3 {
|
||||||
|
errors = append(errors, "RSV3 set")
|
||||||
}
|
}
|
||||||
|
|
||||||
switch frameType {
|
switch frameType {
|
||||||
case CloseMessage, PingMessage, PongMessage:
|
case CloseMessage, PingMessage, PongMessage:
|
||||||
if c.readRemaining > maxControlFramePayloadSize {
|
if c.readRemaining > maxControlFramePayloadSize {
|
||||||
return noFrame, c.handleProtocolError("control frame length > 125")
|
errors = append(errors, "len > 125 for control")
|
||||||
}
|
}
|
||||||
if !final {
|
if !final {
|
||||||
return noFrame, c.handleProtocolError("control frame not final")
|
errors = append(errors, "FIN not set on control")
|
||||||
}
|
}
|
||||||
case TextMessage, BinaryMessage:
|
case TextMessage, BinaryMessage:
|
||||||
if !c.readFinal {
|
if !c.readFinal {
|
||||||
return noFrame, c.handleProtocolError("message start before final message frame")
|
errors = append(errors, "data before FIN")
|
||||||
}
|
}
|
||||||
c.readFinal = final
|
c.readFinal = final
|
||||||
case continuationFrame:
|
case continuationFrame:
|
||||||
if c.readFinal {
|
if c.readFinal {
|
||||||
return noFrame, c.handleProtocolError("continuation after final message frame")
|
errors = append(errors, "continuation after FIN")
|
||||||
}
|
}
|
||||||
c.readFinal = final
|
c.readFinal = final
|
||||||
default:
|
default:
|
||||||
return noFrame, c.handleProtocolError("unknown opcode " + strconv.Itoa(frameType))
|
errors = append(errors, "bad opcode "+strconv.Itoa(frameType))
|
||||||
|
}
|
||||||
|
|
||||||
|
if mask != c.isServer {
|
||||||
|
errors = append(errors, "bad MASK")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(errors) > 0 {
|
||||||
|
return noFrame, c.handleProtocolError(strings.Join(errors, ", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Read and parse frame length as per
|
// 3. Read and parse frame length as per
|
||||||
@@ -872,10 +901,6 @@ func (c *Conn) advanceFrame() (int, error) {
|
|||||||
|
|
||||||
// 4. Handle frame masking.
|
// 4. Handle frame masking.
|
||||||
|
|
||||||
if mask != c.isServer {
|
|
||||||
return noFrame, c.handleProtocolError("incorrect mask flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
if mask {
|
if mask {
|
||||||
c.readMaskPos = 0
|
c.readMaskPos = 0
|
||||||
p, err := c.read(len(c.readMaskKey))
|
p, err := c.read(len(c.readMaskKey))
|
||||||
@@ -935,7 +960,7 @@ func (c *Conn) advanceFrame() (int, error) {
|
|||||||
if len(payload) >= 2 {
|
if len(payload) >= 2 {
|
||||||
closeCode = int(binary.BigEndian.Uint16(payload))
|
closeCode = int(binary.BigEndian.Uint16(payload))
|
||||||
if !isValidReceivedCloseCode(closeCode) {
|
if !isValidReceivedCloseCode(closeCode) {
|
||||||
return noFrame, c.handleProtocolError("invalid close code")
|
return noFrame, c.handleProtocolError("bad close code " + strconv.Itoa(closeCode))
|
||||||
}
|
}
|
||||||
closeText = string(payload[2:])
|
closeText = string(payload[2:])
|
||||||
if !utf8.ValidString(closeText) {
|
if !utf8.ValidString(closeText) {
|
||||||
@@ -952,7 +977,11 @@ func (c *Conn) advanceFrame() (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) handleProtocolError(message string) error {
|
func (c *Conn) handleProtocolError(message string) error {
|
||||||
c.WriteControl(CloseMessage, FormatCloseMessage(CloseProtocolError, message), time.Now().Add(writeWait))
|
data := FormatCloseMessage(CloseProtocolError, message)
|
||||||
|
if len(data) > maxControlFramePayloadSize {
|
||||||
|
data = data[:maxControlFramePayloadSize]
|
||||||
|
}
|
||||||
|
c.WriteControl(CloseMessage, data, time.Now().Add(writeWait))
|
||||||
return errors.New("websocket: " + message)
|
return errors.New("websocket: " + message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
vendor/github.com/gorilla/websocket/conn_write.go
generated
vendored
15
vendor/github.com/gorilla/websocket/conn_write.go
generated
vendored
@@ -1,15 +0,0 @@
|
|||||||
// Copyright 2016 The Gorilla WebSocket Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build go1.8
|
|
||||||
|
|
||||||
package websocket
|
|
||||||
|
|
||||||
import "net"
|
|
||||||
|
|
||||||
func (c *Conn) writeBufs(bufs ...[]byte) error {
|
|
||||||
b := net.Buffers(bufs)
|
|
||||||
_, err := b.WriteTo(c.conn)
|
|
||||||
return err
|
|
||||||
}
|
|
18
vendor/github.com/gorilla/websocket/conn_write_legacy.go
generated
vendored
18
vendor/github.com/gorilla/websocket/conn_write_legacy.go
generated
vendored
@@ -1,18 +0,0 @@
|
|||||||
// Copyright 2016 The Gorilla WebSocket Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build !go1.8
|
|
||||||
|
|
||||||
package websocket
|
|
||||||
|
|
||||||
func (c *Conn) writeBufs(bufs ...[]byte) error {
|
|
||||||
for _, buf := range bufs {
|
|
||||||
if len(buf) > 0 {
|
|
||||||
if _, err := c.conn.Write(buf); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
1
vendor/github.com/gorilla/websocket/mask.go
generated
vendored
1
vendor/github.com/gorilla/websocket/mask.go
generated
vendored
@@ -2,6 +2,7 @@
|
|||||||
// this source code is governed by a BSD-style license that can be found in the
|
// this source code is governed by a BSD-style license that can be found in the
|
||||||
// LICENSE file.
|
// LICENSE file.
|
||||||
|
|
||||||
|
//go:build !appengine
|
||||||
// +build !appengine
|
// +build !appengine
|
||||||
|
|
||||||
package websocket
|
package websocket
|
||||||
|
1
vendor/github.com/gorilla/websocket/mask_safe.go
generated
vendored
1
vendor/github.com/gorilla/websocket/mask_safe.go
generated
vendored
@@ -2,6 +2,7 @@
|
|||||||
// this source code is governed by a BSD-style license that can be found in the
|
// this source code is governed by a BSD-style license that can be found in the
|
||||||
// LICENSE file.
|
// LICENSE file.
|
||||||
|
|
||||||
|
//go:build appengine
|
||||||
// +build appengine
|
// +build appengine
|
||||||
|
|
||||||
package websocket
|
package websocket
|
||||||
|
2
vendor/github.com/gorilla/websocket/proxy.go
generated
vendored
2
vendor/github.com/gorilla/websocket/proxy.go
generated
vendored
@@ -48,7 +48,7 @@ func (hpd *httpProxyDialer) Dial(network string, addr string) (net.Conn, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
connectReq := &http.Request{
|
connectReq := &http.Request{
|
||||||
Method: "CONNECT",
|
Method: http.MethodConnect,
|
||||||
URL: &url.URL{Opaque: addr},
|
URL: &url.URL{Opaque: addr},
|
||||||
Host: addr,
|
Host: addr,
|
||||||
Header: connectHeader,
|
Header: connectHeader,
|
||||||
|
8
vendor/github.com/gorilla/websocket/server.go
generated
vendored
8
vendor/github.com/gorilla/websocket/server.go
generated
vendored
@@ -23,6 +23,8 @@ func (e HandshakeError) Error() string { return e.message }
|
|||||||
|
|
||||||
// Upgrader specifies parameters for upgrading an HTTP connection to a
|
// Upgrader specifies parameters for upgrading an HTTP connection to a
|
||||||
// WebSocket connection.
|
// WebSocket connection.
|
||||||
|
//
|
||||||
|
// It is safe to call Upgrader's methods concurrently.
|
||||||
type Upgrader struct {
|
type Upgrader struct {
|
||||||
// HandshakeTimeout specifies the duration for the handshake to complete.
|
// HandshakeTimeout specifies the duration for the handshake to complete.
|
||||||
HandshakeTimeout time.Duration
|
HandshakeTimeout time.Duration
|
||||||
@@ -115,8 +117,8 @@ func (u *Upgrader) selectSubprotocol(r *http.Request, responseHeader http.Header
|
|||||||
// Upgrade upgrades the HTTP server connection to the WebSocket protocol.
|
// Upgrade upgrades the HTTP server connection to the WebSocket protocol.
|
||||||
//
|
//
|
||||||
// The responseHeader is included in the response to the client's upgrade
|
// The responseHeader is included in the response to the client's upgrade
|
||||||
// request. Use the responseHeader to specify cookies (Set-Cookie) and the
|
// request. Use the responseHeader to specify cookies (Set-Cookie). To specify
|
||||||
// application negotiated subprotocol (Sec-WebSocket-Protocol).
|
// subprotocols supported by the server, set Upgrader.Subprotocols directly.
|
||||||
//
|
//
|
||||||
// If the upgrade fails, then Upgrade replies to the client with an HTTP error
|
// If the upgrade fails, then Upgrade replies to the client with an HTTP error
|
||||||
// response.
|
// response.
|
||||||
@@ -131,7 +133,7 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
|
|||||||
return u.returnError(w, r, http.StatusBadRequest, badHandshake+"'websocket' token not found in 'Upgrade' header")
|
return u.returnError(w, r, http.StatusBadRequest, badHandshake+"'websocket' token not found in 'Upgrade' header")
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Method != "GET" {
|
if r.Method != http.MethodGet {
|
||||||
return u.returnError(w, r, http.StatusMethodNotAllowed, badHandshake+"request method is not GET")
|
return u.returnError(w, r, http.StatusMethodNotAllowed, badHandshake+"request method is not GET")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
vendor/github.com/gorilla/websocket/tls_handshake.go
generated
vendored
Normal file
21
vendor/github.com/gorilla/websocket/tls_handshake.go
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
//go:build go1.17
|
||||||
|
// +build go1.17
|
||||||
|
|
||||||
|
package websocket
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
|
)
|
||||||
|
|
||||||
|
func doHandshake(ctx context.Context, tlsConn *tls.Conn, cfg *tls.Config) error {
|
||||||
|
if err := tlsConn.HandshakeContext(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !cfg.InsecureSkipVerify {
|
||||||
|
if err := tlsConn.VerifyHostname(cfg.ServerName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
21
vendor/github.com/gorilla/websocket/tls_handshake_116.go
generated
vendored
Normal file
21
vendor/github.com/gorilla/websocket/tls_handshake_116.go
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
//go:build !go1.17
|
||||||
|
// +build !go1.17
|
||||||
|
|
||||||
|
package websocket
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
|
)
|
||||||
|
|
||||||
|
func doHandshake(ctx context.Context, tlsConn *tls.Conn, cfg *tls.Config) error {
|
||||||
|
if err := tlsConn.Handshake(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !cfg.InsecureSkipVerify {
|
||||||
|
if err := tlsConn.VerifyHostname(cfg.ServerName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
19
vendor/github.com/gorilla/websocket/trace.go
generated
vendored
19
vendor/github.com/gorilla/websocket/trace.go
generated
vendored
@@ -1,19 +0,0 @@
|
|||||||
// +build go1.8
|
|
||||||
|
|
||||||
package websocket
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/tls"
|
|
||||||
"net/http/httptrace"
|
|
||||||
)
|
|
||||||
|
|
||||||
func doHandshakeWithTrace(trace *httptrace.ClientTrace, tlsConn *tls.Conn, cfg *tls.Config) error {
|
|
||||||
if trace.TLSHandshakeStart != nil {
|
|
||||||
trace.TLSHandshakeStart()
|
|
||||||
}
|
|
||||||
err := doHandshake(tlsConn, cfg)
|
|
||||||
if trace.TLSHandshakeDone != nil {
|
|
||||||
trace.TLSHandshakeDone(tlsConn.ConnectionState(), err)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
12
vendor/github.com/gorilla/websocket/trace_17.go
generated
vendored
12
vendor/github.com/gorilla/websocket/trace_17.go
generated
vendored
@@ -1,12 +0,0 @@
|
|||||||
// +build !go1.8
|
|
||||||
|
|
||||||
package websocket
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/tls"
|
|
||||||
"net/http/httptrace"
|
|
||||||
)
|
|
||||||
|
|
||||||
func doHandshakeWithTrace(trace *httptrace.ClientTrace, tlsConn *tls.Conn, cfg *tls.Config) error {
|
|
||||||
return doHandshake(tlsConn, cfg)
|
|
||||||
}
|
|
125
vendor/github.com/jinzhu/copier/copier.go
generated
vendored
125
vendor/github.com/jinzhu/copier/copier.go
generated
vendored
@@ -24,6 +24,13 @@ const (
|
|||||||
|
|
||||||
// Denotes that the value as been copied
|
// Denotes that the value as been copied
|
||||||
hasCopied
|
hasCopied
|
||||||
|
|
||||||
|
// Some default converter types for a nicer syntax
|
||||||
|
String string = ""
|
||||||
|
Bool bool = false
|
||||||
|
Int int = 0
|
||||||
|
Float32 float32 = 0
|
||||||
|
Float64 float64 = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
// Option sets copy options
|
// Option sets copy options
|
||||||
@@ -32,6 +39,18 @@ type Option struct {
|
|||||||
// struct having all it's fields set to their zero values respectively (see IsZero() in reflect/value.go)
|
// struct having all it's fields set to their zero values respectively (see IsZero() in reflect/value.go)
|
||||||
IgnoreEmpty bool
|
IgnoreEmpty bool
|
||||||
DeepCopy bool
|
DeepCopy bool
|
||||||
|
Converters []TypeConverter
|
||||||
|
}
|
||||||
|
|
||||||
|
type TypeConverter struct {
|
||||||
|
SrcType interface{}
|
||||||
|
DstType interface{}
|
||||||
|
Fn func(src interface{}) (interface{}, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type converterPair struct {
|
||||||
|
SrcType reflect.Type
|
||||||
|
DstType reflect.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tag Flags
|
// Tag Flags
|
||||||
@@ -59,12 +78,27 @@ func CopyWithOption(toValue interface{}, fromValue interface{}, opt Option) (err
|
|||||||
|
|
||||||
func copier(toValue interface{}, fromValue interface{}, opt Option) (err error) {
|
func copier(toValue interface{}, fromValue interface{}, opt Option) (err error) {
|
||||||
var (
|
var (
|
||||||
isSlice bool
|
isSlice bool
|
||||||
amount = 1
|
amount = 1
|
||||||
from = indirect(reflect.ValueOf(fromValue))
|
from = indirect(reflect.ValueOf(fromValue))
|
||||||
to = indirect(reflect.ValueOf(toValue))
|
to = indirect(reflect.ValueOf(toValue))
|
||||||
|
converters map[converterPair]TypeConverter
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// save convertes into map for faster lookup
|
||||||
|
for i := range opt.Converters {
|
||||||
|
if converters == nil {
|
||||||
|
converters = make(map[converterPair]TypeConverter)
|
||||||
|
}
|
||||||
|
|
||||||
|
pair := converterPair{
|
||||||
|
SrcType: reflect.TypeOf(opt.Converters[i].SrcType),
|
||||||
|
DstType: reflect.TypeOf(opt.Converters[i].DstType),
|
||||||
|
}
|
||||||
|
|
||||||
|
converters[pair] = opt.Converters[i]
|
||||||
|
}
|
||||||
|
|
||||||
if !to.CanAddr() {
|
if !to.CanAddr() {
|
||||||
return ErrInvalidCopyDestination
|
return ErrInvalidCopyDestination
|
||||||
}
|
}
|
||||||
@@ -113,13 +147,16 @@ func copier(toValue interface{}, fromValue interface{}, opt Option) (err error)
|
|||||||
|
|
||||||
for _, k := range from.MapKeys() {
|
for _, k := range from.MapKeys() {
|
||||||
toKey := indirect(reflect.New(toType.Key()))
|
toKey := indirect(reflect.New(toType.Key()))
|
||||||
if !set(toKey, k, opt.DeepCopy) {
|
if !set(toKey, k, opt.DeepCopy, converters) {
|
||||||
return fmt.Errorf("%w map, old key: %v, new key: %v", ErrNotSupported, k.Type(), toType.Key())
|
return fmt.Errorf("%w map, old key: %v, new key: %v", ErrNotSupported, k.Type(), toType.Key())
|
||||||
}
|
}
|
||||||
|
|
||||||
elemType, _ := indirectType(toType.Elem())
|
elemType := toType.Elem()
|
||||||
|
if elemType.Kind() != reflect.Slice {
|
||||||
|
elemType, _ = indirectType(elemType)
|
||||||
|
}
|
||||||
toValue := indirect(reflect.New(elemType))
|
toValue := indirect(reflect.New(elemType))
|
||||||
if !set(toValue, from.MapIndex(k), opt.DeepCopy) {
|
if !set(toValue, from.MapIndex(k), opt.DeepCopy, converters) {
|
||||||
if err = copier(toValue.Addr().Interface(), from.MapIndex(k).Interface(), opt); err != nil {
|
if err = copier(toValue.Addr().Interface(), from.MapIndex(k).Interface(), opt); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -148,7 +185,7 @@ func copier(toValue interface{}, fromValue interface{}, opt Option) (err error)
|
|||||||
to.Set(reflect.Append(to, reflect.New(to.Type().Elem()).Elem()))
|
to.Set(reflect.Append(to, reflect.New(to.Type().Elem()).Elem()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if !set(to.Index(i), from.Index(i), opt.DeepCopy) {
|
if !set(to.Index(i), from.Index(i), opt.DeepCopy, converters) {
|
||||||
// ignore error while copy slice element
|
// ignore error while copy slice element
|
||||||
err = copier(to.Index(i).Addr().Interface(), from.Index(i).Interface(), opt)
|
err = copier(to.Index(i).Addr().Interface(), from.Index(i).Interface(), opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -203,6 +240,8 @@ func copier(toValue interface{}, fromValue interface{}, opt Option) (err error)
|
|||||||
|
|
||||||
// check source
|
// check source
|
||||||
if source.IsValid() {
|
if source.IsValid() {
|
||||||
|
copyUnexportedStructFields(dest, source)
|
||||||
|
|
||||||
// Copy from source field to dest field or method
|
// Copy from source field to dest field or method
|
||||||
fromTypeFields := deepFields(fromType)
|
fromTypeFields := deepFields(fromType)
|
||||||
for _, field := range fromTypeFields {
|
for _, field := range fromTypeFields {
|
||||||
@@ -249,7 +288,7 @@ func copier(toValue interface{}, fromValue interface{}, opt Option) (err error)
|
|||||||
toField := dest.FieldByName(destFieldName)
|
toField := dest.FieldByName(destFieldName)
|
||||||
if toField.IsValid() {
|
if toField.IsValid() {
|
||||||
if toField.CanSet() {
|
if toField.CanSet() {
|
||||||
if !set(toField, fromField, opt.DeepCopy) {
|
if !set(toField, fromField, opt.DeepCopy, converters) {
|
||||||
if err := copier(toField.Addr().Interface(), fromField.Interface(), opt); err != nil {
|
if err := copier(toField.Addr().Interface(), fromField.Interface(), opt); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -291,7 +330,7 @@ func copier(toValue interface{}, fromValue interface{}, opt Option) (err error)
|
|||||||
if toField := dest.FieldByName(destFieldName); toField.IsValid() && toField.CanSet() {
|
if toField := dest.FieldByName(destFieldName); toField.IsValid() && toField.CanSet() {
|
||||||
values := fromMethod.Call([]reflect.Value{})
|
values := fromMethod.Call([]reflect.Value{})
|
||||||
if len(values) >= 1 {
|
if len(values) >= 1 {
|
||||||
set(toField, values[0], opt.DeepCopy)
|
set(toField, values[0], opt.DeepCopy, converters)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -303,7 +342,7 @@ func copier(toValue interface{}, fromValue interface{}, opt Option) (err error)
|
|||||||
if to.Len() < i+1 {
|
if to.Len() < i+1 {
|
||||||
to.Set(reflect.Append(to, dest.Addr()))
|
to.Set(reflect.Append(to, dest.Addr()))
|
||||||
} else {
|
} else {
|
||||||
if !set(to.Index(i), dest.Addr(), opt.DeepCopy) {
|
if !set(to.Index(i), dest.Addr(), opt.DeepCopy, converters) {
|
||||||
// ignore error while copy slice element
|
// ignore error while copy slice element
|
||||||
err = copier(to.Index(i).Addr().Interface(), dest.Addr().Interface(), opt)
|
err = copier(to.Index(i).Addr().Interface(), dest.Addr().Interface(), opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -315,7 +354,7 @@ func copier(toValue interface{}, fromValue interface{}, opt Option) (err error)
|
|||||||
if to.Len() < i+1 {
|
if to.Len() < i+1 {
|
||||||
to.Set(reflect.Append(to, dest))
|
to.Set(reflect.Append(to, dest))
|
||||||
} else {
|
} else {
|
||||||
if !set(to.Index(i), dest, opt.DeepCopy) {
|
if !set(to.Index(i), dest, opt.DeepCopy, converters) {
|
||||||
// ignore error while copy slice element
|
// ignore error while copy slice element
|
||||||
err = copier(to.Index(i).Addr().Interface(), dest.Interface(), opt)
|
err = copier(to.Index(i).Addr().Interface(), dest.Interface(), opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -334,6 +373,24 @@ func copier(toValue interface{}, fromValue interface{}, opt Option) (err error)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func copyUnexportedStructFields(to, from reflect.Value) {
|
||||||
|
if from.Kind() != reflect.Struct || to.Kind() != reflect.Struct || !from.Type().AssignableTo(to.Type()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a shallow copy of 'to' to get all fields
|
||||||
|
tmp := indirect(reflect.New(to.Type()))
|
||||||
|
tmp.Set(from)
|
||||||
|
|
||||||
|
// revert exported fields
|
||||||
|
for i := 0; i < to.NumField(); i++ {
|
||||||
|
if tmp.Field(i).CanSet() {
|
||||||
|
tmp.Field(i).Set(to.Field(i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
to.Set(tmp)
|
||||||
|
}
|
||||||
|
|
||||||
func shouldIgnore(v reflect.Value, ignoreEmpty bool) bool {
|
func shouldIgnore(v reflect.Value, ignoreEmpty bool) bool {
|
||||||
if !ignoreEmpty {
|
if !ignoreEmpty {
|
||||||
return false
|
return false
|
||||||
@@ -352,10 +409,10 @@ func deepFields(reflectType reflect.Type) []reflect.StructField {
|
|||||||
// field name. It is empty for upper case (exported) field names.
|
// field name. It is empty for upper case (exported) field names.
|
||||||
// See https://golang.org/ref/spec#Uniqueness_of_identifiers
|
// See https://golang.org/ref/spec#Uniqueness_of_identifiers
|
||||||
if v.PkgPath == "" {
|
if v.PkgPath == "" {
|
||||||
|
fields = append(fields, v)
|
||||||
if v.Anonymous {
|
if v.Anonymous {
|
||||||
|
// also consider fields of anonymous fields as fields of the root
|
||||||
fields = append(fields, deepFields(v.Type)...)
|
fields = append(fields, deepFields(v.Type)...)
|
||||||
} else {
|
|
||||||
fields = append(fields, v)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -381,8 +438,14 @@ func indirectType(reflectType reflect.Type) (_ reflect.Type, isPtr bool) {
|
|||||||
return reflectType, isPtr
|
return reflectType, isPtr
|
||||||
}
|
}
|
||||||
|
|
||||||
func set(to, from reflect.Value, deepCopy bool) bool {
|
func set(to, from reflect.Value, deepCopy bool, converters map[converterPair]TypeConverter) bool {
|
||||||
if from.IsValid() {
|
if from.IsValid() {
|
||||||
|
if ok, err := lookupAndCopyWithConverter(to, from, converters); err != nil {
|
||||||
|
return false
|
||||||
|
} else if ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if to.Kind() == reflect.Ptr {
|
if to.Kind() == reflect.Ptr {
|
||||||
// set `to` to nil if from is nil
|
// set `to` to nil if from is nil
|
||||||
if from.Kind() == reflect.Ptr && from.IsNil() {
|
if from.Kind() == reflect.Ptr && from.IsNil() {
|
||||||
@@ -416,6 +479,9 @@ func set(to, from reflect.Value, deepCopy bool) bool {
|
|||||||
toKind = reflect.TypeOf(to.Interface()).Kind()
|
toKind = reflect.TypeOf(to.Interface()).Kind()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if from.Kind() == reflect.Ptr && from.IsNil() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
if toKind == reflect.Struct || toKind == reflect.Map || toKind == reflect.Slice {
|
if toKind == reflect.Struct || toKind == reflect.Map || toKind == reflect.Slice {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -457,7 +523,7 @@ func set(to, from reflect.Value, deepCopy bool) bool {
|
|||||||
to.Set(rv)
|
to.Set(rv)
|
||||||
}
|
}
|
||||||
} else if from.Kind() == reflect.Ptr {
|
} else if from.Kind() == reflect.Ptr {
|
||||||
return set(to, from.Elem(), deepCopy)
|
return set(to, from.Elem(), deepCopy, converters)
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -466,6 +532,33 @@ func set(to, from reflect.Value, deepCopy bool) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lookupAndCopyWithConverter looks up the type pair, on success the TypeConverter Fn func is called to copy src to dst field.
|
||||||
|
func lookupAndCopyWithConverter(to, from reflect.Value, converters map[converterPair]TypeConverter) (copied bool, err error) {
|
||||||
|
pair := converterPair{
|
||||||
|
SrcType: from.Type(),
|
||||||
|
DstType: to.Type(),
|
||||||
|
}
|
||||||
|
|
||||||
|
if cnv, ok := converters[pair]; ok {
|
||||||
|
result, err := cnv.Fn(from.Interface())
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if result != nil {
|
||||||
|
to.Set(reflect.ValueOf(result))
|
||||||
|
} else {
|
||||||
|
// in case we've got a nil value to copy
|
||||||
|
to.Set(reflect.Zero(to.Type()))
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
// parseTags Parses struct tags and returns uint8 bit flags.
|
// parseTags Parses struct tags and returns uint8 bit flags.
|
||||||
func parseTags(tag string) (flg uint8, name string, err error) {
|
func parseTags(tag string) (flg uint8, name string, err error) {
|
||||||
for _, t := range strings.Split(tag, ",") {
|
for _, t := range strings.Split(tag, ",") {
|
||||||
|
1
vendor/github.com/rs/xid/README.md
generated
vendored
1
vendor/github.com/rs/xid/README.md
generated
vendored
@@ -69,6 +69,7 @@ References:
|
|||||||
- Rust port by [Jérôme Renard](https://github.com/jeromer/): https://github.com/jeromer/libxid
|
- Rust port by [Jérôme Renard](https://github.com/jeromer/): https://github.com/jeromer/libxid
|
||||||
- Ruby port by [Valar](https://github.com/valarpirai/): https://github.com/valarpirai/ruby_xid
|
- Ruby port by [Valar](https://github.com/valarpirai/): https://github.com/valarpirai/ruby_xid
|
||||||
- Java port by [0xShamil](https://github.com/0xShamil/): https://github.com/0xShamil/java-xid
|
- Java port by [0xShamil](https://github.com/0xShamil/): https://github.com/0xShamil/java-xid
|
||||||
|
- Dart port by [Peter Bwire](https://github.com/pitabwire): https://pub.dev/packages/xid
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
|
11
vendor/github.com/rs/xid/error.go
generated
vendored
Normal file
11
vendor/github.com/rs/xid/error.go
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package xid
|
||||||
|
|
||||||
|
const (
|
||||||
|
// ErrInvalidID is returned when trying to unmarshal an invalid ID.
|
||||||
|
ErrInvalidID strErr = "xid: invalid ID"
|
||||||
|
)
|
||||||
|
|
||||||
|
// strErr allows declaring errors as constants.
|
||||||
|
type strErr string
|
||||||
|
|
||||||
|
func (err strErr) Error() string { return string(err) }
|
26
vendor/github.com/rs/xid/id.go
generated
vendored
26
vendor/github.com/rs/xid/id.go
generated
vendored
@@ -47,7 +47,6 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -73,9 +72,6 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrInvalidID is returned when trying to unmarshal an invalid ID
|
|
||||||
ErrInvalidID = errors.New("xid: invalid ID")
|
|
||||||
|
|
||||||
// objectIDCounter is atomically incremented when generating a new ObjectId
|
// objectIDCounter is atomically incremented when generating a new ObjectId
|
||||||
// using NewObjectId() function. It's used as a counter part of an id.
|
// using NewObjectId() function. It's used as a counter part of an id.
|
||||||
// This id is initialized with a random value.
|
// This id is initialized with a random value.
|
||||||
@@ -242,7 +238,9 @@ func (id *ID) UnmarshalText(text []byte) error {
|
|||||||
return ErrInvalidID
|
return ErrInvalidID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
decode(id, text)
|
if !decode(id, text) {
|
||||||
|
return ErrInvalidID
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,11 +251,15 @@ func (id *ID) UnmarshalJSON(b []byte) error {
|
|||||||
*id = nilID
|
*id = nilID
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
// Check the slice length to prevent panic on passing it to UnmarshalText()
|
||||||
|
if len(b) < 2 {
|
||||||
|
return ErrInvalidID
|
||||||
|
}
|
||||||
return id.UnmarshalText(b[1 : len(b)-1])
|
return id.UnmarshalText(b[1 : len(b)-1])
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode by unrolling the stdlib base32 algorithm + removing all safe checks
|
// decode by unrolling the stdlib base32 algorithm + customized safe check.
|
||||||
func decode(id *ID, src []byte) {
|
func decode(id *ID, src []byte) bool {
|
||||||
_ = src[19]
|
_ = src[19]
|
||||||
_ = id[11]
|
_ = id[11]
|
||||||
|
|
||||||
@@ -273,6 +275,16 @@ func decode(id *ID, src []byte) {
|
|||||||
id[2] = dec[src[3]]<<4 | dec[src[4]]>>1
|
id[2] = dec[src[3]]<<4 | dec[src[4]]>>1
|
||||||
id[1] = dec[src[1]]<<6 | dec[src[2]]<<1 | dec[src[3]]>>4
|
id[1] = dec[src[1]]<<6 | dec[src[2]]<<1 | dec[src[3]]>>4
|
||||||
id[0] = dec[src[0]]<<3 | dec[src[1]]>>2
|
id[0] = dec[src[0]]<<3 | dec[src[1]]>>2
|
||||||
|
|
||||||
|
// Validate that there are no discarer bits (padding) in src that would
|
||||||
|
// cause the string-encoded id not to equal src.
|
||||||
|
var check [4]byte
|
||||||
|
|
||||||
|
check[3] = encoding[(id[11]<<4)&0x1F]
|
||||||
|
check[2] = encoding[(id[11]>>1)&0x1F]
|
||||||
|
check[1] = encoding[(id[11]>>6)&0x1F|(id[10]<<2)&0x1F]
|
||||||
|
check[0] = encoding[id[10]>>3]
|
||||||
|
return bytes.Equal([]byte(src[16:20]), check[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Time returns the timestamp part of the id.
|
// Time returns the timestamp part of the id.
|
||||||
|
54
vendor/github.com/stretchr/testify/assert/assertion_compare.go
generated
vendored
54
vendor/github.com/stretchr/testify/assert/assertion_compare.go
generated
vendored
@@ -3,6 +3,7 @@ package assert
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CompareType int
|
type CompareType int
|
||||||
@@ -30,6 +31,8 @@ var (
|
|||||||
float64Type = reflect.TypeOf(float64(1))
|
float64Type = reflect.TypeOf(float64(1))
|
||||||
|
|
||||||
stringType = reflect.TypeOf("")
|
stringType = reflect.TypeOf("")
|
||||||
|
|
||||||
|
timeType = reflect.TypeOf(time.Time{})
|
||||||
)
|
)
|
||||||
|
|
||||||
func compare(obj1, obj2 interface{}, kind reflect.Kind) (CompareType, bool) {
|
func compare(obj1, obj2 interface{}, kind reflect.Kind) (CompareType, bool) {
|
||||||
@@ -299,6 +302,27 @@ func compare(obj1, obj2 interface{}, kind reflect.Kind) (CompareType, bool) {
|
|||||||
return compareLess, true
|
return compareLess, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Check for known struct types we can check for compare results.
|
||||||
|
case reflect.Struct:
|
||||||
|
{
|
||||||
|
// All structs enter here. We're not interested in most types.
|
||||||
|
if !canConvert(obj1Value, timeType) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// time.Time can compared!
|
||||||
|
timeObj1, ok := obj1.(time.Time)
|
||||||
|
if !ok {
|
||||||
|
timeObj1 = obj1Value.Convert(timeType).Interface().(time.Time)
|
||||||
|
}
|
||||||
|
|
||||||
|
timeObj2, ok := obj2.(time.Time)
|
||||||
|
if !ok {
|
||||||
|
timeObj2 = obj2Value.Convert(timeType).Interface().(time.Time)
|
||||||
|
}
|
||||||
|
|
||||||
|
return compare(timeObj1.UnixNano(), timeObj2.UnixNano(), reflect.Int64)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return compareEqual, false
|
return compareEqual, false
|
||||||
@@ -310,7 +334,10 @@ func compare(obj1, obj2 interface{}, kind reflect.Kind) (CompareType, bool) {
|
|||||||
// assert.Greater(t, float64(2), float64(1))
|
// assert.Greater(t, float64(2), float64(1))
|
||||||
// assert.Greater(t, "b", "a")
|
// assert.Greater(t, "b", "a")
|
||||||
func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {
|
func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return compareTwoValues(t, e1, e2, []CompareType{compareGreater}, "\"%v\" is not greater than \"%v\"", msgAndArgs)
|
if h, ok := t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
return compareTwoValues(t, e1, e2, []CompareType{compareGreater}, "\"%v\" is not greater than \"%v\"", msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GreaterOrEqual asserts that the first element is greater than or equal to the second
|
// GreaterOrEqual asserts that the first element is greater than or equal to the second
|
||||||
@@ -320,7 +347,10 @@ func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface
|
|||||||
// assert.GreaterOrEqual(t, "b", "a")
|
// assert.GreaterOrEqual(t, "b", "a")
|
||||||
// assert.GreaterOrEqual(t, "b", "b")
|
// assert.GreaterOrEqual(t, "b", "b")
|
||||||
func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {
|
func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return compareTwoValues(t, e1, e2, []CompareType{compareGreater, compareEqual}, "\"%v\" is not greater than or equal to \"%v\"", msgAndArgs)
|
if h, ok := t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
return compareTwoValues(t, e1, e2, []CompareType{compareGreater, compareEqual}, "\"%v\" is not greater than or equal to \"%v\"", msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Less asserts that the first element is less than the second
|
// Less asserts that the first element is less than the second
|
||||||
@@ -329,7 +359,10 @@ func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...in
|
|||||||
// assert.Less(t, float64(1), float64(2))
|
// assert.Less(t, float64(1), float64(2))
|
||||||
// assert.Less(t, "a", "b")
|
// assert.Less(t, "a", "b")
|
||||||
func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {
|
func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return compareTwoValues(t, e1, e2, []CompareType{compareLess}, "\"%v\" is not less than \"%v\"", msgAndArgs)
|
if h, ok := t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
return compareTwoValues(t, e1, e2, []CompareType{compareLess}, "\"%v\" is not less than \"%v\"", msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LessOrEqual asserts that the first element is less than or equal to the second
|
// LessOrEqual asserts that the first element is less than or equal to the second
|
||||||
@@ -339,7 +372,10 @@ func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{})
|
|||||||
// assert.LessOrEqual(t, "a", "b")
|
// assert.LessOrEqual(t, "a", "b")
|
||||||
// assert.LessOrEqual(t, "b", "b")
|
// assert.LessOrEqual(t, "b", "b")
|
||||||
func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {
|
func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return compareTwoValues(t, e1, e2, []CompareType{compareLess, compareEqual}, "\"%v\" is not less than or equal to \"%v\"", msgAndArgs)
|
if h, ok := t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
return compareTwoValues(t, e1, e2, []CompareType{compareLess, compareEqual}, "\"%v\" is not less than or equal to \"%v\"", msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Positive asserts that the specified element is positive
|
// Positive asserts that the specified element is positive
|
||||||
@@ -347,8 +383,11 @@ func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...inter
|
|||||||
// assert.Positive(t, 1)
|
// assert.Positive(t, 1)
|
||||||
// assert.Positive(t, 1.23)
|
// assert.Positive(t, 1.23)
|
||||||
func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) bool {
|
func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) bool {
|
||||||
|
if h, ok := t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
zero := reflect.Zero(reflect.TypeOf(e))
|
zero := reflect.Zero(reflect.TypeOf(e))
|
||||||
return compareTwoValues(t, e, zero.Interface(), []CompareType{compareGreater}, "\"%v\" is not positive", msgAndArgs)
|
return compareTwoValues(t, e, zero.Interface(), []CompareType{compareGreater}, "\"%v\" is not positive", msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Negative asserts that the specified element is negative
|
// Negative asserts that the specified element is negative
|
||||||
@@ -356,8 +395,11 @@ func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) bool {
|
|||||||
// assert.Negative(t, -1)
|
// assert.Negative(t, -1)
|
||||||
// assert.Negative(t, -1.23)
|
// assert.Negative(t, -1.23)
|
||||||
func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) bool {
|
func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) bool {
|
||||||
|
if h, ok := t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
zero := reflect.Zero(reflect.TypeOf(e))
|
zero := reflect.Zero(reflect.TypeOf(e))
|
||||||
return compareTwoValues(t, e, zero.Interface(), []CompareType{compareLess}, "\"%v\" is not negative", msgAndArgs)
|
return compareTwoValues(t, e, zero.Interface(), []CompareType{compareLess}, "\"%v\" is not negative", msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func compareTwoValues(t TestingT, e1 interface{}, e2 interface{}, allowedComparesResults []CompareType, failMessage string, msgAndArgs ...interface{}) bool {
|
func compareTwoValues(t TestingT, e1 interface{}, e2 interface{}, allowedComparesResults []CompareType, failMessage string, msgAndArgs ...interface{}) bool {
|
||||||
|
16
vendor/github.com/stretchr/testify/assert/assertion_compare_can_convert.go
generated
vendored
Normal file
16
vendor/github.com/stretchr/testify/assert/assertion_compare_can_convert.go
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
//go:build go1.17
|
||||||
|
// +build go1.17
|
||||||
|
|
||||||
|
// TODO: once support for Go 1.16 is dropped, this file can be
|
||||||
|
// merged/removed with assertion_compare_go1.17_test.go and
|
||||||
|
// assertion_compare_legacy.go
|
||||||
|
|
||||||
|
package assert
|
||||||
|
|
||||||
|
import "reflect"
|
||||||
|
|
||||||
|
// Wrapper around reflect.Value.CanConvert, for compatability
|
||||||
|
// reasons.
|
||||||
|
func canConvert(value reflect.Value, to reflect.Type) bool {
|
||||||
|
return value.CanConvert(to)
|
||||||
|
}
|
16
vendor/github.com/stretchr/testify/assert/assertion_compare_legacy.go
generated
vendored
Normal file
16
vendor/github.com/stretchr/testify/assert/assertion_compare_legacy.go
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
//go:build !go1.17
|
||||||
|
// +build !go1.17
|
||||||
|
|
||||||
|
// TODO: once support for Go 1.16 is dropped, this file can be
|
||||||
|
// merged/removed with assertion_compare_go1.17_test.go and
|
||||||
|
// assertion_compare_can_convert.go
|
||||||
|
|
||||||
|
package assert
|
||||||
|
|
||||||
|
import "reflect"
|
||||||
|
|
||||||
|
// Older versions of Go does not have the reflect.Value.CanConvert
|
||||||
|
// method.
|
||||||
|
func canConvert(value reflect.Value, to reflect.Type) bool {
|
||||||
|
return false
|
||||||
|
}
|
12
vendor/github.com/stretchr/testify/assert/assertion_format.go
generated
vendored
12
vendor/github.com/stretchr/testify/assert/assertion_format.go
generated
vendored
@@ -123,6 +123,18 @@ func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...int
|
|||||||
return ErrorAs(t, err, target, append([]interface{}{msg}, args...)...)
|
return ErrorAs(t, err, target, append([]interface{}{msg}, args...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrorContainsf asserts that a function returned an error (i.e. not `nil`)
|
||||||
|
// and that the error contains the specified substring.
|
||||||
|
//
|
||||||
|
// actualObj, err := SomeFunction()
|
||||||
|
// assert.ErrorContainsf(t, err, expectedErrorSubString, "error message %s", "formatted")
|
||||||
|
func ErrorContainsf(t TestingT, theError error, contains string, msg string, args ...interface{}) bool {
|
||||||
|
if h, ok := t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
return ErrorContains(t, theError, contains, append([]interface{}{msg}, args...)...)
|
||||||
|
}
|
||||||
|
|
||||||
// ErrorIsf asserts that at least one of the errors in err's chain matches target.
|
// ErrorIsf asserts that at least one of the errors in err's chain matches target.
|
||||||
// This is a wrapper for errors.Is.
|
// This is a wrapper for errors.Is.
|
||||||
func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) bool {
|
func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) bool {
|
||||||
|
24
vendor/github.com/stretchr/testify/assert/assertion_forward.go
generated
vendored
24
vendor/github.com/stretchr/testify/assert/assertion_forward.go
generated
vendored
@@ -222,6 +222,30 @@ func (a *Assertions) ErrorAsf(err error, target interface{}, msg string, args ..
|
|||||||
return ErrorAsf(a.t, err, target, msg, args...)
|
return ErrorAsf(a.t, err, target, msg, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrorContains asserts that a function returned an error (i.e. not `nil`)
|
||||||
|
// and that the error contains the specified substring.
|
||||||
|
//
|
||||||
|
// actualObj, err := SomeFunction()
|
||||||
|
// a.ErrorContains(err, expectedErrorSubString)
|
||||||
|
func (a *Assertions) ErrorContains(theError error, contains string, msgAndArgs ...interface{}) bool {
|
||||||
|
if h, ok := a.t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
return ErrorContains(a.t, theError, contains, msgAndArgs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorContainsf asserts that a function returned an error (i.e. not `nil`)
|
||||||
|
// and that the error contains the specified substring.
|
||||||
|
//
|
||||||
|
// actualObj, err := SomeFunction()
|
||||||
|
// a.ErrorContainsf(err, expectedErrorSubString, "error message %s", "formatted")
|
||||||
|
func (a *Assertions) ErrorContainsf(theError error, contains string, msg string, args ...interface{}) bool {
|
||||||
|
if h, ok := a.t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
return ErrorContainsf(a.t, theError, contains, msg, args...)
|
||||||
|
}
|
||||||
|
|
||||||
// ErrorIs asserts that at least one of the errors in err's chain matches target.
|
// ErrorIs asserts that at least one of the errors in err's chain matches target.
|
||||||
// This is a wrapper for errors.Is.
|
// This is a wrapper for errors.Is.
|
||||||
func (a *Assertions) ErrorIs(err error, target error, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) ErrorIs(err error, target error, msgAndArgs ...interface{}) bool {
|
||||||
|
8
vendor/github.com/stretchr/testify/assert/assertion_order.go
generated
vendored
8
vendor/github.com/stretchr/testify/assert/assertion_order.go
generated
vendored
@@ -50,7 +50,7 @@ func isOrdered(t TestingT, object interface{}, allowedComparesResults []CompareT
|
|||||||
// assert.IsIncreasing(t, []float{1, 2})
|
// assert.IsIncreasing(t, []float{1, 2})
|
||||||
// assert.IsIncreasing(t, []string{"a", "b"})
|
// assert.IsIncreasing(t, []string{"a", "b"})
|
||||||
func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return isOrdered(t, object, []CompareType{compareLess}, "\"%v\" is not less than \"%v\"", msgAndArgs)
|
return isOrdered(t, object, []CompareType{compareLess}, "\"%v\" is not less than \"%v\"", msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsNonIncreasing asserts that the collection is not increasing
|
// IsNonIncreasing asserts that the collection is not increasing
|
||||||
@@ -59,7 +59,7 @@ func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) boo
|
|||||||
// assert.IsNonIncreasing(t, []float{2, 1})
|
// assert.IsNonIncreasing(t, []float{2, 1})
|
||||||
// assert.IsNonIncreasing(t, []string{"b", "a"})
|
// assert.IsNonIncreasing(t, []string{"b", "a"})
|
||||||
func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return isOrdered(t, object, []CompareType{compareEqual, compareGreater}, "\"%v\" is not greater than or equal to \"%v\"", msgAndArgs)
|
return isOrdered(t, object, []CompareType{compareEqual, compareGreater}, "\"%v\" is not greater than or equal to \"%v\"", msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsDecreasing asserts that the collection is decreasing
|
// IsDecreasing asserts that the collection is decreasing
|
||||||
@@ -68,7 +68,7 @@ func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{})
|
|||||||
// assert.IsDecreasing(t, []float{2, 1})
|
// assert.IsDecreasing(t, []float{2, 1})
|
||||||
// assert.IsDecreasing(t, []string{"b", "a"})
|
// assert.IsDecreasing(t, []string{"b", "a"})
|
||||||
func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return isOrdered(t, object, []CompareType{compareGreater}, "\"%v\" is not greater than \"%v\"", msgAndArgs)
|
return isOrdered(t, object, []CompareType{compareGreater}, "\"%v\" is not greater than \"%v\"", msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsNonDecreasing asserts that the collection is not decreasing
|
// IsNonDecreasing asserts that the collection is not decreasing
|
||||||
@@ -77,5 +77,5 @@ func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) boo
|
|||||||
// assert.IsNonDecreasing(t, []float{1, 2})
|
// assert.IsNonDecreasing(t, []float{1, 2})
|
||||||
// assert.IsNonDecreasing(t, []string{"a", "b"})
|
// assert.IsNonDecreasing(t, []string{"a", "b"})
|
||||||
func IsNonDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
func IsNonDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return isOrdered(t, object, []CompareType{compareLess, compareEqual}, "\"%v\" is not less than or equal to \"%v\"", msgAndArgs)
|
return isOrdered(t, object, []CompareType{compareLess, compareEqual}, "\"%v\" is not less than or equal to \"%v\"", msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
112
vendor/github.com/stretchr/testify/assert/assertions.go
generated
vendored
112
vendor/github.com/stretchr/testify/assert/assertions.go
generated
vendored
@@ -718,10 +718,14 @@ func NotEqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...inte
|
|||||||
// return (false, false) if impossible.
|
// return (false, false) if impossible.
|
||||||
// return (true, false) if element was not found.
|
// return (true, false) if element was not found.
|
||||||
// return (true, true) if element was found.
|
// return (true, true) if element was found.
|
||||||
func includeElement(list interface{}, element interface{}) (ok, found bool) {
|
func containsElement(list interface{}, element interface{}) (ok, found bool) {
|
||||||
|
|
||||||
listValue := reflect.ValueOf(list)
|
listValue := reflect.ValueOf(list)
|
||||||
listKind := reflect.TypeOf(list).Kind()
|
listType := reflect.TypeOf(list)
|
||||||
|
if listType == nil {
|
||||||
|
return false, false
|
||||||
|
}
|
||||||
|
listKind := listType.Kind()
|
||||||
defer func() {
|
defer func() {
|
||||||
if e := recover(); e != nil {
|
if e := recover(); e != nil {
|
||||||
ok = false
|
ok = false
|
||||||
@@ -764,7 +768,7 @@ func Contains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bo
|
|||||||
h.Helper()
|
h.Helper()
|
||||||
}
|
}
|
||||||
|
|
||||||
ok, found := includeElement(s, contains)
|
ok, found := containsElement(s, contains)
|
||||||
if !ok {
|
if !ok {
|
||||||
return Fail(t, fmt.Sprintf("%#v could not be applied builtin len()", s), msgAndArgs...)
|
return Fail(t, fmt.Sprintf("%#v could not be applied builtin len()", s), msgAndArgs...)
|
||||||
}
|
}
|
||||||
@@ -787,7 +791,7 @@ func NotContains(t TestingT, s, contains interface{}, msgAndArgs ...interface{})
|
|||||||
h.Helper()
|
h.Helper()
|
||||||
}
|
}
|
||||||
|
|
||||||
ok, found := includeElement(s, contains)
|
ok, found := containsElement(s, contains)
|
||||||
if !ok {
|
if !ok {
|
||||||
return Fail(t, fmt.Sprintf("\"%s\" could not be applied builtin len()", s), msgAndArgs...)
|
return Fail(t, fmt.Sprintf("\"%s\" could not be applied builtin len()", s), msgAndArgs...)
|
||||||
}
|
}
|
||||||
@@ -831,7 +835,7 @@ func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok
|
|||||||
|
|
||||||
for i := 0; i < subsetValue.Len(); i++ {
|
for i := 0; i < subsetValue.Len(); i++ {
|
||||||
element := subsetValue.Index(i).Interface()
|
element := subsetValue.Index(i).Interface()
|
||||||
ok, found := includeElement(list, element)
|
ok, found := containsElement(list, element)
|
||||||
if !ok {
|
if !ok {
|
||||||
return Fail(t, fmt.Sprintf("\"%s\" could not be applied builtin len()", list), msgAndArgs...)
|
return Fail(t, fmt.Sprintf("\"%s\" could not be applied builtin len()", list), msgAndArgs...)
|
||||||
}
|
}
|
||||||
@@ -852,7 +856,7 @@ func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{})
|
|||||||
h.Helper()
|
h.Helper()
|
||||||
}
|
}
|
||||||
if subset == nil {
|
if subset == nil {
|
||||||
return Fail(t, fmt.Sprintf("nil is the empty set which is a subset of every set"), msgAndArgs...)
|
return Fail(t, "nil is the empty set which is a subset of every set", msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
subsetValue := reflect.ValueOf(subset)
|
subsetValue := reflect.ValueOf(subset)
|
||||||
@@ -875,7 +879,7 @@ func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{})
|
|||||||
|
|
||||||
for i := 0; i < subsetValue.Len(); i++ {
|
for i := 0; i < subsetValue.Len(); i++ {
|
||||||
element := subsetValue.Index(i).Interface()
|
element := subsetValue.Index(i).Interface()
|
||||||
ok, found := includeElement(list, element)
|
ok, found := containsElement(list, element)
|
||||||
if !ok {
|
if !ok {
|
||||||
return Fail(t, fmt.Sprintf("\"%s\" could not be applied builtin len()", list), msgAndArgs...)
|
return Fail(t, fmt.Sprintf("\"%s\" could not be applied builtin len()", list), msgAndArgs...)
|
||||||
}
|
}
|
||||||
@@ -1000,27 +1004,21 @@ func Condition(t TestingT, comp Comparison, msgAndArgs ...interface{}) bool {
|
|||||||
type PanicTestFunc func()
|
type PanicTestFunc func()
|
||||||
|
|
||||||
// didPanic returns true if the function passed to it panics. Otherwise, it returns false.
|
// didPanic returns true if the function passed to it panics. Otherwise, it returns false.
|
||||||
func didPanic(f PanicTestFunc) (bool, interface{}, string) {
|
func didPanic(f PanicTestFunc) (didPanic bool, message interface{}, stack string) {
|
||||||
|
didPanic = true
|
||||||
didPanic := false
|
|
||||||
var message interface{}
|
|
||||||
var stack string
|
|
||||||
func() {
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
if message = recover(); message != nil {
|
|
||||||
didPanic = true
|
|
||||||
stack = string(debug.Stack())
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// call the target function
|
|
||||||
f()
|
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
message = recover()
|
||||||
|
if didPanic {
|
||||||
|
stack = string(debug.Stack())
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return didPanic, message, stack
|
// call the target function
|
||||||
|
f()
|
||||||
|
didPanic = false
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Panics asserts that the code inside the specified PanicTestFunc panics.
|
// Panics asserts that the code inside the specified PanicTestFunc panics.
|
||||||
@@ -1161,11 +1159,15 @@ func InDelta(t TestingT, expected, actual interface{}, delta float64, msgAndArgs
|
|||||||
bf, bok := toFloat(actual)
|
bf, bok := toFloat(actual)
|
||||||
|
|
||||||
if !aok || !bok {
|
if !aok || !bok {
|
||||||
return Fail(t, fmt.Sprintf("Parameters must be numerical"), msgAndArgs...)
|
return Fail(t, "Parameters must be numerical", msgAndArgs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
if math.IsNaN(af) && math.IsNaN(bf) {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if math.IsNaN(af) {
|
if math.IsNaN(af) {
|
||||||
return Fail(t, fmt.Sprintf("Expected must not be NaN"), msgAndArgs...)
|
return Fail(t, "Expected must not be NaN", msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if math.IsNaN(bf) {
|
if math.IsNaN(bf) {
|
||||||
@@ -1188,7 +1190,7 @@ func InDeltaSlice(t TestingT, expected, actual interface{}, delta float64, msgAn
|
|||||||
if expected == nil || actual == nil ||
|
if expected == nil || actual == nil ||
|
||||||
reflect.TypeOf(actual).Kind() != reflect.Slice ||
|
reflect.TypeOf(actual).Kind() != reflect.Slice ||
|
||||||
reflect.TypeOf(expected).Kind() != reflect.Slice {
|
reflect.TypeOf(expected).Kind() != reflect.Slice {
|
||||||
return Fail(t, fmt.Sprintf("Parameters must be slice"), msgAndArgs...)
|
return Fail(t, "Parameters must be slice", msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
actualSlice := reflect.ValueOf(actual)
|
actualSlice := reflect.ValueOf(actual)
|
||||||
@@ -1250,8 +1252,12 @@ func InDeltaMapValues(t TestingT, expected, actual interface{}, delta float64, m
|
|||||||
|
|
||||||
func calcRelativeError(expected, actual interface{}) (float64, error) {
|
func calcRelativeError(expected, actual interface{}) (float64, error) {
|
||||||
af, aok := toFloat(expected)
|
af, aok := toFloat(expected)
|
||||||
if !aok {
|
bf, bok := toFloat(actual)
|
||||||
return 0, fmt.Errorf("expected value %q cannot be converted to float", expected)
|
if !aok || !bok {
|
||||||
|
return 0, fmt.Errorf("Parameters must be numerical")
|
||||||
|
}
|
||||||
|
if math.IsNaN(af) && math.IsNaN(bf) {
|
||||||
|
return 0, nil
|
||||||
}
|
}
|
||||||
if math.IsNaN(af) {
|
if math.IsNaN(af) {
|
||||||
return 0, errors.New("expected value must not be NaN")
|
return 0, errors.New("expected value must not be NaN")
|
||||||
@@ -1259,10 +1265,6 @@ func calcRelativeError(expected, actual interface{}) (float64, error) {
|
|||||||
if af == 0 {
|
if af == 0 {
|
||||||
return 0, fmt.Errorf("expected value must have a value other than zero to calculate the relative error")
|
return 0, fmt.Errorf("expected value must have a value other than zero to calculate the relative error")
|
||||||
}
|
}
|
||||||
bf, bok := toFloat(actual)
|
|
||||||
if !bok {
|
|
||||||
return 0, fmt.Errorf("actual value %q cannot be converted to float", actual)
|
|
||||||
}
|
|
||||||
if math.IsNaN(bf) {
|
if math.IsNaN(bf) {
|
||||||
return 0, errors.New("actual value must not be NaN")
|
return 0, errors.New("actual value must not be NaN")
|
||||||
}
|
}
|
||||||
@@ -1298,7 +1300,7 @@ func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, m
|
|||||||
if expected == nil || actual == nil ||
|
if expected == nil || actual == nil ||
|
||||||
reflect.TypeOf(actual).Kind() != reflect.Slice ||
|
reflect.TypeOf(actual).Kind() != reflect.Slice ||
|
||||||
reflect.TypeOf(expected).Kind() != reflect.Slice {
|
reflect.TypeOf(expected).Kind() != reflect.Slice {
|
||||||
return Fail(t, fmt.Sprintf("Parameters must be slice"), msgAndArgs...)
|
return Fail(t, "Parameters must be slice", msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
actualSlice := reflect.ValueOf(actual)
|
actualSlice := reflect.ValueOf(actual)
|
||||||
@@ -1375,6 +1377,27 @@ func EqualError(t TestingT, theError error, errString string, msgAndArgs ...inte
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrorContains asserts that a function returned an error (i.e. not `nil`)
|
||||||
|
// and that the error contains the specified substring.
|
||||||
|
//
|
||||||
|
// actualObj, err := SomeFunction()
|
||||||
|
// assert.ErrorContains(t, err, expectedErrorSubString)
|
||||||
|
func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{}) bool {
|
||||||
|
if h, ok := t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
if !Error(t, theError, msgAndArgs...) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
actual := theError.Error()
|
||||||
|
if !strings.Contains(actual, contains) {
|
||||||
|
return Fail(t, fmt.Sprintf("Error %#v does not contain %#v", actual, contains), msgAndArgs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// matchRegexp return true if a specified regexp matches a string.
|
// matchRegexp return true if a specified regexp matches a string.
|
||||||
func matchRegexp(rx interface{}, str interface{}) bool {
|
func matchRegexp(rx interface{}, str interface{}) bool {
|
||||||
|
|
||||||
@@ -1588,12 +1611,17 @@ func diff(expected interface{}, actual interface{}) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var e, a string
|
var e, a string
|
||||||
if et != reflect.TypeOf("") {
|
|
||||||
e = spewConfig.Sdump(expected)
|
switch et {
|
||||||
a = spewConfig.Sdump(actual)
|
case reflect.TypeOf(""):
|
||||||
} else {
|
|
||||||
e = reflect.ValueOf(expected).String()
|
e = reflect.ValueOf(expected).String()
|
||||||
a = reflect.ValueOf(actual).String()
|
a = reflect.ValueOf(actual).String()
|
||||||
|
case reflect.TypeOf(time.Time{}):
|
||||||
|
e = spewConfigStringerEnabled.Sdump(expected)
|
||||||
|
a = spewConfigStringerEnabled.Sdump(actual)
|
||||||
|
default:
|
||||||
|
e = spewConfig.Sdump(expected)
|
||||||
|
a = spewConfig.Sdump(actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
|
diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
|
||||||
@@ -1625,6 +1653,14 @@ var spewConfig = spew.ConfigState{
|
|||||||
MaxDepth: 10,
|
MaxDepth: 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var spewConfigStringerEnabled = spew.ConfigState{
|
||||||
|
Indent: " ",
|
||||||
|
DisablePointerAddresses: true,
|
||||||
|
DisableCapacities: true,
|
||||||
|
SortKeys: true,
|
||||||
|
MaxDepth: 10,
|
||||||
|
}
|
||||||
|
|
||||||
type tHelper interface {
|
type tHelper interface {
|
||||||
Helper()
|
Helper()
|
||||||
}
|
}
|
||||||
|
30
vendor/github.com/stretchr/testify/require/require.go
generated
vendored
30
vendor/github.com/stretchr/testify/require/require.go
generated
vendored
@@ -280,6 +280,36 @@ func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...int
|
|||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrorContains asserts that a function returned an error (i.e. not `nil`)
|
||||||
|
// and that the error contains the specified substring.
|
||||||
|
//
|
||||||
|
// actualObj, err := SomeFunction()
|
||||||
|
// assert.ErrorContains(t, err, expectedErrorSubString)
|
||||||
|
func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{}) {
|
||||||
|
if h, ok := t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
if assert.ErrorContains(t, theError, contains, msgAndArgs...) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorContainsf asserts that a function returned an error (i.e. not `nil`)
|
||||||
|
// and that the error contains the specified substring.
|
||||||
|
//
|
||||||
|
// actualObj, err := SomeFunction()
|
||||||
|
// assert.ErrorContainsf(t, err, expectedErrorSubString, "error message %s", "formatted")
|
||||||
|
func ErrorContainsf(t TestingT, theError error, contains string, msg string, args ...interface{}) {
|
||||||
|
if h, ok := t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
if assert.ErrorContainsf(t, theError, contains, msg, args...) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
// ErrorIs asserts that at least one of the errors in err's chain matches target.
|
// ErrorIs asserts that at least one of the errors in err's chain matches target.
|
||||||
// This is a wrapper for errors.Is.
|
// This is a wrapper for errors.Is.
|
||||||
func ErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) {
|
func ErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) {
|
||||||
|
24
vendor/github.com/stretchr/testify/require/require_forward.go
generated
vendored
24
vendor/github.com/stretchr/testify/require/require_forward.go
generated
vendored
@@ -223,6 +223,30 @@ func (a *Assertions) ErrorAsf(err error, target interface{}, msg string, args ..
|
|||||||
ErrorAsf(a.t, err, target, msg, args...)
|
ErrorAsf(a.t, err, target, msg, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrorContains asserts that a function returned an error (i.e. not `nil`)
|
||||||
|
// and that the error contains the specified substring.
|
||||||
|
//
|
||||||
|
// actualObj, err := SomeFunction()
|
||||||
|
// a.ErrorContains(err, expectedErrorSubString)
|
||||||
|
func (a *Assertions) ErrorContains(theError error, contains string, msgAndArgs ...interface{}) {
|
||||||
|
if h, ok := a.t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
ErrorContains(a.t, theError, contains, msgAndArgs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorContainsf asserts that a function returned an error (i.e. not `nil`)
|
||||||
|
// and that the error contains the specified substring.
|
||||||
|
//
|
||||||
|
// actualObj, err := SomeFunction()
|
||||||
|
// a.ErrorContainsf(err, expectedErrorSubString, "error message %s", "formatted")
|
||||||
|
func (a *Assertions) ErrorContainsf(theError error, contains string, msg string, args ...interface{}) {
|
||||||
|
if h, ok := a.t.(tHelper); ok {
|
||||||
|
h.Helper()
|
||||||
|
}
|
||||||
|
ErrorContainsf(a.t, theError, contains, msg, args...)
|
||||||
|
}
|
||||||
|
|
||||||
// ErrorIs asserts that at least one of the errors in err's chain matches target.
|
// ErrorIs asserts that at least one of the errors in err's chain matches target.
|
||||||
// This is a wrapper for errors.Is.
|
// This is a wrapper for errors.Is.
|
||||||
func (a *Assertions) ErrorIs(err error, target error, msgAndArgs ...interface{}) {
|
func (a *Assertions) ErrorIs(err error, target error, msgAndArgs ...interface{}) {
|
||||||
|
2
vendor/go.etcd.io/bbolt/.gitignore
generated
vendored
2
vendor/go.etcd.io/bbolt/.gitignore
generated
vendored
@@ -3,5 +3,3 @@
|
|||||||
*.swp
|
*.swp
|
||||||
/bin/
|
/bin/
|
||||||
cover.out
|
cover.out
|
||||||
/.idea
|
|
||||||
*.iml
|
|
||||||
|
3
vendor/go.etcd.io/bbolt/.travis.yml
generated
vendored
3
vendor/go.etcd.io/bbolt/.travis.yml
generated
vendored
@@ -4,10 +4,9 @@ go_import_path: go.etcd.io/bbolt
|
|||||||
sudo: false
|
sudo: false
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- 1.15
|
- 1.12
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- go get -v golang.org/x/sys/unix
|
|
||||||
- go get -v honnef.co/go/tools/...
|
- go get -v honnef.co/go/tools/...
|
||||||
- go get -v github.com/kisielk/errcheck
|
- go get -v github.com/kisielk/errcheck
|
||||||
|
|
||||||
|
2
vendor/go.etcd.io/bbolt/Makefile
generated
vendored
2
vendor/go.etcd.io/bbolt/Makefile
generated
vendored
@@ -2,6 +2,8 @@ BRANCH=`git rev-parse --abbrev-ref HEAD`
|
|||||||
COMMIT=`git rev-parse --short HEAD`
|
COMMIT=`git rev-parse --short HEAD`
|
||||||
GOLDFLAGS="-X main.branch $(BRANCH) -X main.commit $(COMMIT)"
|
GOLDFLAGS="-X main.branch $(BRANCH) -X main.commit $(COMMIT)"
|
||||||
|
|
||||||
|
default: build
|
||||||
|
|
||||||
race:
|
race:
|
||||||
@TEST_FREELIST_TYPE=hashmap go test -v -race -test.run="TestSimulate_(100op|1000op)"
|
@TEST_FREELIST_TYPE=hashmap go test -v -race -test.run="TestSimulate_(100op|1000op)"
|
||||||
@echo "array freelist test"
|
@echo "array freelist test"
|
||||||
|
5
vendor/go.etcd.io/bbolt/README.md
generated
vendored
5
vendor/go.etcd.io/bbolt/README.md
generated
vendored
@@ -908,14 +908,12 @@ Below is a list of public, open source projects that use Bolt:
|
|||||||
* [BoltStore](https://github.com/yosssi/boltstore) - Session store using Bolt.
|
* [BoltStore](https://github.com/yosssi/boltstore) - Session store using Bolt.
|
||||||
* [Boltdb Boilerplate](https://github.com/bobintornado/boltdb-boilerplate) - Boilerplate wrapper around bolt aiming to make simple calls one-liners.
|
* [Boltdb Boilerplate](https://github.com/bobintornado/boltdb-boilerplate) - Boilerplate wrapper around bolt aiming to make simple calls one-liners.
|
||||||
* [BoltDbWeb](https://github.com/evnix/boltdbweb) - A web based GUI for BoltDB files.
|
* [BoltDbWeb](https://github.com/evnix/boltdbweb) - A web based GUI for BoltDB files.
|
||||||
* [BoltDB Viewer](https://github.com/zc310/rich_boltdb) - A BoltDB Viewer Can run on Windows、Linux、Android system.
|
|
||||||
* [bleve](http://www.blevesearch.com/) - A pure Go search engine similar to ElasticSearch that uses Bolt as the default storage backend.
|
* [bleve](http://www.blevesearch.com/) - A pure Go search engine similar to ElasticSearch that uses Bolt as the default storage backend.
|
||||||
* [btcwallet](https://github.com/btcsuite/btcwallet) - A bitcoin wallet.
|
* [btcwallet](https://github.com/btcsuite/btcwallet) - A bitcoin wallet.
|
||||||
* [buckets](https://github.com/joyrexus/buckets) - a bolt wrapper streamlining
|
* [buckets](https://github.com/joyrexus/buckets) - a bolt wrapper streamlining
|
||||||
simple tx and key scans.
|
simple tx and key scans.
|
||||||
* [cayley](https://github.com/google/cayley) - Cayley is an open-source graph database using Bolt as optional backend.
|
* [cayley](https://github.com/google/cayley) - Cayley is an open-source graph database using Bolt as optional backend.
|
||||||
* [ChainStore](https://github.com/pressly/chainstore) - Simple key-value interface to a variety of storage engines organized as a chain of operations.
|
* [ChainStore](https://github.com/pressly/chainstore) - Simple key-value interface to a variety of storage engines organized as a chain of operations.
|
||||||
* [🌰 Chestnut](https://github.com/jrapoport/chestnut) - Chestnut is encrypted storage for Go.
|
|
||||||
* [Consul](https://github.com/hashicorp/consul) - Consul is service discovery and configuration made easy. Distributed, highly available, and datacenter-aware.
|
* [Consul](https://github.com/hashicorp/consul) - Consul is service discovery and configuration made easy. Distributed, highly available, and datacenter-aware.
|
||||||
* [DVID](https://github.com/janelia-flyem/dvid) - Added Bolt as optional storage engine and testing it against Basho-tuned leveldb.
|
* [DVID](https://github.com/janelia-flyem/dvid) - Added Bolt as optional storage engine and testing it against Basho-tuned leveldb.
|
||||||
* [dcrwallet](https://github.com/decred/dcrwallet) - A wallet for the Decred cryptocurrency.
|
* [dcrwallet](https://github.com/decred/dcrwallet) - A wallet for the Decred cryptocurrency.
|
||||||
@@ -940,8 +938,9 @@ Below is a list of public, open source projects that use Bolt:
|
|||||||
* [MetricBase](https://github.com/msiebuhr/MetricBase) - Single-binary version of Graphite.
|
* [MetricBase](https://github.com/msiebuhr/MetricBase) - Single-binary version of Graphite.
|
||||||
* [MuLiFS](https://github.com/dankomiocevic/mulifs) - Music Library Filesystem creates a filesystem to organise your music files.
|
* [MuLiFS](https://github.com/dankomiocevic/mulifs) - Music Library Filesystem creates a filesystem to organise your music files.
|
||||||
* [NATS](https://github.com/nats-io/nats-streaming-server) - NATS Streaming uses bbolt for message and metadata storage.
|
* [NATS](https://github.com/nats-io/nats-streaming-server) - NATS Streaming uses bbolt for message and metadata storage.
|
||||||
|
* [Operation Go: A Routine Mission](http://gocode.io) - An online programming game for Golang using Bolt for user accounts and a leaderboard.
|
||||||
|
* [photosite/session](https://godoc.org/bitbucket.org/kardianos/photosite/session) - Sessions for a photo viewing site.
|
||||||
* [Prometheus Annotation Server](https://github.com/oliver006/prom_annotation_server) - Annotation server for PromDash & Prometheus service monitoring system.
|
* [Prometheus Annotation Server](https://github.com/oliver006/prom_annotation_server) - Annotation server for PromDash & Prometheus service monitoring system.
|
||||||
* [Rain](https://github.com/cenkalti/rain) - BitTorrent client and library.
|
|
||||||
* [reef-pi](https://github.com/reef-pi/reef-pi) - reef-pi is an award winning, modular, DIY reef tank controller using easy to learn electronics based on a Raspberry Pi.
|
* [reef-pi](https://github.com/reef-pi/reef-pi) - reef-pi is an award winning, modular, DIY reef tank controller using easy to learn electronics based on a Raspberry Pi.
|
||||||
* [Request Baskets](https://github.com/darklynx/request-baskets) - A web service to collect arbitrary HTTP requests and inspect them via REST API or simple web UI, similar to [RequestBin](http://requestb.in/) service
|
* [Request Baskets](https://github.com/darklynx/request-baskets) - A web service to collect arbitrary HTTP requests and inspect them via REST API or simple web UI, similar to [RequestBin](http://requestb.in/) service
|
||||||
* [Seaweed File System](https://github.com/chrislusf/seaweedfs) - Highly scalable distributed key~file system with O(1) disk read.
|
* [Seaweed File System](https://github.com/chrislusf/seaweedfs) - Highly scalable distributed key~file system with O(1) disk read.
|
||||||
|
17
vendor/go.etcd.io/bbolt/bolt_unix.go
generated
vendored
17
vendor/go.etcd.io/bbolt/bolt_unix.go
generated
vendored
@@ -7,8 +7,6 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// flock acquires an advisory lock on a file descriptor.
|
// flock acquires an advisory lock on a file descriptor.
|
||||||
@@ -51,13 +49,13 @@ func funlock(db *DB) error {
|
|||||||
// mmap memory maps a DB's data file.
|
// mmap memory maps a DB's data file.
|
||||||
func mmap(db *DB, sz int) error {
|
func mmap(db *DB, sz int) error {
|
||||||
// Map the data file to memory.
|
// Map the data file to memory.
|
||||||
b, err := unix.Mmap(int(db.file.Fd()), 0, sz, syscall.PROT_READ, syscall.MAP_SHARED|db.MmapFlags)
|
b, err := syscall.Mmap(int(db.file.Fd()), 0, sz, syscall.PROT_READ, syscall.MAP_SHARED|db.MmapFlags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advise the kernel that the mmap is accessed randomly.
|
// Advise the kernel that the mmap is accessed randomly.
|
||||||
err = unix.Madvise(b, syscall.MADV_RANDOM)
|
err = madvise(b, syscall.MADV_RANDOM)
|
||||||
if err != nil && err != syscall.ENOSYS {
|
if err != nil && err != syscall.ENOSYS {
|
||||||
// Ignore not implemented error in kernel because it still works.
|
// Ignore not implemented error in kernel because it still works.
|
||||||
return fmt.Errorf("madvise: %s", err)
|
return fmt.Errorf("madvise: %s", err)
|
||||||
@@ -78,9 +76,18 @@ func munmap(db *DB) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unmap using the original byte slice.
|
// Unmap using the original byte slice.
|
||||||
err := unix.Munmap(db.dataref)
|
err := syscall.Munmap(db.dataref)
|
||||||
db.dataref = nil
|
db.dataref = nil
|
||||||
db.data = nil
|
db.data = nil
|
||||||
db.datasz = 0
|
db.datasz = 0
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: This function is copied from stdlib because it is not available on darwin.
|
||||||
|
func madvise(b []byte, advice int) (err error) {
|
||||||
|
_, _, e1 := syscall.Syscall(syscall.SYS_MADVISE, uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)), uintptr(advice))
|
||||||
|
if e1 != 0 {
|
||||||
|
err = e1
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
114
vendor/go.etcd.io/bbolt/compact.go
generated
vendored
114
vendor/go.etcd.io/bbolt/compact.go
generated
vendored
@@ -1,114 +0,0 @@
|
|||||||
package bbolt
|
|
||||||
|
|
||||||
// Compact will create a copy of the source DB and in the destination DB. This may
|
|
||||||
// reclaim space that the source database no longer has use for. txMaxSize can be
|
|
||||||
// used to limit the transactions size of this process and may trigger intermittent
|
|
||||||
// commits. A value of zero will ignore transaction sizes.
|
|
||||||
// TODO: merge with: https://github.com/etcd-io/etcd/blob/b7f0f52a16dbf83f18ca1d803f7892d750366a94/mvcc/backend/backend.go#L349
|
|
||||||
func Compact(dst, src *DB, txMaxSize int64) error {
|
|
||||||
// commit regularly, or we'll run out of memory for large datasets if using one transaction.
|
|
||||||
var size int64
|
|
||||||
tx, err := dst.Begin(true)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer tx.Rollback()
|
|
||||||
|
|
||||||
if err := walk(src, func(keys [][]byte, k, v []byte, seq uint64) error {
|
|
||||||
// On each key/value, check if we have exceeded tx size.
|
|
||||||
sz := int64(len(k) + len(v))
|
|
||||||
if size+sz > txMaxSize && txMaxSize != 0 {
|
|
||||||
// Commit previous transaction.
|
|
||||||
if err := tx.Commit(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start new transaction.
|
|
||||||
tx, err = dst.Begin(true)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
size = 0
|
|
||||||
}
|
|
||||||
size += sz
|
|
||||||
|
|
||||||
// Create bucket on the root transaction if this is the first level.
|
|
||||||
nk := len(keys)
|
|
||||||
if nk == 0 {
|
|
||||||
bkt, err := tx.CreateBucket(k)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := bkt.SetSequence(seq); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create buckets on subsequent levels, if necessary.
|
|
||||||
b := tx.Bucket(keys[0])
|
|
||||||
if nk > 1 {
|
|
||||||
for _, k := range keys[1:] {
|
|
||||||
b = b.Bucket(k)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fill the entire page for best compaction.
|
|
||||||
b.FillPercent = 1.0
|
|
||||||
|
|
||||||
// If there is no value then this is a bucket call.
|
|
||||||
if v == nil {
|
|
||||||
bkt, err := b.CreateBucket(k)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := bkt.SetSequence(seq); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise treat it as a key/value pair.
|
|
||||||
return b.Put(k, v)
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return tx.Commit()
|
|
||||||
}
|
|
||||||
|
|
||||||
// walkFunc is the type of the function called for keys (buckets and "normal"
|
|
||||||
// values) discovered by Walk. keys is the list of keys to descend to the bucket
|
|
||||||
// owning the discovered key/value pair k/v.
|
|
||||||
type walkFunc func(keys [][]byte, k, v []byte, seq uint64) error
|
|
||||||
|
|
||||||
// walk walks recursively the bolt database db, calling walkFn for each key it finds.
|
|
||||||
func walk(db *DB, walkFn walkFunc) error {
|
|
||||||
return db.View(func(tx *Tx) error {
|
|
||||||
return tx.ForEach(func(name []byte, b *Bucket) error {
|
|
||||||
return walkBucket(b, nil, name, nil, b.Sequence(), walkFn)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func walkBucket(b *Bucket, keypath [][]byte, k, v []byte, seq uint64, fn walkFunc) error {
|
|
||||||
// Execute callback.
|
|
||||||
if err := fn(keypath, k, v, seq); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this is not a bucket then stop.
|
|
||||||
if v != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Iterate over each child key/value.
|
|
||||||
keypath = append(keypath, k)
|
|
||||||
return b.ForEach(func(k, v []byte) error {
|
|
||||||
if v == nil {
|
|
||||||
bkt := b.Bucket(k)
|
|
||||||
return walkBucket(bkt, keypath, k, nil, bkt.Sequence(), fn)
|
|
||||||
}
|
|
||||||
return walkBucket(b, keypath, k, v, b.Sequence(), fn)
|
|
||||||
})
|
|
||||||
}
|
|
66
vendor/go.etcd.io/bbolt/db.go
generated
vendored
66
vendor/go.etcd.io/bbolt/db.go
generated
vendored
@@ -120,12 +120,6 @@ type DB struct {
|
|||||||
// of truncate() and fsync() when growing the data file.
|
// of truncate() and fsync() when growing the data file.
|
||||||
AllocSize int
|
AllocSize int
|
||||||
|
|
||||||
// Mlock locks database file in memory when set to true.
|
|
||||||
// It prevents major page faults, however used memory can't be reclaimed.
|
|
||||||
//
|
|
||||||
// Supported only on Unix via mlock/munlock syscalls.
|
|
||||||
Mlock bool
|
|
||||||
|
|
||||||
path string
|
path string
|
||||||
openFile func(string, int, os.FileMode) (*os.File, error)
|
openFile func(string, int, os.FileMode) (*os.File, error)
|
||||||
file *os.File
|
file *os.File
|
||||||
@@ -194,7 +188,6 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
|
|||||||
db.MmapFlags = options.MmapFlags
|
db.MmapFlags = options.MmapFlags
|
||||||
db.NoFreelistSync = options.NoFreelistSync
|
db.NoFreelistSync = options.NoFreelistSync
|
||||||
db.FreelistType = options.FreelistType
|
db.FreelistType = options.FreelistType
|
||||||
db.Mlock = options.Mlock
|
|
||||||
|
|
||||||
// Set default values for later DB operations.
|
// Set default values for later DB operations.
|
||||||
db.MaxBatchSize = DefaultMaxBatchSize
|
db.MaxBatchSize = DefaultMaxBatchSize
|
||||||
@@ -344,8 +337,7 @@ func (db *DB) mmap(minsz int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the size is at least the minimum size.
|
// Ensure the size is at least the minimum size.
|
||||||
fileSize := int(info.Size())
|
var size = int(info.Size())
|
||||||
var size = fileSize
|
|
||||||
if size < minsz {
|
if size < minsz {
|
||||||
size = minsz
|
size = minsz
|
||||||
}
|
}
|
||||||
@@ -354,13 +346,6 @@ func (db *DB) mmap(minsz int) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if db.Mlock {
|
|
||||||
// Unlock db memory
|
|
||||||
if err := db.munlock(fileSize); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dereference all mmap references before unmapping.
|
// Dereference all mmap references before unmapping.
|
||||||
if db.rwtx != nil {
|
if db.rwtx != nil {
|
||||||
db.rwtx.root.dereference()
|
db.rwtx.root.dereference()
|
||||||
@@ -376,13 +361,6 @@ func (db *DB) mmap(minsz int) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if db.Mlock {
|
|
||||||
// Don't allow swapping of data file
|
|
||||||
if err := db.mlock(fileSize); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save references to the meta pages.
|
// Save references to the meta pages.
|
||||||
db.meta0 = db.page(0).meta()
|
db.meta0 = db.page(0).meta()
|
||||||
db.meta1 = db.page(1).meta()
|
db.meta1 = db.page(1).meta()
|
||||||
@@ -444,36 +422,12 @@ func (db *DB) mmapSize(size int) (int, error) {
|
|||||||
return int(sz), nil
|
return int(sz), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) munlock(fileSize int) error {
|
|
||||||
if err := munlock(db, fileSize); err != nil {
|
|
||||||
return fmt.Errorf("munlock error: " + err.Error())
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (db *DB) mlock(fileSize int) error {
|
|
||||||
if err := mlock(db, fileSize); err != nil {
|
|
||||||
return fmt.Errorf("mlock error: " + err.Error())
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (db *DB) mrelock(fileSizeFrom, fileSizeTo int) error {
|
|
||||||
if err := db.munlock(fileSizeFrom); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := db.mlock(fileSizeTo); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// init creates a new database file and initializes its meta pages.
|
// init creates a new database file and initializes its meta pages.
|
||||||
func (db *DB) init() error {
|
func (db *DB) init() error {
|
||||||
// Create two meta pages on a buffer.
|
// Create two meta pages on a buffer.
|
||||||
buf := make([]byte, db.pageSize*4)
|
buf := make([]byte, db.pageSize*4)
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
p := db.pageInBuffer(buf, pgid(i))
|
p := db.pageInBuffer(buf[:], pgid(i))
|
||||||
p.id = pgid(i)
|
p.id = pgid(i)
|
||||||
p.flags = metaPageFlag
|
p.flags = metaPageFlag
|
||||||
|
|
||||||
@@ -490,13 +444,13 @@ func (db *DB) init() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write an empty freelist at page 3.
|
// Write an empty freelist at page 3.
|
||||||
p := db.pageInBuffer(buf, pgid(2))
|
p := db.pageInBuffer(buf[:], pgid(2))
|
||||||
p.id = pgid(2)
|
p.id = pgid(2)
|
||||||
p.flags = freelistPageFlag
|
p.flags = freelistPageFlag
|
||||||
p.count = 0
|
p.count = 0
|
||||||
|
|
||||||
// Write an empty leaf page at page 4.
|
// Write an empty leaf page at page 4.
|
||||||
p = db.pageInBuffer(buf, pgid(3))
|
p = db.pageInBuffer(buf[:], pgid(3))
|
||||||
p.id = pgid(3)
|
p.id = pgid(3)
|
||||||
p.flags = leafPageFlag
|
p.flags = leafPageFlag
|
||||||
p.count = 0
|
p.count = 0
|
||||||
@@ -508,7 +462,6 @@ func (db *DB) init() error {
|
|||||||
if err := fdatasync(db); err != nil {
|
if err := fdatasync(db); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
db.filesz = len(buf)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1020,12 +973,6 @@ func (db *DB) grow(sz int) error {
|
|||||||
if err := db.file.Sync(); err != nil {
|
if err := db.file.Sync(); err != nil {
|
||||||
return fmt.Errorf("file sync error: %s", err)
|
return fmt.Errorf("file sync error: %s", err)
|
||||||
}
|
}
|
||||||
if db.Mlock {
|
|
||||||
// unlock old file and lock new one
|
|
||||||
if err := db.mrelock(db.filesz, sz); err != nil {
|
|
||||||
return fmt.Errorf("mlock/munlock error: %s", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
db.filesz = sz
|
db.filesz = sz
|
||||||
@@ -1117,11 +1064,6 @@ type Options struct {
|
|||||||
// OpenFile is used to open files. It defaults to os.OpenFile. This option
|
// OpenFile is used to open files. It defaults to os.OpenFile. This option
|
||||||
// is useful for writing hermetic tests.
|
// is useful for writing hermetic tests.
|
||||||
OpenFile func(string, int, os.FileMode) (*os.File, error)
|
OpenFile func(string, int, os.FileMode) (*os.File, error)
|
||||||
|
|
||||||
// Mlock locks database file in memory when set to true.
|
|
||||||
// It prevents potential page faults, however
|
|
||||||
// used memory can't be reclaimed. (UNIX only)
|
|
||||||
Mlock bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultOptions represent the options used if nil options are passed into Open().
|
// DefaultOptions represent the options used if nil options are passed into Open().
|
||||||
|
6
vendor/go.etcd.io/bbolt/freelist_hmap.go
generated
vendored
6
vendor/go.etcd.io/bbolt/freelist_hmap.go
generated
vendored
@@ -4,7 +4,7 @@ import "sort"
|
|||||||
|
|
||||||
// hashmapFreeCount returns count of free pages(hashmap version)
|
// hashmapFreeCount returns count of free pages(hashmap version)
|
||||||
func (f *freelist) hashmapFreeCount() int {
|
func (f *freelist) hashmapFreeCount() int {
|
||||||
// use the forwardMap to get the total count
|
// use the forwardmap to get the total count
|
||||||
count := 0
|
count := 0
|
||||||
for _, size := range f.forwardMap {
|
for _, size := range f.forwardMap {
|
||||||
count += int(size)
|
count += int(size)
|
||||||
@@ -41,7 +41,7 @@ func (f *freelist) hashmapAllocate(txid txid, n int) pgid {
|
|||||||
|
|
||||||
for pid := range bm {
|
for pid := range bm {
|
||||||
// remove the initial
|
// remove the initial
|
||||||
f.delSpan(pid, size)
|
f.delSpan(pid, uint64(size))
|
||||||
|
|
||||||
f.allocs[pid] = txid
|
f.allocs[pid] = txid
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ func (f *freelist) hashmapAllocate(txid txid, n int) pgid {
|
|||||||
f.addSpan(pid+pgid(n), remain)
|
f.addSpan(pid+pgid(n), remain)
|
||||||
|
|
||||||
for i := pgid(0); i < pgid(n); i++ {
|
for i := pgid(0); i < pgid(n); i++ {
|
||||||
delete(f.cache, pid+i)
|
delete(f.cache, pid+pgid(i))
|
||||||
}
|
}
|
||||||
return pid
|
return pid
|
||||||
}
|
}
|
||||||
|
36
vendor/go.etcd.io/bbolt/mlock_unix.go
generated
vendored
36
vendor/go.etcd.io/bbolt/mlock_unix.go
generated
vendored
@@ -1,36 +0,0 @@
|
|||||||
// +build !windows
|
|
||||||
|
|
||||||
package bbolt
|
|
||||||
|
|
||||||
import "golang.org/x/sys/unix"
|
|
||||||
|
|
||||||
// mlock locks memory of db file
|
|
||||||
func mlock(db *DB, fileSize int) error {
|
|
||||||
sizeToLock := fileSize
|
|
||||||
if sizeToLock > db.datasz {
|
|
||||||
// Can't lock more than mmaped slice
|
|
||||||
sizeToLock = db.datasz
|
|
||||||
}
|
|
||||||
if err := unix.Mlock(db.dataref[:sizeToLock]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
//munlock unlocks memory of db file
|
|
||||||
func munlock(db *DB, fileSize int) error {
|
|
||||||
if db.dataref == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
sizeToUnlock := fileSize
|
|
||||||
if sizeToUnlock > db.datasz {
|
|
||||||
// Can't unlock more than mmaped slice
|
|
||||||
sizeToUnlock = db.datasz
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := unix.Munlock(db.dataref[:sizeToUnlock]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
11
vendor/go.etcd.io/bbolt/mlock_windows.go
generated
vendored
11
vendor/go.etcd.io/bbolt/mlock_windows.go
generated
vendored
@@ -1,11 +0,0 @@
|
|||||||
package bbolt
|
|
||||||
|
|
||||||
// mlock locks memory of db file
|
|
||||||
func mlock(_ *DB, _ int) error {
|
|
||||||
panic("mlock is supported only on UNIX systems")
|
|
||||||
}
|
|
||||||
|
|
||||||
//munlock unlocks memory of db file
|
|
||||||
func munlock(_ *DB, _ int) error {
|
|
||||||
panic("munlock is supported only on UNIX systems")
|
|
||||||
}
|
|
3
vendor/go.etcd.io/bbolt/tx.go
generated
vendored
3
vendor/go.etcd.io/bbolt/tx.go
generated
vendored
@@ -188,6 +188,7 @@ func (tx *Tx) Commit() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If strict mode is enabled then perform a consistency check.
|
// If strict mode is enabled then perform a consistency check.
|
||||||
|
// Only the first consistency error is reported in the panic.
|
||||||
if tx.db.StrictMode {
|
if tx.db.StrictMode {
|
||||||
ch := tx.Check()
|
ch := tx.Check()
|
||||||
var errs []string
|
var errs []string
|
||||||
@@ -392,7 +393,7 @@ func (tx *Tx) CopyFile(path string, mode os.FileMode) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.WriteTo(f)
|
err = tx.Copy(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = f.Close()
|
_ = f.Close()
|
||||||
return err
|
return err
|
||||||
|
10
vendor/modules.txt
vendored
10
vendor/modules.txt
vendored
@@ -12,10 +12,10 @@ github.com/asdine/storm/v3/q
|
|||||||
# github.com/davecgh/go-spew v1.1.1
|
# github.com/davecgh/go-spew v1.1.1
|
||||||
## explicit
|
## explicit
|
||||||
github.com/davecgh/go-spew/spew
|
github.com/davecgh/go-spew/spew
|
||||||
# github.com/gorilla/websocket v1.4.2
|
# github.com/gorilla/websocket v1.5.0
|
||||||
## explicit; go 1.12
|
## explicit; go 1.12
|
||||||
github.com/gorilla/websocket
|
github.com/gorilla/websocket
|
||||||
# github.com/jinzhu/copier v0.3.4
|
# github.com/jinzhu/copier v0.3.5
|
||||||
## explicit; go 1.13
|
## explicit; go 1.13
|
||||||
github.com/jinzhu/copier
|
github.com/jinzhu/copier
|
||||||
# github.com/logrusorgru/aurora v2.0.3+incompatible
|
# github.com/logrusorgru/aurora v2.0.3+incompatible
|
||||||
@@ -24,14 +24,14 @@ github.com/logrusorgru/aurora
|
|||||||
# github.com/pmezard/go-difflib v1.0.0
|
# github.com/pmezard/go-difflib v1.0.0
|
||||||
## explicit
|
## explicit
|
||||||
github.com/pmezard/go-difflib/difflib
|
github.com/pmezard/go-difflib/difflib
|
||||||
# github.com/rs/xid v1.3.0
|
# github.com/rs/xid v1.4.0
|
||||||
## explicit; go 1.12
|
## explicit; go 1.12
|
||||||
github.com/rs/xid
|
github.com/rs/xid
|
||||||
# github.com/stretchr/testify v1.7.0
|
# github.com/stretchr/testify v1.7.1
|
||||||
## explicit; go 1.13
|
## explicit; go 1.13
|
||||||
github.com/stretchr/testify/assert
|
github.com/stretchr/testify/assert
|
||||||
github.com/stretchr/testify/require
|
github.com/stretchr/testify/require
|
||||||
# go.etcd.io/bbolt v1.3.6
|
# go.etcd.io/bbolt v1.3.5
|
||||||
## explicit; go 1.12
|
## explicit; go 1.12
|
||||||
go.etcd.io/bbolt
|
go.etcd.io/bbolt
|
||||||
# golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d
|
# golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d
|
||||||
|
Reference in New Issue
Block a user