forked from pneymrl2f/nightingale
Clean up gomod and vendor (#96)
parent
c14a7a170a
commit
c0675e9a2a
@ -1,175 +0,0 @@
|
|||||||
|
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
@ -1,54 +0,0 @@
|
|||||||
// Copyright 2014 Gary Burd
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
|
||||||
// not use this file except in compliance with the License. You may obtain
|
|
||||||
// a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
// License for the specific language governing permissions and limitations
|
|
||||||
// under the License.
|
|
||||||
|
|
||||||
package internal // import "github.com/gomodule/redigo/internal"
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
WatchState = 1 << iota
|
|
||||||
MultiState
|
|
||||||
SubscribeState
|
|
||||||
MonitorState
|
|
||||||
)
|
|
||||||
|
|
||||||
type CommandInfo struct {
|
|
||||||
Set, Clear int
|
|
||||||
}
|
|
||||||
|
|
||||||
var commandInfos = map[string]CommandInfo{
|
|
||||||
"WATCH": {Set: WatchState},
|
|
||||||
"UNWATCH": {Clear: WatchState},
|
|
||||||
"MULTI": {Set: MultiState},
|
|
||||||
"EXEC": {Clear: WatchState | MultiState},
|
|
||||||
"DISCARD": {Clear: WatchState | MultiState},
|
|
||||||
"PSUBSCRIBE": {Set: SubscribeState},
|
|
||||||
"SUBSCRIBE": {Set: SubscribeState},
|
|
||||||
"MONITOR": {Set: MonitorState},
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
for n, ci := range commandInfos {
|
|
||||||
commandInfos[strings.ToLower(n)] = ci
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func LookupCommandInfo(commandName string) CommandInfo {
|
|
||||||
if ci, ok := commandInfos[commandName]; ok {
|
|
||||||
return ci
|
|
||||||
}
|
|
||||||
return commandInfos[strings.ToUpper(commandName)]
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,177 +0,0 @@
|
|||||||
// Copyright 2012 Gary Burd
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
|
||||||
// not use this file except in compliance with the License. You may obtain
|
|
||||||
// a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
// License for the specific language governing permissions and limitations
|
|
||||||
// under the License.
|
|
||||||
|
|
||||||
// Package redis is a client for the Redis database.
|
|
||||||
//
|
|
||||||
// The Redigo FAQ (https://github.com/gomodule/redigo/wiki/FAQ) contains more
|
|
||||||
// documentation about this package.
|
|
||||||
//
|
|
||||||
// Connections
|
|
||||||
//
|
|
||||||
// The Conn interface is the primary interface for working with Redis.
|
|
||||||
// Applications create connections by calling the Dial, DialWithTimeout or
|
|
||||||
// NewConn functions. In the future, functions will be added for creating
|
|
||||||
// sharded and other types of connections.
|
|
||||||
//
|
|
||||||
// The application must call the connection Close method when the application
|
|
||||||
// is done with the connection.
|
|
||||||
//
|
|
||||||
// Executing Commands
|
|
||||||
//
|
|
||||||
// The Conn interface has a generic method for executing Redis commands:
|
|
||||||
//
|
|
||||||
// Do(commandName string, args ...interface{}) (reply interface{}, err error)
|
|
||||||
//
|
|
||||||
// The Redis command reference (http://redis.io/commands) lists the available
|
|
||||||
// commands. An example of using the Redis APPEND command is:
|
|
||||||
//
|
|
||||||
// n, err := conn.Do("APPEND", "key", "value")
|
|
||||||
//
|
|
||||||
// The Do method converts command arguments to bulk strings for transmission
|
|
||||||
// to the server as follows:
|
|
||||||
//
|
|
||||||
// Go Type Conversion
|
|
||||||
// []byte Sent as is
|
|
||||||
// string Sent as is
|
|
||||||
// int, int64 strconv.FormatInt(v)
|
|
||||||
// float64 strconv.FormatFloat(v, 'g', -1, 64)
|
|
||||||
// bool true -> "1", false -> "0"
|
|
||||||
// nil ""
|
|
||||||
// all other types fmt.Fprint(w, v)
|
|
||||||
//
|
|
||||||
// Redis command reply types are represented using the following Go types:
|
|
||||||
//
|
|
||||||
// Redis type Go type
|
|
||||||
// error redis.Error
|
|
||||||
// integer int64
|
|
||||||
// simple string string
|
|
||||||
// bulk string []byte or nil if value not present.
|
|
||||||
// array []interface{} or nil if value not present.
|
|
||||||
//
|
|
||||||
// Use type assertions or the reply helper functions to convert from
|
|
||||||
// interface{} to the specific Go type for the command result.
|
|
||||||
//
|
|
||||||
// Pipelining
|
|
||||||
//
|
|
||||||
// Connections support pipelining using the Send, Flush and Receive methods.
|
|
||||||
//
|
|
||||||
// Send(commandName string, args ...interface{}) error
|
|
||||||
// Flush() error
|
|
||||||
// Receive() (reply interface{}, err error)
|
|
||||||
//
|
|
||||||
// Send writes the command to the connection's output buffer. Flush flushes the
|
|
||||||
// connection's output buffer to the server. Receive reads a single reply from
|
|
||||||
// the server. The following example shows a simple pipeline.
|
|
||||||
//
|
|
||||||
// c.Send("SET", "foo", "bar")
|
|
||||||
// c.Send("GET", "foo")
|
|
||||||
// c.Flush()
|
|
||||||
// c.Receive() // reply from SET
|
|
||||||
// v, err = c.Receive() // reply from GET
|
|
||||||
//
|
|
||||||
// The Do method combines the functionality of the Send, Flush and Receive
|
|
||||||
// methods. The Do method starts by writing the command and flushing the output
|
|
||||||
// buffer. Next, the Do method receives all pending replies including the reply
|
|
||||||
// for the command just sent by Do. If any of the received replies is an error,
|
|
||||||
// then Do returns the error. If there are no errors, then Do returns the last
|
|
||||||
// reply. If the command argument to the Do method is "", then the Do method
|
|
||||||
// will flush the output buffer and receive pending replies without sending a
|
|
||||||
// command.
|
|
||||||
//
|
|
||||||
// Use the Send and Do methods to implement pipelined transactions.
|
|
||||||
//
|
|
||||||
// c.Send("MULTI")
|
|
||||||
// c.Send("INCR", "foo")
|
|
||||||
// c.Send("INCR", "bar")
|
|
||||||
// r, err := c.Do("EXEC")
|
|
||||||
// fmt.Println(r) // prints [1, 1]
|
|
||||||
//
|
|
||||||
// Concurrency
|
|
||||||
//
|
|
||||||
// Connections support one concurrent caller to the Receive method and one
|
|
||||||
// concurrent caller to the Send and Flush methods. No other concurrency is
|
|
||||||
// supported including concurrent calls to the Do method.
|
|
||||||
//
|
|
||||||
// For full concurrent access to Redis, use the thread-safe Pool to get, use
|
|
||||||
// and release a connection from within a goroutine. Connections returned from
|
|
||||||
// a Pool have the concurrency restrictions described in the previous
|
|
||||||
// paragraph.
|
|
||||||
//
|
|
||||||
// Publish and Subscribe
|
|
||||||
//
|
|
||||||
// Use the Send, Flush and Receive methods to implement Pub/Sub subscribers.
|
|
||||||
//
|
|
||||||
// c.Send("SUBSCRIBE", "example")
|
|
||||||
// c.Flush()
|
|
||||||
// for {
|
|
||||||
// reply, err := c.Receive()
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// // process pushed message
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// The PubSubConn type wraps a Conn with convenience methods for implementing
|
|
||||||
// subscribers. The Subscribe, PSubscribe, Unsubscribe and PUnsubscribe methods
|
|
||||||
// send and flush a subscription management command. The receive method
|
|
||||||
// converts a pushed message to convenient types for use in a type switch.
|
|
||||||
//
|
|
||||||
// psc := redis.PubSubConn{Conn: c}
|
|
||||||
// psc.Subscribe("example")
|
|
||||||
// for {
|
|
||||||
// switch v := psc.Receive().(type) {
|
|
||||||
// case redis.Message:
|
|
||||||
// fmt.Printf("%s: message: %s\n", v.Channel, v.Data)
|
|
||||||
// case redis.Subscription:
|
|
||||||
// fmt.Printf("%s: %s %d\n", v.Channel, v.Kind, v.Count)
|
|
||||||
// case error:
|
|
||||||
// return v
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Reply Helpers
|
|
||||||
//
|
|
||||||
// The Bool, Int, Bytes, String, Strings and Values functions convert a reply
|
|
||||||
// to a value of a specific type. To allow convenient wrapping of calls to the
|
|
||||||
// connection Do and Receive methods, the functions take a second argument of
|
|
||||||
// type error. If the error is non-nil, then the helper function returns the
|
|
||||||
// error. If the error is nil, the function converts the reply to the specified
|
|
||||||
// type:
|
|
||||||
//
|
|
||||||
// exists, err := redis.Bool(c.Do("EXISTS", "foo"))
|
|
||||||
// if err != nil {
|
|
||||||
// // handle error return from c.Do or type conversion error.
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// The Scan function converts elements of a array reply to Go types:
|
|
||||||
//
|
|
||||||
// var value1 int
|
|
||||||
// var value2 string
|
|
||||||
// reply, err := redis.Values(c.Do("MGET", "key1", "key2"))
|
|
||||||
// if err != nil {
|
|
||||||
// // handle error
|
|
||||||
// }
|
|
||||||
// if _, err := redis.Scan(reply, &value1, &value2); err != nil {
|
|
||||||
// // handle error
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Errors
|
|
||||||
//
|
|
||||||
// Connection methods return error replies from the server as type redis.Error.
|
|
||||||
//
|
|
||||||
// Call the connection Err() method to determine if the connection encountered
|
|
||||||
// non-recoverable error such as a network error or protocol parsing error. If
|
|
||||||
// Err() returns a non-nil value, then the connection is not usable and should
|
|
||||||
// be closed.
|
|
||||||
package redis // import "github.com/gomodule/redigo/redis"
|
|
@ -1,27 +0,0 @@
|
|||||||
// +build !go1.7
|
|
||||||
|
|
||||||
package redis
|
|
||||||
|
|
||||||
import "crypto/tls"
|
|
||||||
|
|
||||||
func cloneTLSConfig(cfg *tls.Config) *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,
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
// +build go1.7,!go1.8
|
|
||||||
|
|
||||||
package redis
|
|
||||||
|
|
||||||
import "crypto/tls"
|
|
||||||
|
|
||||||
func cloneTLSConfig(cfg *tls.Config) *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,
|
|
||||||
DynamicRecordSizingDisabled: cfg.DynamicRecordSizingDisabled,
|
|
||||||
Renegotiation: cfg.Renegotiation,
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
// +build go1.8
|
|
||||||
|
|
||||||
package redis
|
|
||||||
|
|
||||||
import "crypto/tls"
|
|
||||||
|
|
||||||
func cloneTLSConfig(cfg *tls.Config) *tls.Config {
|
|
||||||
return cfg.Clone()
|
|
||||||
}
|
|
@ -1,134 +0,0 @@
|
|||||||
// Copyright 2012 Gary Burd
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
|
||||||
// not use this file except in compliance with the License. You may obtain
|
|
||||||
// a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
// License for the specific language governing permissions and limitations
|
|
||||||
// under the License.
|
|
||||||
|
|
||||||
package redis
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
_ ConnWithTimeout = (*loggingConn)(nil)
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewLoggingConn returns a logging wrapper around a connection.
|
|
||||||
func NewLoggingConn(conn Conn, logger *log.Logger, prefix string) Conn {
|
|
||||||
if prefix != "" {
|
|
||||||
prefix = prefix + "."
|
|
||||||
}
|
|
||||||
return &loggingConn{conn, logger, prefix}
|
|
||||||
}
|
|
||||||
|
|
||||||
type loggingConn struct {
|
|
||||||
Conn
|
|
||||||
logger *log.Logger
|
|
||||||
prefix string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *loggingConn) Close() error {
|
|
||||||
err := c.Conn.Close()
|
|
||||||
var buf bytes.Buffer
|
|
||||||
fmt.Fprintf(&buf, "%sClose() -> (%v)", c.prefix, err)
|
|
||||||
c.logger.Output(2, buf.String())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *loggingConn) printValue(buf *bytes.Buffer, v interface{}) {
|
|
||||||
const chop = 32
|
|
||||||
switch v := v.(type) {
|
|
||||||
case []byte:
|
|
||||||
if len(v) > chop {
|
|
||||||
fmt.Fprintf(buf, "%q...", v[:chop])
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(buf, "%q", v)
|
|
||||||
}
|
|
||||||
case string:
|
|
||||||
if len(v) > chop {
|
|
||||||
fmt.Fprintf(buf, "%q...", v[:chop])
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(buf, "%q", v)
|
|
||||||
}
|
|
||||||
case []interface{}:
|
|
||||||
if len(v) == 0 {
|
|
||||||
buf.WriteString("[]")
|
|
||||||
} else {
|
|
||||||
sep := "["
|
|
||||||
fin := "]"
|
|
||||||
if len(v) > chop {
|
|
||||||
v = v[:chop]
|
|
||||||
fin = "...]"
|
|
||||||
}
|
|
||||||
for _, vv := range v {
|
|
||||||
buf.WriteString(sep)
|
|
||||||
c.printValue(buf, vv)
|
|
||||||
sep = ", "
|
|
||||||
}
|
|
||||||
buf.WriteString(fin)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
fmt.Fprint(buf, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *loggingConn) print(method, commandName string, args []interface{}, reply interface{}, err error) {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
fmt.Fprintf(&buf, "%s%s(", c.prefix, method)
|
|
||||||
if method != "Receive" {
|
|
||||||
buf.WriteString(commandName)
|
|
||||||
for _, arg := range args {
|
|
||||||
buf.WriteString(", ")
|
|
||||||
c.printValue(&buf, arg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buf.WriteString(") -> (")
|
|
||||||
if method != "Send" {
|
|
||||||
c.printValue(&buf, reply)
|
|
||||||
buf.WriteString(", ")
|
|
||||||
}
|
|
||||||
fmt.Fprintf(&buf, "%v)", err)
|
|
||||||
c.logger.Output(3, buf.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *loggingConn) Do(commandName string, args ...interface{}) (interface{}, error) {
|
|
||||||
reply, err := c.Conn.Do(commandName, args...)
|
|
||||||
c.print("Do", commandName, args, reply, err)
|
|
||||||
return reply, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *loggingConn) DoWithTimeout(timeout time.Duration, commandName string, args ...interface{}) (interface{}, error) {
|
|
||||||
reply, err := DoWithTimeout(c.Conn, timeout, commandName, args...)
|
|
||||||
c.print("DoWithTimeout", commandName, args, reply, err)
|
|
||||||
return reply, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *loggingConn) Send(commandName string, args ...interface{}) error {
|
|
||||||
err := c.Conn.Send(commandName, args...)
|
|
||||||
c.print("Send", commandName, args, nil, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *loggingConn) Receive() (interface{}, error) {
|
|
||||||
reply, err := c.Conn.Receive()
|
|
||||||
c.print("Receive", "", nil, reply, err)
|
|
||||||
return reply, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *loggingConn) ReceiveWithTimeout(timeout time.Duration) (interface{}, error) {
|
|
||||||
reply, err := ReceiveWithTimeout(c.Conn, timeout)
|
|
||||||
c.print("ReceiveWithTimeout", "", nil, reply, err)
|
|
||||||
return reply, err
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,35 +0,0 @@
|
|||||||
// Copyright 2018 Gary Burd
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
|
||||||
// not use this file except in compliance with the License. You may obtain
|
|
||||||
// a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
// License for the specific language governing permissions and limitations
|
|
||||||
// under the License.
|
|
||||||
|
|
||||||
// +build go1.7
|
|
||||||
|
|
||||||
package redis
|
|
||||||
|
|
||||||
import "context"
|
|
||||||
|
|
||||||
// GetContext gets a connection using the provided context.
|
|
||||||
//
|
|
||||||
// The provided Context must be non-nil. If the context expires before the
|
|
||||||
// connection is complete, an error is returned. Any expiration on the context
|
|
||||||
// will not affect the returned connection.
|
|
||||||
//
|
|
||||||
// If the function completes without error, then the application must close the
|
|
||||||
// returned connection.
|
|
||||||
func (p *Pool) GetContext(ctx context.Context) (Conn, error) {
|
|
||||||
pc, err := p.get(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return errorConn{err}, err
|
|
||||||
}
|
|
||||||
return &activeConn{p: p, pc: pc}, nil
|
|
||||||
}
|
|
@ -1,148 +0,0 @@
|
|||||||
// Copyright 2012 Gary Burd
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
|
||||||
// not use this file except in compliance with the License. You may obtain
|
|
||||||
// a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
// License for the specific language governing permissions and limitations
|
|
||||||
// under the License.
|
|
||||||
|
|
||||||
package redis
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Subscription represents a subscribe or unsubscribe notification.
|
|
||||||
type Subscription struct {
|
|
||||||
// Kind is "subscribe", "unsubscribe", "psubscribe" or "punsubscribe"
|
|
||||||
Kind string
|
|
||||||
|
|
||||||
// The channel that was changed.
|
|
||||||
Channel string
|
|
||||||
|
|
||||||
// The current number of subscriptions for connection.
|
|
||||||
Count int
|
|
||||||
}
|
|
||||||
|
|
||||||
// Message represents a message notification.
|
|
||||||
type Message struct {
|
|
||||||
// The originating channel.
|
|
||||||
Channel string
|
|
||||||
|
|
||||||
// The matched pattern, if any
|
|
||||||
Pattern string
|
|
||||||
|
|
||||||
// The message data.
|
|
||||||
Data []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pong represents a pubsub pong notification.
|
|
||||||
type Pong struct {
|
|
||||||
Data string
|
|
||||||
}
|
|
||||||
|
|
||||||
// PubSubConn wraps a Conn with convenience methods for subscribers.
|
|
||||||
type PubSubConn struct {
|
|
||||||
Conn Conn
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close closes the connection.
|
|
||||||
func (c PubSubConn) Close() error {
|
|
||||||
return c.Conn.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Subscribe subscribes the connection to the specified channels.
|
|
||||||
func (c PubSubConn) Subscribe(channel ...interface{}) error {
|
|
||||||
c.Conn.Send("SUBSCRIBE", channel...)
|
|
||||||
return c.Conn.Flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
// PSubscribe subscribes the connection to the given patterns.
|
|
||||||
func (c PubSubConn) PSubscribe(channel ...interface{}) error {
|
|
||||||
c.Conn.Send("PSUBSCRIBE", channel...)
|
|
||||||
return c.Conn.Flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unsubscribe unsubscribes the connection from the given channels, or from all
|
|
||||||
// of them if none is given.
|
|
||||||
func (c PubSubConn) Unsubscribe(channel ...interface{}) error {
|
|
||||||
c.Conn.Send("UNSUBSCRIBE", channel...)
|
|
||||||
return c.Conn.Flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
// PUnsubscribe unsubscribes the connection from the given patterns, or from all
|
|
||||||
// of them if none is given.
|
|
||||||
func (c PubSubConn) PUnsubscribe(channel ...interface{}) error {
|
|
||||||
c.Conn.Send("PUNSUBSCRIBE", channel...)
|
|
||||||
return c.Conn.Flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ping sends a PING to the server with the specified data.
|
|
||||||
//
|
|
||||||
// The connection must be subscribed to at least one channel or pattern when
|
|
||||||
// calling this method.
|
|
||||||
func (c PubSubConn) Ping(data string) error {
|
|
||||||
c.Conn.Send("PING", data)
|
|
||||||
return c.Conn.Flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Receive returns a pushed message as a Subscription, Message, Pong or error.
|
|
||||||
// The return value is intended to be used directly in a type switch as
|
|
||||||
// illustrated in the PubSubConn example.
|
|
||||||
func (c PubSubConn) Receive() interface{} {
|
|
||||||
return c.receiveInternal(c.Conn.Receive())
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReceiveWithTimeout is like Receive, but it allows the application to
|
|
||||||
// override the connection's default timeout.
|
|
||||||
func (c PubSubConn) ReceiveWithTimeout(timeout time.Duration) interface{} {
|
|
||||||
return c.receiveInternal(ReceiveWithTimeout(c.Conn, timeout))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c PubSubConn) receiveInternal(replyArg interface{}, errArg error) interface{} {
|
|
||||||
reply, err := Values(replyArg, errArg)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var kind string
|
|
||||||
reply, err = Scan(reply, &kind)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
switch kind {
|
|
||||||
case "message":
|
|
||||||
var m Message
|
|
||||||
if _, err := Scan(reply, &m.Channel, &m.Data); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
case "pmessage":
|
|
||||||
var m Message
|
|
||||||
if _, err := Scan(reply, &m.Pattern, &m.Channel, &m.Data); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
case "subscribe", "psubscribe", "unsubscribe", "punsubscribe":
|
|
||||||
s := Subscription{Kind: kind}
|
|
||||||
if _, err := Scan(reply, &s.Channel, &s.Count); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
case "pong":
|
|
||||||
var p Pong
|
|
||||||
if _, err := Scan(reply, &p.Data); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
return errors.New("redigo: unknown pubsub notification")
|
|
||||||
}
|
|
@ -1,117 +0,0 @@
|
|||||||
// Copyright 2012 Gary Burd
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
|
||||||
// not use this file except in compliance with the License. You may obtain
|
|
||||||
// a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
// License for the specific language governing permissions and limitations
|
|
||||||
// under the License.
|
|
||||||
|
|
||||||
package redis
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Error represents an error returned in a command reply.
|
|
||||||
type Error string
|
|
||||||
|
|
||||||
func (err Error) Error() string { return string(err) }
|
|
||||||
|
|
||||||
// Conn represents a connection to a Redis server.
|
|
||||||
type Conn interface {
|
|
||||||
// Close closes the connection.
|
|
||||||
Close() error
|
|
||||||
|
|
||||||
// Err returns a non-nil value when the connection is not usable.
|
|
||||||
Err() error
|
|
||||||
|
|
||||||
// Do sends a command to the server and returns the received reply.
|
|
||||||
Do(commandName string, args ...interface{}) (reply interface{}, err error)
|
|
||||||
|
|
||||||
// Send writes the command to the client's output buffer.
|
|
||||||
Send(commandName string, args ...interface{}) error
|
|
||||||
|
|
||||||
// Flush flushes the output buffer to the Redis server.
|
|
||||||
Flush() error
|
|
||||||
|
|
||||||
// Receive receives a single reply from the Redis server
|
|
||||||
Receive() (reply interface{}, err error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Argument is the interface implemented by an object which wants to control how
|
|
||||||
// the object is converted to Redis bulk strings.
|
|
||||||
type Argument interface {
|
|
||||||
// RedisArg returns a value to be encoded as a bulk string per the
|
|
||||||
// conversions listed in the section 'Executing Commands'.
|
|
||||||
// Implementations should typically return a []byte or string.
|
|
||||||
RedisArg() interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scanner is implemented by an object which wants to control its value is
|
|
||||||
// interpreted when read from Redis.
|
|
||||||
type Scanner interface {
|
|
||||||
// RedisScan assigns a value from a Redis value. The argument src is one of
|
|
||||||
// the reply types listed in the section `Executing Commands`.
|
|
||||||
//
|
|
||||||
// An error should be returned if the value cannot be stored without
|
|
||||||
// loss of information.
|
|
||||||
RedisScan(src interface{}) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConnWithTimeout is an optional interface that allows the caller to override
|
|
||||||
// a connection's default read timeout. This interface is useful for executing
|
|
||||||
// the BLPOP, BRPOP, BRPOPLPUSH, XREAD and other commands that block at the
|
|
||||||
// server.
|
|
||||||
//
|
|
||||||
// A connection's default read timeout is set with the DialReadTimeout dial
|
|
||||||
// option. Applications should rely on the default timeout for commands that do
|
|
||||||
// not block at the server.
|
|
||||||
//
|
|
||||||
// All of the Conn implementations in this package satisfy the ConnWithTimeout
|
|
||||||
// interface.
|
|
||||||
//
|
|
||||||
// Use the DoWithTimeout and ReceiveWithTimeout helper functions to simplify
|
|
||||||
// use of this interface.
|
|
||||||
type ConnWithTimeout interface {
|
|
||||||
Conn
|
|
||||||
|
|
||||||
// Do sends a command to the server and returns the received reply.
|
|
||||||
// The timeout overrides the read timeout set when dialing the
|
|
||||||
// connection.
|
|
||||||
DoWithTimeout(timeout time.Duration, commandName string, args ...interface{}) (reply interface{}, err error)
|
|
||||||
|
|
||||||
// Receive receives a single reply from the Redis server. The timeout
|
|
||||||
// overrides the read timeout set when dialing the connection.
|
|
||||||
ReceiveWithTimeout(timeout time.Duration) (reply interface{}, err error)
|
|
||||||
}
|
|
||||||
|
|
||||||
var errTimeoutNotSupported = errors.New("redis: connection does not support ConnWithTimeout")
|
|
||||||
|
|
||||||
// DoWithTimeout executes a Redis command with the specified read timeout. If
|
|
||||||
// the connection does not satisfy the ConnWithTimeout interface, then an error
|
|
||||||
// is returned.
|
|
||||||
func DoWithTimeout(c Conn, timeout time.Duration, cmd string, args ...interface{}) (interface{}, error) {
|
|
||||||
cwt, ok := c.(ConnWithTimeout)
|
|
||||||
if !ok {
|
|
||||||
return nil, errTimeoutNotSupported
|
|
||||||
}
|
|
||||||
return cwt.DoWithTimeout(timeout, cmd, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReceiveWithTimeout receives a reply with the specified read timeout. If the
|
|
||||||
// connection does not satisfy the ConnWithTimeout interface, then an error is
|
|
||||||
// returned.
|
|
||||||
func ReceiveWithTimeout(c Conn, timeout time.Duration) (interface{}, error) {
|
|
||||||
cwt, ok := c.(ConnWithTimeout)
|
|
||||||
if !ok {
|
|
||||||
return nil, errTimeoutNotSupported
|
|
||||||
}
|
|
||||||
return cwt.ReceiveWithTimeout(timeout)
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,91 +0,0 @@
|
|||||||
// Copyright 2012 Gary Burd
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
|
||||||
// not use this file except in compliance with the License. You may obtain
|
|
||||||
// a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
// License for the specific language governing permissions and limitations
|
|
||||||
// under the License.
|
|
||||||
|
|
||||||
package redis
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/sha1"
|
|
||||||
"encoding/hex"
|
|
||||||
"io"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Script encapsulates the source, hash and key count for a Lua script. See
|
|
||||||
// http://redis.io/commands/eval for information on scripts in Redis.
|
|
||||||
type Script struct {
|
|
||||||
keyCount int
|
|
||||||
src string
|
|
||||||
hash string
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewScript returns a new script object. If keyCount is greater than or equal
|
|
||||||
// to zero, then the count is automatically inserted in the EVAL command
|
|
||||||
// argument list. If keyCount is less than zero, then the application supplies
|
|
||||||
// the count as the first value in the keysAndArgs argument to the Do, Send and
|
|
||||||
// SendHash methods.
|
|
||||||
func NewScript(keyCount int, src string) *Script {
|
|
||||||
h := sha1.New()
|
|
||||||
io.WriteString(h, src)
|
|
||||||
return &Script{keyCount, src, hex.EncodeToString(h.Sum(nil))}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Script) args(spec string, keysAndArgs []interface{}) []interface{} {
|
|
||||||
var args []interface{}
|
|
||||||
if s.keyCount < 0 {
|
|
||||||
args = make([]interface{}, 1+len(keysAndArgs))
|
|
||||||
args[0] = spec
|
|
||||||
copy(args[1:], keysAndArgs)
|
|
||||||
} else {
|
|
||||||
args = make([]interface{}, 2+len(keysAndArgs))
|
|
||||||
args[0] = spec
|
|
||||||
args[1] = s.keyCount
|
|
||||||
copy(args[2:], keysAndArgs)
|
|
||||||
}
|
|
||||||
return args
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hash returns the script hash.
|
|
||||||
func (s *Script) Hash() string {
|
|
||||||
return s.hash
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do evaluates the script. Under the covers, Do optimistically evaluates the
|
|
||||||
// script using the EVALSHA command. If the command fails because the script is
|
|
||||||
// not loaded, then Do evaluates the script using the EVAL command (thus
|
|
||||||
// causing the script to load).
|
|
||||||
func (s *Script) Do(c Conn, keysAndArgs ...interface{}) (interface{}, error) {
|
|
||||||
v, err := c.Do("EVALSHA", s.args(s.hash, keysAndArgs)...)
|
|
||||||
if e, ok := err.(Error); ok && strings.HasPrefix(string(e), "NOSCRIPT ") {
|
|
||||||
v, err = c.Do("EVAL", s.args(s.src, keysAndArgs)...)
|
|
||||||
}
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendHash evaluates the script without waiting for the reply. The script is
|
|
||||||
// evaluated with the EVALSHA command. The application must ensure that the
|
|
||||||
// script is loaded by a previous call to Send, Do or Load methods.
|
|
||||||
func (s *Script) SendHash(c Conn, keysAndArgs ...interface{}) error {
|
|
||||||
return c.Send("EVALSHA", s.args(s.hash, keysAndArgs)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send evaluates the script without waiting for the reply.
|
|
||||||
func (s *Script) Send(c Conn, keysAndArgs ...interface{}) error {
|
|
||||||
return c.Send("EVAL", s.args(s.src, keysAndArgs)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load loads the script without evaluating it.
|
|
||||||
func (s *Script) Load(c Conn) error {
|
|
||||||
_, err := c.Do("SCRIPT", "LOAD", s.src)
|
|
||||||
return err
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,78 +0,0 @@
|
|||||||
// Copyright 2018 The Go 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 ignore
|
|
||||||
|
|
||||||
// mkasm_darwin.go generates assembly trampolines to call libSystem routines from Go.
|
|
||||||
//This program must be run after mksyscall.go.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func writeASMFile(in string, fileName string, buildTags string) {
|
|
||||||
trampolines := map[string]bool{}
|
|
||||||
|
|
||||||
var out bytes.Buffer
|
|
||||||
|
|
||||||
fmt.Fprintf(&out, "// go run mkasm_darwin.go %s\n", strings.Join(os.Args[1:], " "))
|
|
||||||
fmt.Fprintf(&out, "// Code generated by the command above; DO NOT EDIT.\n")
|
|
||||||
fmt.Fprintf(&out, "\n")
|
|
||||||
fmt.Fprintf(&out, "// +build %s\n", buildTags)
|
|
||||||
fmt.Fprintf(&out, "\n")
|
|
||||||
fmt.Fprintf(&out, "#include \"textflag.h\"\n")
|
|
||||||
for _, line := range strings.Split(in, "\n") {
|
|
||||||
if !strings.HasPrefix(line, "func ") || !strings.HasSuffix(line, "_trampoline()") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
fn := line[5 : len(line)-13]
|
|
||||||
if !trampolines[fn] {
|
|
||||||
trampolines[fn] = true
|
|
||||||
fmt.Fprintf(&out, "TEXT ·%s_trampoline(SB),NOSPLIT,$0-0\n", fn)
|
|
||||||
fmt.Fprintf(&out, "\tJMP\t%s(SB)\n", fn)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err := ioutil.WriteFile(fileName, out.Bytes(), 0644)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("can't write %s: %s", fileName, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
in1, err := ioutil.ReadFile("syscall_darwin.go")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("can't open syscall_darwin.go: %s", err)
|
|
||||||
}
|
|
||||||
arch := os.Args[1]
|
|
||||||
in2, err := ioutil.ReadFile(fmt.Sprintf("syscall_darwin_%s.go", arch))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("can't open syscall_darwin_%s.go: %s", arch, err)
|
|
||||||
}
|
|
||||||
in3, err := ioutil.ReadFile(fmt.Sprintf("zsyscall_darwin_%s.go", arch))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("can't open zsyscall_darwin_%s.go: %s", arch, err)
|
|
||||||
}
|
|
||||||
in := string(in1) + string(in2) + string(in3)
|
|
||||||
|
|
||||||
writeASMFile(in, fmt.Sprintf("zsyscall_darwin_%s.s", arch), "go1.12")
|
|
||||||
|
|
||||||
in1, err = ioutil.ReadFile("syscall_darwin.1_13.go")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("can't open syscall_darwin.1_13.go: %s", err)
|
|
||||||
}
|
|
||||||
in2, err = ioutil.ReadFile(fmt.Sprintf("zsyscall_darwin_%s.1_13.go", arch))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("can't open zsyscall_darwin_%s.1_13.go: %s", arch, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
in = string(in1) + string(in2)
|
|
||||||
|
|
||||||
writeASMFile(in, fmt.Sprintf("zsyscall_darwin_%s.1_13.s", arch), "go1.13")
|
|
||||||
}
|
|
@ -1,127 +0,0 @@
|
|||||||
// Copyright 2016 The Go 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 ignore
|
|
||||||
|
|
||||||
// mkpost processes the output of cgo -godefs to
|
|
||||||
// modify the generated types. It is used to clean up
|
|
||||||
// the sys API in an architecture specific manner.
|
|
||||||
//
|
|
||||||
// mkpost is run after cgo -godefs; see README.md.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"go/format"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"regexp"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// Get the OS and architecture (using GOARCH_TARGET if it exists)
|
|
||||||
goos := os.Getenv("GOOS")
|
|
||||||
goarch := os.Getenv("GOARCH_TARGET")
|
|
||||||
if goarch == "" {
|
|
||||||
goarch = os.Getenv("GOARCH")
|
|
||||||
}
|
|
||||||
// Check that we are using the Docker-based build system if we should be.
|
|
||||||
if goos == "linux" {
|
|
||||||
if os.Getenv("GOLANG_SYS_BUILD") != "docker" {
|
|
||||||
os.Stderr.WriteString("In the Docker-based build system, mkpost should not be called directly.\n")
|
|
||||||
os.Stderr.WriteString("See README.md\n")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
b, err := ioutil.ReadAll(os.Stdin)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if goos == "aix" {
|
|
||||||
// Replace type of Atim, Mtim and Ctim by Timespec in Stat_t
|
|
||||||
// to avoid having both StTimespec and Timespec.
|
|
||||||
sttimespec := regexp.MustCompile(`_Ctype_struct_st_timespec`)
|
|
||||||
b = sttimespec.ReplaceAll(b, []byte("Timespec"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Intentionally export __val fields in Fsid and Sigset_t
|
|
||||||
valRegex := regexp.MustCompile(`type (Fsid|Sigset_t) struct {(\s+)X__(bits|val)(\s+\S+\s+)}`)
|
|
||||||
b = valRegex.ReplaceAll(b, []byte("type $1 struct {${2}Val$4}"))
|
|
||||||
|
|
||||||
// Intentionally export __fds_bits field in FdSet
|
|
||||||
fdSetRegex := regexp.MustCompile(`type (FdSet) struct {(\s+)X__fds_bits(\s+\S+\s+)}`)
|
|
||||||
b = fdSetRegex.ReplaceAll(b, []byte("type $1 struct {${2}Bits$3}"))
|
|
||||||
|
|
||||||
// If we have empty Ptrace structs, we should delete them. Only s390x emits
|
|
||||||
// nonempty Ptrace structs.
|
|
||||||
ptraceRexexp := regexp.MustCompile(`type Ptrace((Psw|Fpregs|Per) struct {\s*})`)
|
|
||||||
b = ptraceRexexp.ReplaceAll(b, nil)
|
|
||||||
|
|
||||||
// Replace the control_regs union with a blank identifier for now.
|
|
||||||
controlRegsRegex := regexp.MustCompile(`(Control_regs)\s+\[0\]uint64`)
|
|
||||||
b = controlRegsRegex.ReplaceAll(b, []byte("_ [0]uint64"))
|
|
||||||
|
|
||||||
// Remove fields that are added by glibc
|
|
||||||
// Note that this is unstable as the identifers are private.
|
|
||||||
removeFieldsRegex := regexp.MustCompile(`X__glibc\S*`)
|
|
||||||
b = removeFieldsRegex.ReplaceAll(b, []byte("_"))
|
|
||||||
|
|
||||||
// Convert [65]int8 to [65]byte in Utsname members to simplify
|
|
||||||
// conversion to string; see golang.org/issue/20753
|
|
||||||
convertUtsnameRegex := regexp.MustCompile(`((Sys|Node|Domain)name|Release|Version|Machine)(\s+)\[(\d+)\]u?int8`)
|
|
||||||
b = convertUtsnameRegex.ReplaceAll(b, []byte("$1$3[$4]byte"))
|
|
||||||
|
|
||||||
// Convert [n]int8 to [n]byte in Statvfs_t members to simplify
|
|
||||||
// conversion to string.
|
|
||||||
convertStatvfsRegex := regexp.MustCompile(`((Fstype|Mnton|Mntfrom)name)(\s+)\[(\d+)\]int8`)
|
|
||||||
b = convertStatvfsRegex.ReplaceAll(b, []byte("$1$3[$4]byte"))
|
|
||||||
|
|
||||||
// Convert [1024]int8 to [1024]byte in Ptmget members
|
|
||||||
convertPtmget := regexp.MustCompile(`([SC]n)(\s+)\[(\d+)\]u?int8`)
|
|
||||||
b = convertPtmget.ReplaceAll(b, []byte("$1[$3]byte"))
|
|
||||||
|
|
||||||
// Remove spare fields (e.g. in Statx_t)
|
|
||||||
spareFieldsRegex := regexp.MustCompile(`X__spare\S*`)
|
|
||||||
b = spareFieldsRegex.ReplaceAll(b, []byte("_"))
|
|
||||||
|
|
||||||
// Remove cgo padding fields
|
|
||||||
removePaddingFieldsRegex := regexp.MustCompile(`Pad_cgo_\d+`)
|
|
||||||
b = removePaddingFieldsRegex.ReplaceAll(b, []byte("_"))
|
|
||||||
|
|
||||||
// Remove padding, hidden, or unused fields
|
|
||||||
removeFieldsRegex = regexp.MustCompile(`\b(X_\S+|Padding)`)
|
|
||||||
b = removeFieldsRegex.ReplaceAll(b, []byte("_"))
|
|
||||||
|
|
||||||
// Remove the first line of warning from cgo
|
|
||||||
b = b[bytes.IndexByte(b, '\n')+1:]
|
|
||||||
// Modify the command in the header to include:
|
|
||||||
// mkpost, our own warning, and a build tag.
|
|
||||||
replacement := fmt.Sprintf(`$1 | go run mkpost.go
|
|
||||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
|
||||||
|
|
||||||
// +build %s,%s`, goarch, goos)
|
|
||||||
cgoCommandRegex := regexp.MustCompile(`(cgo -godefs .*)`)
|
|
||||||
b = cgoCommandRegex.ReplaceAll(b, []byte(replacement))
|
|
||||||
|
|
||||||
// Rename Stat_t time fields
|
|
||||||
if goos == "freebsd" && goarch == "386" {
|
|
||||||
// Hide Stat_t.[AMCB]tim_ext fields
|
|
||||||
renameStatTimeExtFieldsRegex := regexp.MustCompile(`[AMCB]tim_ext`)
|
|
||||||
b = renameStatTimeExtFieldsRegex.ReplaceAll(b, []byte("_"))
|
|
||||||
}
|
|
||||||
renameStatTimeFieldsRegex := regexp.MustCompile(`([AMCB])(?:irth)?time?(?:spec)?\s+(Timespec|StTimespec)`)
|
|
||||||
b = renameStatTimeFieldsRegex.ReplaceAll(b, []byte("${1}tim ${2}"))
|
|
||||||
|
|
||||||
// gofmt
|
|
||||||
b, err = format.Source(b)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
os.Stdout.Write(b)
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,190 +0,0 @@
|
|||||||
// Copyright 2018 The Go 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 ignore
|
|
||||||
|
|
||||||
// Generate system call table for DragonFly, NetBSD,
|
|
||||||
// FreeBSD, OpenBSD or Darwin from master list
|
|
||||||
// (for example, /usr/src/sys/kern/syscalls.master or
|
|
||||||
// sys/syscall.h).
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
goos, goarch string
|
|
||||||
)
|
|
||||||
|
|
||||||
// cmdLine returns this programs's commandline arguments
|
|
||||||
func cmdLine() string {
|
|
||||||
return "go run mksysnum.go " + strings.Join(os.Args[1:], " ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// buildTags returns build tags
|
|
||||||
func buildTags() string {
|
|
||||||
return fmt.Sprintf("%s,%s", goarch, goos)
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkErr(err error) {
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// source string and substring slice for regexp
|
|
||||||
type re struct {
|
|
||||||
str string // source string
|
|
||||||
sub []string // matched sub-string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Match performs regular expression match
|
|
||||||
func (r *re) Match(exp string) bool {
|
|
||||||
r.sub = regexp.MustCompile(exp).FindStringSubmatch(r.str)
|
|
||||||
if r.sub != nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// fetchFile fetches a text file from URL
|
|
||||||
func fetchFile(URL string) io.Reader {
|
|
||||||
resp, err := http.Get(URL)
|
|
||||||
checkErr(err)
|
|
||||||
defer resp.Body.Close()
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
|
||||||
checkErr(err)
|
|
||||||
return strings.NewReader(string(body))
|
|
||||||
}
|
|
||||||
|
|
||||||
// readFile reads a text file from path
|
|
||||||
func readFile(path string) io.Reader {
|
|
||||||
file, err := os.Open(os.Args[1])
|
|
||||||
checkErr(err)
|
|
||||||
return file
|
|
||||||
}
|
|
||||||
|
|
||||||
func format(name, num, proto string) string {
|
|
||||||
name = strings.ToUpper(name)
|
|
||||||
// There are multiple entries for enosys and nosys, so comment them out.
|
|
||||||
nm := re{str: name}
|
|
||||||
if nm.Match(`^SYS_E?NOSYS$`) {
|
|
||||||
name = fmt.Sprintf("// %s", name)
|
|
||||||
}
|
|
||||||
if name == `SYS_SYS_EXIT` {
|
|
||||||
name = `SYS_EXIT`
|
|
||||||
}
|
|
||||||
return fmt.Sprintf(" %s = %s; // %s\n", name, num, proto)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// Get the OS (using GOOS_TARGET if it exist)
|
|
||||||
goos = os.Getenv("GOOS_TARGET")
|
|
||||||
if goos == "" {
|
|
||||||
goos = os.Getenv("GOOS")
|
|
||||||
}
|
|
||||||
// Get the architecture (using GOARCH_TARGET if it exists)
|
|
||||||
goarch = os.Getenv("GOARCH_TARGET")
|
|
||||||
if goarch == "" {
|
|
||||||
goarch = os.Getenv("GOARCH")
|
|
||||||
}
|
|
||||||
// Check if GOOS and GOARCH environment variables are defined
|
|
||||||
if goarch == "" || goos == "" {
|
|
||||||
fmt.Fprintf(os.Stderr, "GOARCH or GOOS not defined in environment\n")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
file := strings.TrimSpace(os.Args[1])
|
|
||||||
var syscalls io.Reader
|
|
||||||
if strings.HasPrefix(file, "https://") || strings.HasPrefix(file, "http://") {
|
|
||||||
// Download syscalls.master file
|
|
||||||
syscalls = fetchFile(file)
|
|
||||||
} else {
|
|
||||||
syscalls = readFile(file)
|
|
||||||
}
|
|
||||||
|
|
||||||
var text, line string
|
|
||||||
s := bufio.NewScanner(syscalls)
|
|
||||||
for s.Scan() {
|
|
||||||
t := re{str: line}
|
|
||||||
if t.Match(`^(.*)\\$`) {
|
|
||||||
// Handle continuation
|
|
||||||
line = t.sub[1]
|
|
||||||
line += strings.TrimLeft(s.Text(), " \t")
|
|
||||||
} else {
|
|
||||||
// New line
|
|
||||||
line = s.Text()
|
|
||||||
}
|
|
||||||
t = re{str: line}
|
|
||||||
if t.Match(`\\$`) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
t = re{str: line}
|
|
||||||
|
|
||||||
switch goos {
|
|
||||||
case "dragonfly":
|
|
||||||
if t.Match(`^([0-9]+)\s+STD\s+({ \S+\s+(\w+).*)$`) {
|
|
||||||
num, proto := t.sub[1], t.sub[2]
|
|
||||||
name := fmt.Sprintf("SYS_%s", t.sub[3])
|
|
||||||
text += format(name, num, proto)
|
|
||||||
}
|
|
||||||
case "freebsd":
|
|
||||||
if t.Match(`^([0-9]+)\s+\S+\s+(?:(?:NO)?STD|COMPAT10)\s+({ \S+\s+(\w+).*)$`) {
|
|
||||||
num, proto := t.sub[1], t.sub[2]
|
|
||||||
name := fmt.Sprintf("SYS_%s", t.sub[3])
|
|
||||||
text += format(name, num, proto)
|
|
||||||
}
|
|
||||||
case "openbsd":
|
|
||||||
if t.Match(`^([0-9]+)\s+STD\s+(NOLOCK\s+)?({ \S+\s+\*?(\w+).*)$`) {
|
|
||||||
num, proto, name := t.sub[1], t.sub[3], t.sub[4]
|
|
||||||
text += format(name, num, proto)
|
|
||||||
}
|
|
||||||
case "netbsd":
|
|
||||||
if t.Match(`^([0-9]+)\s+((STD)|(NOERR))\s+(RUMP\s+)?({\s+\S+\s*\*?\s*\|(\S+)\|(\S*)\|(\w+).*\s+})(\s+(\S+))?$`) {
|
|
||||||
num, proto, compat := t.sub[1], t.sub[6], t.sub[8]
|
|
||||||
name := t.sub[7] + "_" + t.sub[9]
|
|
||||||
if t.sub[11] != "" {
|
|
||||||
name = t.sub[7] + "_" + t.sub[11]
|
|
||||||
}
|
|
||||||
name = strings.ToUpper(name)
|
|
||||||
if compat == "" || compat == "13" || compat == "30" || compat == "50" {
|
|
||||||
text += fmt.Sprintf(" %s = %s; // %s\n", name, num, proto)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "darwin":
|
|
||||||
if t.Match(`^#define\s+SYS_(\w+)\s+([0-9]+)`) {
|
|
||||||
name, num := t.sub[1], t.sub[2]
|
|
||||||
name = strings.ToUpper(name)
|
|
||||||
text += fmt.Sprintf(" SYS_%s = %s;\n", name, num)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
fmt.Fprintf(os.Stderr, "unrecognized GOOS=%s\n", goos)
|
|
||||||
os.Exit(1)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err := s.Err()
|
|
||||||
checkErr(err)
|
|
||||||
|
|
||||||
fmt.Printf(template, cmdLine(), buildTags(), text)
|
|
||||||
}
|
|
||||||
|
|
||||||
const template = `// %s
|
|
||||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
|
||||||
|
|
||||||
// +build %s
|
|
||||||
|
|
||||||
package unix
|
|
||||||
|
|
||||||
const(
|
|
||||||
%s)`
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue