go.mod: Roll back to golang/mock 1.0.0
This commit is contained in:
parent
9ce337296b
commit
d7a38bbdf2
2
go.mod
2
go.mod
@ -9,7 +9,7 @@ require (
|
|||||||
github.com/go-lintpack/lintpack v0.5.2
|
github.com/go-lintpack/lintpack v0.5.2
|
||||||
github.com/go-ole/go-ole v1.2.1 // indirect
|
github.com/go-ole/go-ole v1.2.1 // indirect
|
||||||
github.com/gobwas/glob v0.2.3 // indirect
|
github.com/gobwas/glob v0.2.3 // indirect
|
||||||
github.com/golang/mock v1.1.1
|
github.com/golang/mock v1.0.0
|
||||||
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2
|
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2
|
||||||
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a
|
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a
|
||||||
github.com/golangci/errcheck v0.0.0-20181003203344-ef45e06d44b6
|
github.com/golangci/errcheck v0.0.0-20181003203344-ef45e06d44b6
|
||||||
|
4
go.sum
4
go.sum
@ -38,8 +38,8 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
|
|||||||
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
|
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
|
||||||
github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
|
github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
|
||||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||||
github.com/golang/mock v1.1.1 h1:G5FRp8JnTd7RQH5kemVNlMeyXQAztQ3mOWV95KxsXH8=
|
github.com/golang/mock v1.0.0 h1:HzcpUG60pfl43n9d2qbdi/3l1uKpAmxlfWEPWtV/QxM=
|
||||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
github.com/golang/mock v1.0.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 h1:23T5iq8rbUYlhpt5DB4XJkc6BU31uODLD1o1gKvZmD0=
|
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 h1:23T5iq8rbUYlhpt5DB4XJkc6BU31uODLD1o1gKvZmD0=
|
||||||
|
290
vendor/github.com/golang/mock/gomock/call.go
generated
vendored
290
vendor/github.com/golang/mock/gomock/call.go
generated
vendored
@ -17,7 +17,6 @@ package gomock
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,7 +28,7 @@ type Call struct {
|
|||||||
method string // the name of the method
|
method string // the name of the method
|
||||||
methodType reflect.Type // the type of the method
|
methodType reflect.Type // the type of the method
|
||||||
args []Matcher // the args
|
args []Matcher // the args
|
||||||
origin string // file and line number of call setup
|
rets []interface{} // the return values (if any)
|
||||||
|
|
||||||
preReqs []*Call // prerequisite calls
|
preReqs []*Call // prerequisite calls
|
||||||
|
|
||||||
@ -38,44 +37,9 @@ type Call struct {
|
|||||||
|
|
||||||
numCalls int // actual number made
|
numCalls int // actual number made
|
||||||
|
|
||||||
// actions are called when this Call is called. Each action gets the args and
|
// Actions
|
||||||
// can set the return values by returning a non-nil slice. Actions run in the
|
doFunc reflect.Value
|
||||||
// order they are created.
|
setArgs map[int]reflect.Value
|
||||||
actions []func([]interface{}) []interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newCall creates a *Call. It requires the method type in order to support
|
|
||||||
// unexported methods.
|
|
||||||
func newCall(t TestReporter, receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call {
|
|
||||||
if h, ok := t.(testHelper); ok {
|
|
||||||
h.Helper()
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: check arity, types.
|
|
||||||
margs := make([]Matcher, len(args))
|
|
||||||
for i, arg := range args {
|
|
||||||
if m, ok := arg.(Matcher); ok {
|
|
||||||
margs[i] = m
|
|
||||||
} else if arg == nil {
|
|
||||||
// Handle nil specially so that passing a nil interface value
|
|
||||||
// will match the typed nils of concrete args.
|
|
||||||
margs[i] = Nil()
|
|
||||||
} else {
|
|
||||||
margs[i] = Eq(arg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
origin := callerInfo(3)
|
|
||||||
actions := []func([]interface{}) []interface{}{func([]interface{}) []interface{} {
|
|
||||||
// Synthesize the zero value for each of the return args' types.
|
|
||||||
rets := make([]interface{}, methodType.NumOut())
|
|
||||||
for i := 0; i < methodType.NumOut(); i++ {
|
|
||||||
rets[i] = reflect.Zero(methodType.Out(i)).Interface()
|
|
||||||
}
|
|
||||||
return rets
|
|
||||||
}}
|
|
||||||
return &Call{t: t, receiver: receiver, method: method, methodType: methodType,
|
|
||||||
args: margs, origin: origin, minCalls: 1, maxCalls: 1, actions: actions}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AnyTimes allows the expectation to be called 0 or more times
|
// AnyTimes allows the expectation to be called 0 or more times
|
||||||
@ -104,69 +68,19 @@ func (c *Call) MaxTimes(n int) *Call {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// DoAndReturn declares the action to run when the call is matched.
|
// Do declares the action to run when the call is matched.
|
||||||
// The return values from this function are returned by the mocked function.
|
|
||||||
// It takes an interface{} argument to support n-arity functions.
|
|
||||||
func (c *Call) DoAndReturn(f interface{}) *Call {
|
|
||||||
// TODO: Check arity and types here, rather than dying badly elsewhere.
|
|
||||||
v := reflect.ValueOf(f)
|
|
||||||
|
|
||||||
c.addAction(func(args []interface{}) []interface{} {
|
|
||||||
vargs := make([]reflect.Value, len(args))
|
|
||||||
ft := v.Type()
|
|
||||||
for i := 0; i < len(args); i++ {
|
|
||||||
if args[i] != nil {
|
|
||||||
vargs[i] = reflect.ValueOf(args[i])
|
|
||||||
} else {
|
|
||||||
// Use the zero value for the arg.
|
|
||||||
vargs[i] = reflect.Zero(ft.In(i))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vrets := v.Call(vargs)
|
|
||||||
rets := make([]interface{}, len(vrets))
|
|
||||||
for i, ret := range vrets {
|
|
||||||
rets[i] = ret.Interface()
|
|
||||||
}
|
|
||||||
return rets
|
|
||||||
})
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do declares the action to run when the call is matched. The function's
|
|
||||||
// return values are ignored to retain backward compatibility. To use the
|
|
||||||
// return values call DoAndReturn.
|
|
||||||
// It takes an interface{} argument to support n-arity functions.
|
// It takes an interface{} argument to support n-arity functions.
|
||||||
func (c *Call) Do(f interface{}) *Call {
|
func (c *Call) Do(f interface{}) *Call {
|
||||||
// TODO: Check arity and types here, rather than dying badly elsewhere.
|
// TODO: Check arity and types here, rather than dying badly elsewhere.
|
||||||
v := reflect.ValueOf(f)
|
c.doFunc = reflect.ValueOf(f)
|
||||||
|
|
||||||
c.addAction(func(args []interface{}) []interface{} {
|
|
||||||
vargs := make([]reflect.Value, len(args))
|
|
||||||
ft := v.Type()
|
|
||||||
for i := 0; i < len(args); i++ {
|
|
||||||
if args[i] != nil {
|
|
||||||
vargs[i] = reflect.ValueOf(args[i])
|
|
||||||
} else {
|
|
||||||
// Use the zero value for the arg.
|
|
||||||
vargs[i] = reflect.Zero(ft.In(i))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
v.Call(vargs)
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return declares the values to be returned by the mocked function call.
|
|
||||||
func (c *Call) Return(rets ...interface{}) *Call {
|
func (c *Call) Return(rets ...interface{}) *Call {
|
||||||
if h, ok := c.t.(testHelper); ok {
|
|
||||||
h.Helper()
|
|
||||||
}
|
|
||||||
|
|
||||||
mt := c.methodType
|
mt := c.methodType
|
||||||
if len(rets) != mt.NumOut() {
|
if len(rets) != mt.NumOut() {
|
||||||
c.t.Fatalf("wrong number of arguments to Return for %T.%v: got %d, want %d [%s]",
|
c.t.Fatalf("wrong number of arguments to Return for %T.%v: got %d, want %d",
|
||||||
c.receiver, c.method, len(rets), mt.NumOut(), c.origin)
|
c.receiver, c.method, len(rets), mt.NumOut())
|
||||||
}
|
}
|
||||||
for i, ret := range rets {
|
for i, ret := range rets {
|
||||||
if got, want := reflect.TypeOf(ret), mt.Out(i); got == want {
|
if got, want := reflect.TypeOf(ret), mt.Out(i); got == want {
|
||||||
@ -177,8 +91,8 @@ func (c *Call) Return(rets ...interface{}) *Call {
|
|||||||
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
|
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
|
||||||
// ok
|
// ok
|
||||||
default:
|
default:
|
||||||
c.t.Fatalf("argument %d to Return for %T.%v is nil, but %v is not nillable [%s]",
|
c.t.Fatalf("argument %d to Return for %T.%v is nil, but %v is not nillable",
|
||||||
i, c.receiver, c.method, want, c.origin)
|
i, c.receiver, c.method, want)
|
||||||
}
|
}
|
||||||
} else if got.AssignableTo(want) {
|
} else if got.AssignableTo(want) {
|
||||||
// Assignable type relation. Make the assignment now so that the generated code
|
// Assignable type relation. Make the assignment now so that the generated code
|
||||||
@ -187,38 +101,31 @@ func (c *Call) Return(rets ...interface{}) *Call {
|
|||||||
v.Set(reflect.ValueOf(ret))
|
v.Set(reflect.ValueOf(ret))
|
||||||
rets[i] = v.Interface()
|
rets[i] = v.Interface()
|
||||||
} else {
|
} else {
|
||||||
c.t.Fatalf("wrong type of argument %d to Return for %T.%v: %v is not assignable to %v [%s]",
|
c.t.Fatalf("wrong type of argument %d to Return for %T.%v: %v is not assignable to %v",
|
||||||
i, c.receiver, c.method, got, want, c.origin)
|
i, c.receiver, c.method, got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.addAction(func([]interface{}) []interface{} {
|
c.rets = rets
|
||||||
return rets
|
|
||||||
})
|
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Times declares the exact number of times a function call is expected to be executed.
|
|
||||||
func (c *Call) Times(n int) *Call {
|
func (c *Call) Times(n int) *Call {
|
||||||
c.minCalls, c.maxCalls = n, n
|
c.minCalls, c.maxCalls = n, n
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetArg declares an action that will set the nth argument's value,
|
// SetArg declares an action that will set the nth argument's value,
|
||||||
// indirected through a pointer. Or, in the case of a slice, SetArg
|
// indirected through a pointer.
|
||||||
// will copy value's elements into the nth argument.
|
|
||||||
func (c *Call) SetArg(n int, value interface{}) *Call {
|
func (c *Call) SetArg(n int, value interface{}) *Call {
|
||||||
if h, ok := c.t.(testHelper); ok {
|
if c.setArgs == nil {
|
||||||
h.Helper()
|
c.setArgs = make(map[int]reflect.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
mt := c.methodType
|
mt := c.methodType
|
||||||
// TODO: This will break on variadic methods.
|
// TODO: This will break on variadic methods.
|
||||||
// We will need to check those at invocation time.
|
// We will need to check those at invocation time.
|
||||||
if n < 0 || n >= mt.NumIn() {
|
if n < 0 || n >= mt.NumIn() {
|
||||||
c.t.Fatalf("SetArg(%d, ...) called for a method with %d args [%s]",
|
c.t.Fatalf("SetArg(%d, ...) called for a method with %d args", n, mt.NumIn())
|
||||||
n, mt.NumIn(), c.origin)
|
|
||||||
}
|
}
|
||||||
// Permit setting argument through an interface.
|
// Permit setting argument through an interface.
|
||||||
// In the interface case, we don't (nay, can't) check the type here.
|
// In the interface case, we don't (nay, can't) check the type here.
|
||||||
@ -227,28 +134,14 @@ func (c *Call) SetArg(n int, value interface{}) *Call {
|
|||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
dt := at.Elem()
|
dt := at.Elem()
|
||||||
if vt := reflect.TypeOf(value); !vt.AssignableTo(dt) {
|
if vt := reflect.TypeOf(value); !vt.AssignableTo(dt) {
|
||||||
c.t.Fatalf("SetArg(%d, ...) argument is a %v, not assignable to %v [%s]",
|
c.t.Fatalf("SetArg(%d, ...) argument is a %v, not assignable to %v", n, vt, dt)
|
||||||
n, vt, dt, c.origin)
|
|
||||||
}
|
}
|
||||||
case reflect.Interface:
|
case reflect.Interface:
|
||||||
// nothing to do
|
// nothing to do
|
||||||
case reflect.Slice:
|
|
||||||
// nothing to do
|
|
||||||
default:
|
default:
|
||||||
c.t.Fatalf("SetArg(%d, ...) referring to argument of non-pointer non-interface non-slice type %v [%s]",
|
c.t.Fatalf("SetArg(%d, ...) referring to argument of non-pointer non-interface type %v", n, at)
|
||||||
n, at, c.origin)
|
|
||||||
}
|
}
|
||||||
|
c.setArgs[n] = reflect.ValueOf(value)
|
||||||
c.addAction(func(args []interface{}) []interface{} {
|
|
||||||
v := reflect.ValueOf(value)
|
|
||||||
switch reflect.TypeOf(args[n]).Kind() {
|
|
||||||
case reflect.Slice:
|
|
||||||
setSlice(args[n], v)
|
|
||||||
default:
|
|
||||||
reflect.ValueOf(args[n]).Elem().Set(v)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,12 +157,8 @@ func (c *Call) isPreReq(other *Call) bool {
|
|||||||
|
|
||||||
// After declares that the call may only match after preReq has been exhausted.
|
// After declares that the call may only match after preReq has been exhausted.
|
||||||
func (c *Call) After(preReq *Call) *Call {
|
func (c *Call) After(preReq *Call) *Call {
|
||||||
if h, ok := c.t.(testHelper); ok {
|
|
||||||
h.Helper()
|
|
||||||
}
|
|
||||||
|
|
||||||
if c == preReq {
|
if c == preReq {
|
||||||
c.t.Fatalf("A call isn't allowed to be its own prerequisite")
|
c.t.Fatalf("A call isn't allowed to be it's own prerequisite")
|
||||||
}
|
}
|
||||||
if preReq.isPreReq(c) {
|
if preReq.isPreReq(c) {
|
||||||
c.t.Fatalf("Loop in call order: %v is a prerequisite to %v (possibly indirectly).", c, preReq)
|
c.t.Fatalf("Loop in call order: %v is a prerequisite to %v (possibly indirectly).", c, preReq)
|
||||||
@ -279,7 +168,7 @@ func (c *Call) After(preReq *Call) *Call {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the minimum number of calls have been made.
|
// Returns true iff the minimum number of calls have been made.
|
||||||
func (c *Call) satisfied() bool {
|
func (c *Call) satisfied() bool {
|
||||||
return c.numCalls >= c.minCalls
|
return c.numCalls >= c.minCalls
|
||||||
}
|
}
|
||||||
@ -295,108 +184,31 @@ func (c *Call) String() string {
|
|||||||
args[i] = arg.String()
|
args[i] = arg.String()
|
||||||
}
|
}
|
||||||
arguments := strings.Join(args, ", ")
|
arguments := strings.Join(args, ", ")
|
||||||
return fmt.Sprintf("%T.%v(%s) %s", c.receiver, c.method, arguments, c.origin)
|
return fmt.Sprintf("%T.%v(%s)", c.receiver, c.method, arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests if the given call matches the expected call.
|
// Tests if the given call matches the expected call.
|
||||||
// If yes, returns nil. If no, returns error with message explaining why it does not match.
|
func (c *Call) matches(args []interface{}) bool {
|
||||||
func (c *Call) matches(args []interface{}) error {
|
|
||||||
if !c.methodType.IsVariadic() {
|
|
||||||
if len(args) != len(c.args) {
|
if len(args) != len(c.args) {
|
||||||
return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: %d",
|
return false
|
||||||
c.origin, len(args), len(c.args))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, m := range c.args {
|
for i, m := range c.args {
|
||||||
if !m.Matches(args[i]) {
|
if !m.Matches(args[i]) {
|
||||||
return fmt.Errorf("Expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v",
|
return false
|
||||||
c.origin, strconv.Itoa(i), args[i], m)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if len(c.args) < c.methodType.NumIn()-1 {
|
|
||||||
return fmt.Errorf("Expected call at %s has the wrong number of matchers. Got: %d, want: %d",
|
|
||||||
c.origin, len(c.args), c.methodType.NumIn()-1)
|
|
||||||
}
|
|
||||||
if len(c.args) != c.methodType.NumIn() && len(args) != len(c.args) {
|
|
||||||
return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: %d",
|
|
||||||
c.origin, len(args), len(c.args))
|
|
||||||
}
|
|
||||||
if len(args) < len(c.args)-1 {
|
|
||||||
return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: greater than or equal to %d",
|
|
||||||
c.origin, len(args), len(c.args)-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, m := range c.args {
|
|
||||||
if i < c.methodType.NumIn()-1 {
|
|
||||||
// Non-variadic args
|
|
||||||
if !m.Matches(args[i]) {
|
|
||||||
return fmt.Errorf("Expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v",
|
|
||||||
c.origin, strconv.Itoa(i), args[i], m)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// The last arg has a possibility of a variadic argument, so let it branch
|
|
||||||
|
|
||||||
// sample: Foo(a int, b int, c ...int)
|
|
||||||
if i < len(c.args) && i < len(args) {
|
|
||||||
if m.Matches(args[i]) {
|
|
||||||
// Got Foo(a, b, c) want Foo(matcherA, matcherB, gomock.Any())
|
|
||||||
// Got Foo(a, b, c) want Foo(matcherA, matcherB, someSliceMatcher)
|
|
||||||
// Got Foo(a, b, c) want Foo(matcherA, matcherB, matcherC)
|
|
||||||
// Got Foo(a, b) want Foo(matcherA, matcherB)
|
|
||||||
// Got Foo(a, b, c, d) want Foo(matcherA, matcherB, matcherC, matcherD)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The number of actual args don't match the number of matchers,
|
|
||||||
// or the last matcher is a slice and the last arg is not.
|
|
||||||
// If this function still matches it is because the last matcher
|
|
||||||
// matches all the remaining arguments or the lack of any.
|
|
||||||
// Convert the remaining arguments, if any, into a slice of the
|
|
||||||
// expected type.
|
|
||||||
vargsType := c.methodType.In(c.methodType.NumIn() - 1)
|
|
||||||
vargs := reflect.MakeSlice(vargsType, 0, len(args)-i)
|
|
||||||
for _, arg := range args[i:] {
|
|
||||||
vargs = reflect.Append(vargs, reflect.ValueOf(arg))
|
|
||||||
}
|
|
||||||
if m.Matches(vargs.Interface()) {
|
|
||||||
// Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, gomock.Any())
|
|
||||||
// Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, someSliceMatcher)
|
|
||||||
// Got Foo(a, b) want Foo(matcherA, matcherB, gomock.Any())
|
|
||||||
// Got Foo(a, b) want Foo(matcherA, matcherB, someEmptySliceMatcher)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
// Wrong number of matchers or not match. Fail.
|
|
||||||
// Got Foo(a, b) want Foo(matcherA, matcherB, matcherC, matcherD)
|
|
||||||
// Got Foo(a, b, c) want Foo(matcherA, matcherB, matcherC, matcherD)
|
|
||||||
// Got Foo(a, b, c, d) want Foo(matcherA, matcherB, matcherC, matcherD, matcherE)
|
|
||||||
// Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, matcherC, matcherD)
|
|
||||||
// Got Foo(a, b, c) want Foo(matcherA, matcherB)
|
|
||||||
return fmt.Errorf("Expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v",
|
|
||||||
c.origin, strconv.Itoa(i), args[i:], c.args[i])
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that all prerequisite calls have been satisfied.
|
// Check that all prerequisite calls have been satisfied.
|
||||||
for _, preReqCall := range c.preReqs {
|
for _, preReqCall := range c.preReqs {
|
||||||
if !preReqCall.satisfied() {
|
if !preReqCall.satisfied() {
|
||||||
return fmt.Errorf("Expected call at %s doesn't have a prerequisite call satisfied:\n%v\nshould be called before:\n%v",
|
return false
|
||||||
c.origin, preReqCall, c)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the call is not exhausted.
|
return true
|
||||||
if c.exhausted() {
|
|
||||||
return fmt.Errorf("Expected call at %s has already been called the max number of times.", c.origin)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
// dropPrereqs tells the expected Call to not re-check prerequite calls any
|
||||||
}
|
|
||||||
|
|
||||||
// dropPrereqs tells the expected Call to not re-check prerequisite calls any
|
|
||||||
// longer, and to return its current set.
|
// longer, and to return its current set.
|
||||||
func (c *Call) dropPrereqs() (preReqs []*Call) {
|
func (c *Call) dropPrereqs() (preReqs []*Call) {
|
||||||
preReqs = c.preReqs
|
preReqs = c.preReqs
|
||||||
@ -404,9 +216,38 @@ func (c *Call) dropPrereqs() (preReqs []*Call) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Call) call(args []interface{}) []func([]interface{}) []interface{} {
|
func (c *Call) call(args []interface{}) (rets []interface{}, action func()) {
|
||||||
c.numCalls++
|
c.numCalls++
|
||||||
return c.actions
|
|
||||||
|
// Actions
|
||||||
|
if c.doFunc.IsValid() {
|
||||||
|
doArgs := make([]reflect.Value, len(args))
|
||||||
|
ft := c.doFunc.Type()
|
||||||
|
for i := 0; i < len(args); i++ {
|
||||||
|
if args[i] != nil {
|
||||||
|
doArgs[i] = reflect.ValueOf(args[i])
|
||||||
|
} else {
|
||||||
|
// Use the zero value for the arg.
|
||||||
|
doArgs[i] = reflect.Zero(ft.In(i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
action = func() { c.doFunc.Call(doArgs) }
|
||||||
|
}
|
||||||
|
for n, v := range c.setArgs {
|
||||||
|
reflect.ValueOf(args[n]).Elem().Set(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
rets = c.rets
|
||||||
|
if rets == nil {
|
||||||
|
// Synthesize the zero value for each of the return args' types.
|
||||||
|
mt := c.methodType
|
||||||
|
rets = make([]interface{}, mt.NumOut())
|
||||||
|
for i := 0; i < mt.NumOut(); i++ {
|
||||||
|
rets[i] = reflect.Zero(mt.Out(i)).Interface()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// InOrder declares that the given calls should occur in order.
|
// InOrder declares that the given calls should occur in order.
|
||||||
@ -415,14 +256,3 @@ func InOrder(calls ...*Call) {
|
|||||||
calls[i].After(calls[i-1])
|
calls[i].After(calls[i-1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setSlice(arg interface{}, v reflect.Value) {
|
|
||||||
va := reflect.ValueOf(arg)
|
|
||||||
for i := 0; i < v.Len(); i++ {
|
|
||||||
va.Index(i).Set(v.Index(i))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Call) addAction(action func([]interface{}) []interface{}) {
|
|
||||||
c.actions = append(c.actions, action)
|
|
||||||
}
|
|
||||||
|
106
vendor/github.com/golang/mock/gomock/callset.go
generated
vendored
106
vendor/github.com/golang/mock/gomock/callset.go
generated
vendored
@ -14,95 +14,63 @@
|
|||||||
|
|
||||||
package gomock
|
package gomock
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
// callSet represents a set of expected calls, indexed by receiver and method
|
// callSet represents a set of expected calls, indexed by receiver and method
|
||||||
// name.
|
// name.
|
||||||
type callSet struct {
|
type callSet map[interface{}]map[string][]*Call
|
||||||
// Calls that are still expected.
|
|
||||||
expected map[callSetKey][]*Call
|
|
||||||
// Calls that have been exhausted.
|
|
||||||
exhausted map[callSetKey][]*Call
|
|
||||||
}
|
|
||||||
|
|
||||||
// callSetKey is the key in the maps in callSet
|
|
||||||
type callSetKey struct {
|
|
||||||
receiver interface{}
|
|
||||||
fname string
|
|
||||||
}
|
|
||||||
|
|
||||||
func newCallSet() *callSet {
|
|
||||||
return &callSet{make(map[callSetKey][]*Call), make(map[callSetKey][]*Call)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add adds a new expected call.
|
// Add adds a new expected call.
|
||||||
func (cs callSet) Add(call *Call) {
|
func (cs callSet) Add(call *Call) {
|
||||||
key := callSetKey{call.receiver, call.method}
|
methodMap, ok := cs[call.receiver]
|
||||||
m := cs.expected
|
if !ok {
|
||||||
if call.exhausted() {
|
methodMap = make(map[string][]*Call)
|
||||||
m = cs.exhausted
|
cs[call.receiver] = methodMap
|
||||||
}
|
}
|
||||||
m[key] = append(m[key], call)
|
methodMap[call.method] = append(methodMap[call.method], call)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove removes an expected call.
|
// Remove removes an expected call.
|
||||||
func (cs callSet) Remove(call *Call) {
|
func (cs callSet) Remove(call *Call) {
|
||||||
key := callSetKey{call.receiver, call.method}
|
methodMap, ok := cs[call.receiver]
|
||||||
calls := cs.expected[key]
|
if !ok {
|
||||||
for i, c := range calls {
|
return
|
||||||
|
}
|
||||||
|
sl := methodMap[call.method]
|
||||||
|
for i, c := range sl {
|
||||||
if c == call {
|
if c == call {
|
||||||
// maintain order for remaining calls
|
// quick removal; we don't need to maintain call order
|
||||||
cs.expected[key] = append(calls[:i], calls[i+1:]...)
|
if len(sl) > 1 {
|
||||||
cs.exhausted[key] = append(cs.exhausted[key], call)
|
sl[i] = sl[len(sl)-1]
|
||||||
|
}
|
||||||
|
methodMap[call.method] = sl[:len(sl)-1]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindMatch searches for a matching call. Returns error with explanation message if no call matched.
|
// FindMatch searches for a matching call. Returns nil if no call matched.
|
||||||
func (cs callSet) FindMatch(receiver interface{}, method string, args []interface{}) (*Call, error) {
|
func (cs callSet) FindMatch(receiver interface{}, method string, args []interface{}) *Call {
|
||||||
key := callSetKey{receiver, method}
|
methodMap, ok := cs[receiver]
|
||||||
|
if !ok {
|
||||||
// Search through the expected calls.
|
return nil
|
||||||
expected := cs.expected[key]
|
|
||||||
var callsErrors bytes.Buffer
|
|
||||||
for _, call := range expected {
|
|
||||||
err := call.matches(args)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(&callsErrors, "\n%v", err)
|
|
||||||
} else {
|
|
||||||
return call, nil
|
|
||||||
}
|
}
|
||||||
|
calls, ok := methodMap[method]
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we haven't found a match then search through the exhausted calls so we
|
// Search through the unordered set of calls expected on a method on a
|
||||||
// get useful error messages.
|
// receiver.
|
||||||
exhausted := cs.exhausted[key]
|
|
||||||
for _, call := range exhausted {
|
|
||||||
if err := call.matches(args); err != nil {
|
|
||||||
fmt.Fprintf(&callsErrors, "\n%v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(expected)+len(exhausted) == 0 {
|
|
||||||
fmt.Fprintf(&callsErrors, "there are no expected calls of the method %q for that receiver", method)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, fmt.Errorf(callsErrors.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Failures returns the calls that are not satisfied.
|
|
||||||
func (cs callSet) Failures() []*Call {
|
|
||||||
failures := make([]*Call, 0, len(cs.expected))
|
|
||||||
for _, calls := range cs.expected {
|
|
||||||
for _, call := range calls {
|
for _, call := range calls {
|
||||||
if !call.satisfied() {
|
// A call should not normally still be here if exhausted,
|
||||||
failures = append(failures, call)
|
// but it can happen if, for instance, .Times(0) was used.
|
||||||
|
// Pretend the call doesn't match.
|
||||||
|
if call.exhausted() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if call.matches(args) {
|
||||||
|
return call
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return failures
|
return nil
|
||||||
}
|
}
|
||||||
|
116
vendor/github.com/golang/mock/gomock/controller.go
generated
vendored
116
vendor/github.com/golang/mock/gomock/controller.go
generated
vendored
@ -57,9 +57,7 @@ package gomock
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"golang.org/x/net/context"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -76,40 +74,17 @@ type TestReporter interface {
|
|||||||
type Controller struct {
|
type Controller struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
t TestReporter
|
t TestReporter
|
||||||
expectedCalls *callSet
|
expectedCalls callSet
|
||||||
finished bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewController(t TestReporter) *Controller {
|
func NewController(t TestReporter) *Controller {
|
||||||
return &Controller{
|
return &Controller{
|
||||||
t: t,
|
t: t,
|
||||||
expectedCalls: newCallSet(),
|
expectedCalls: make(callSet),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type cancelReporter struct {
|
|
||||||
t TestReporter
|
|
||||||
cancel func()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *cancelReporter) Errorf(format string, args ...interface{}) { r.t.Errorf(format, args...) }
|
|
||||||
func (r *cancelReporter) Fatalf(format string, args ...interface{}) {
|
|
||||||
defer r.cancel()
|
|
||||||
r.t.Fatalf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithContext returns a new Controller and a Context, which is cancelled on any
|
|
||||||
// fatal failure.
|
|
||||||
func WithContext(ctx context.Context, t TestReporter) (*Controller, context.Context) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
return NewController(&cancelReporter{t, cancel}), ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ...interface{}) *Call {
|
func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ...interface{}) *Call {
|
||||||
if h, ok := ctrl.t.(testHelper); ok {
|
|
||||||
h.Helper()
|
|
||||||
}
|
|
||||||
|
|
||||||
recv := reflect.ValueOf(receiver)
|
recv := reflect.ValueOf(receiver)
|
||||||
for i := 0; i < recv.Type().NumMethod(); i++ {
|
for i := 0; i < recv.Type().NumMethod(); i++ {
|
||||||
if recv.Type().Method(i).Name == method {
|
if recv.Type().Method(i).Name == method {
|
||||||
@ -117,37 +92,41 @@ func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ...
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctrl.t.Fatalf("gomock: failed finding method %s on %T", method, receiver)
|
ctrl.t.Fatalf("gomock: failed finding method %s on %T", method, receiver)
|
||||||
panic("unreachable")
|
// In case t.Fatalf does not panic.
|
||||||
|
panic(fmt.Sprintf("gomock: failed finding method %s on %T", method, receiver))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctrl *Controller) RecordCallWithMethodType(receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call {
|
func (ctrl *Controller) RecordCallWithMethodType(receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call {
|
||||||
if h, ok := ctrl.t.(testHelper); ok {
|
// TODO: check arity, types.
|
||||||
h.Helper()
|
margs := make([]Matcher, len(args))
|
||||||
|
for i, arg := range args {
|
||||||
|
if m, ok := arg.(Matcher); ok {
|
||||||
|
margs[i] = m
|
||||||
|
} else if arg == nil {
|
||||||
|
// Handle nil specially so that passing a nil interface value
|
||||||
|
// will match the typed nils of concrete args.
|
||||||
|
margs[i] = Nil()
|
||||||
|
} else {
|
||||||
|
margs[i] = Eq(arg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
call := newCall(ctrl.t, receiver, method, methodType, args...)
|
|
||||||
|
|
||||||
ctrl.mu.Lock()
|
ctrl.mu.Lock()
|
||||||
defer ctrl.mu.Unlock()
|
defer ctrl.mu.Unlock()
|
||||||
ctrl.expectedCalls.Add(call)
|
|
||||||
|
|
||||||
|
call := &Call{t: ctrl.t, receiver: receiver, method: method, methodType: methodType, args: margs, minCalls: 1, maxCalls: 1}
|
||||||
|
|
||||||
|
ctrl.expectedCalls.Add(call)
|
||||||
return call
|
return call
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctrl *Controller) Call(receiver interface{}, method string, args ...interface{}) []interface{} {
|
func (ctrl *Controller) Call(receiver interface{}, method string, args ...interface{}) []interface{} {
|
||||||
if h, ok := ctrl.t.(testHelper); ok {
|
|
||||||
h.Helper()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nest this code so we can use defer to make sure the lock is released.
|
|
||||||
actions := func() []func([]interface{}) []interface{} {
|
|
||||||
ctrl.mu.Lock()
|
ctrl.mu.Lock()
|
||||||
defer ctrl.mu.Unlock()
|
defer ctrl.mu.Unlock()
|
||||||
|
|
||||||
expected, err := ctrl.expectedCalls.FindMatch(receiver, method, args)
|
expected := ctrl.expectedCalls.FindMatch(receiver, method, args)
|
||||||
if err != nil {
|
if expected == nil {
|
||||||
origin := callerInfo(2)
|
ctrl.t.Fatalf("no matching expected call: %T.%v(%v)", receiver, method, args)
|
||||||
ctrl.t.Fatalf("Unexpected call to %T.%v(%v) at %s because: %s", receiver, method, args, origin, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Two things happen here:
|
// Two things happen here:
|
||||||
@ -158,36 +137,28 @@ func (ctrl *Controller) Call(receiver interface{}, method string, args ...interf
|
|||||||
ctrl.expectedCalls.Remove(preReqCall)
|
ctrl.expectedCalls.Remove(preReqCall)
|
||||||
}
|
}
|
||||||
|
|
||||||
actions := expected.call(args)
|
rets, action := expected.call(args)
|
||||||
if expected.exhausted() {
|
if expected.exhausted() {
|
||||||
ctrl.expectedCalls.Remove(expected)
|
ctrl.expectedCalls.Remove(expected)
|
||||||
}
|
}
|
||||||
return actions
|
|
||||||
}()
|
|
||||||
|
|
||||||
var rets []interface{}
|
// Don't hold the lock while doing the call's action (if any)
|
||||||
for _, action := range actions {
|
// so that actions may execute concurrently.
|
||||||
if r := action(args); r != nil {
|
// We use the deferred Unlock to capture any panics that happen above;
|
||||||
rets = r
|
// here we add a deferred Lock to balance it.
|
||||||
}
|
ctrl.mu.Unlock()
|
||||||
|
defer ctrl.mu.Lock()
|
||||||
|
if action != nil {
|
||||||
|
action()
|
||||||
}
|
}
|
||||||
|
|
||||||
return rets
|
return rets
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctrl *Controller) Finish() {
|
func (ctrl *Controller) Finish() {
|
||||||
if h, ok := ctrl.t.(testHelper); ok {
|
|
||||||
h.Helper()
|
|
||||||
}
|
|
||||||
|
|
||||||
ctrl.mu.Lock()
|
ctrl.mu.Lock()
|
||||||
defer ctrl.mu.Unlock()
|
defer ctrl.mu.Unlock()
|
||||||
|
|
||||||
if ctrl.finished {
|
|
||||||
ctrl.t.Fatalf("Controller.Finish was called more than once. It has to be called exactly once.")
|
|
||||||
}
|
|
||||||
ctrl.finished = true
|
|
||||||
|
|
||||||
// If we're currently panicking, probably because this is a deferred call,
|
// If we're currently panicking, probably because this is a deferred call,
|
||||||
// pass through the panic.
|
// pass through the panic.
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
@ -195,23 +166,18 @@ func (ctrl *Controller) Finish() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that all remaining expected calls are satisfied.
|
// Check that all remaining expected calls are satisfied.
|
||||||
failures := ctrl.expectedCalls.Failures()
|
failures := false
|
||||||
for _, call := range failures {
|
for _, methodMap := range ctrl.expectedCalls {
|
||||||
|
for _, calls := range methodMap {
|
||||||
|
for _, call := range calls {
|
||||||
|
if !call.satisfied() {
|
||||||
ctrl.t.Errorf("missing call(s) to %v", call)
|
ctrl.t.Errorf("missing call(s) to %v", call)
|
||||||
|
failures = true
|
||||||
}
|
}
|
||||||
if len(failures) != 0 {
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if failures {
|
||||||
ctrl.t.Fatalf("aborting test due to missing call(s)")
|
ctrl.t.Fatalf("aborting test due to missing call(s)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func callerInfo(skip int) string {
|
|
||||||
if _, file, line, ok := runtime.Caller(skip + 1); ok {
|
|
||||||
return fmt.Sprintf("%s:%d", file, line)
|
|
||||||
}
|
|
||||||
return "unknown file"
|
|
||||||
}
|
|
||||||
|
|
||||||
type testHelper interface {
|
|
||||||
TestReporter
|
|
||||||
Helper()
|
|
||||||
}
|
|
||||||
|
3
vendor/golang.org/x/net/AUTHORS
generated
vendored
3
vendor/golang.org/x/net/AUTHORS
generated
vendored
@ -1,3 +0,0 @@
|
|||||||
# This source code refers to The Go Authors for copyright purposes.
|
|
||||||
# The master list of authors is in the main Go distribution,
|
|
||||||
# visible at http://tip.golang.org/AUTHORS.
|
|
3
vendor/golang.org/x/net/CONTRIBUTORS
generated
vendored
3
vendor/golang.org/x/net/CONTRIBUTORS
generated
vendored
@ -1,3 +0,0 @@
|
|||||||
# This source code was written by the Go contributors.
|
|
||||||
# The master list of contributors is in the main Go distribution,
|
|
||||||
# visible at http://tip.golang.org/CONTRIBUTORS.
|
|
27
vendor/golang.org/x/net/LICENSE
generated
vendored
27
vendor/golang.org/x/net/LICENSE
generated
vendored
@ -1,27 +0,0 @@
|
|||||||
Copyright (c) 2009 The Go Authors. All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are
|
|
||||||
met:
|
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
|
||||||
in the documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
* Neither the name of Google Inc. nor the names of its
|
|
||||||
contributors may be used to endorse or promote products derived from
|
|
||||||
this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
22
vendor/golang.org/x/net/PATENTS
generated
vendored
22
vendor/golang.org/x/net/PATENTS
generated
vendored
@ -1,22 +0,0 @@
|
|||||||
Additional IP Rights Grant (Patents)
|
|
||||||
|
|
||||||
"This implementation" means the copyrightable works distributed by
|
|
||||||
Google as part of the Go project.
|
|
||||||
|
|
||||||
Google 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,
|
|
||||||
transfer and otherwise run, modify and propagate the contents of this
|
|
||||||
implementation of Go, where such license applies only to those patent
|
|
||||||
claims, both currently owned or controlled by Google and acquired in
|
|
||||||
the future, licensable by Google that are necessarily infringed by this
|
|
||||||
implementation of Go. This grant does not include claims that would be
|
|
||||||
infringed only as a consequence of further modification of this
|
|
||||||
implementation. If you or your agent or exclusive licensee institute or
|
|
||||||
order or agree to the institution of patent litigation against any
|
|
||||||
entity (including a cross-claim or counterclaim in a lawsuit) alleging
|
|
||||||
that this implementation of Go or any code incorporated within this
|
|
||||||
implementation of Go constitutes direct or contributory patent
|
|
||||||
infringement, or inducement of patent infringement, then any patent
|
|
||||||
rights granted to you under this License for this implementation of Go
|
|
||||||
shall terminate as of the date such litigation is filed.
|
|
56
vendor/golang.org/x/net/context/context.go
generated
vendored
56
vendor/golang.org/x/net/context/context.go
generated
vendored
@ -1,56 +0,0 @@
|
|||||||
// Copyright 2014 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.
|
|
||||||
|
|
||||||
// Package context defines the Context type, which carries deadlines,
|
|
||||||
// cancelation signals, and other request-scoped values across API boundaries
|
|
||||||
// and between processes.
|
|
||||||
// As of Go 1.7 this package is available in the standard library under the
|
|
||||||
// name context. https://golang.org/pkg/context.
|
|
||||||
//
|
|
||||||
// Incoming requests to a server should create a Context, and outgoing calls to
|
|
||||||
// servers should accept a Context. The chain of function calls between must
|
|
||||||
// propagate the Context, optionally replacing it with a modified copy created
|
|
||||||
// using WithDeadline, WithTimeout, WithCancel, or WithValue.
|
|
||||||
//
|
|
||||||
// Programs that use Contexts should follow these rules to keep interfaces
|
|
||||||
// consistent across packages and enable static analysis tools to check context
|
|
||||||
// propagation:
|
|
||||||
//
|
|
||||||
// Do not store Contexts inside a struct type; instead, pass a Context
|
|
||||||
// explicitly to each function that needs it. The Context should be the first
|
|
||||||
// parameter, typically named ctx:
|
|
||||||
//
|
|
||||||
// func DoSomething(ctx context.Context, arg Arg) error {
|
|
||||||
// // ... use ctx ...
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Do not pass a nil Context, even if a function permits it. Pass context.TODO
|
|
||||||
// if you are unsure about which Context to use.
|
|
||||||
//
|
|
||||||
// Use context Values only for request-scoped data that transits processes and
|
|
||||||
// APIs, not for passing optional parameters to functions.
|
|
||||||
//
|
|
||||||
// The same Context may be passed to functions running in different goroutines;
|
|
||||||
// Contexts are safe for simultaneous use by multiple goroutines.
|
|
||||||
//
|
|
||||||
// See http://blog.golang.org/context for example code for a server that uses
|
|
||||||
// Contexts.
|
|
||||||
package context // import "golang.org/x/net/context"
|
|
||||||
|
|
||||||
// Background returns a non-nil, empty Context. It is never canceled, has no
|
|
||||||
// values, and has no deadline. It is typically used by the main function,
|
|
||||||
// initialization, and tests, and as the top-level Context for incoming
|
|
||||||
// requests.
|
|
||||||
func Background() Context {
|
|
||||||
return background
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO returns a non-nil, empty Context. Code should use context.TODO when
|
|
||||||
// it's unclear which Context to use or it is not yet available (because the
|
|
||||||
// surrounding function has not yet been extended to accept a Context
|
|
||||||
// parameter). TODO is recognized by static analysis tools that determine
|
|
||||||
// whether Contexts are propagated correctly in a program.
|
|
||||||
func TODO() Context {
|
|
||||||
return todo
|
|
||||||
}
|
|
72
vendor/golang.org/x/net/context/go17.go
generated
vendored
72
vendor/golang.org/x/net/context/go17.go
generated
vendored
@ -1,72 +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 go1.7
|
|
||||||
|
|
||||||
package context
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context" // standard library's context, as of Go 1.7
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
todo = context.TODO()
|
|
||||||
background = context.Background()
|
|
||||||
)
|
|
||||||
|
|
||||||
// Canceled is the error returned by Context.Err when the context is canceled.
|
|
||||||
var Canceled = context.Canceled
|
|
||||||
|
|
||||||
// DeadlineExceeded is the error returned by Context.Err when the context's
|
|
||||||
// deadline passes.
|
|
||||||
var DeadlineExceeded = context.DeadlineExceeded
|
|
||||||
|
|
||||||
// WithCancel returns a copy of parent with a new Done channel. The returned
|
|
||||||
// context's Done channel is closed when the returned cancel function is called
|
|
||||||
// or when the parent context's Done channel is closed, whichever happens first.
|
|
||||||
//
|
|
||||||
// Canceling this context releases resources associated with it, so code should
|
|
||||||
// call cancel as soon as the operations running in this Context complete.
|
|
||||||
func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {
|
|
||||||
ctx, f := context.WithCancel(parent)
|
|
||||||
return ctx, CancelFunc(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDeadline returns a copy of the parent context with the deadline adjusted
|
|
||||||
// to be no later than d. If the parent's deadline is already earlier than d,
|
|
||||||
// WithDeadline(parent, d) is semantically equivalent to parent. The returned
|
|
||||||
// context's Done channel is closed when the deadline expires, when the returned
|
|
||||||
// cancel function is called, or when the parent context's Done channel is
|
|
||||||
// closed, whichever happens first.
|
|
||||||
//
|
|
||||||
// Canceling this context releases resources associated with it, so code should
|
|
||||||
// call cancel as soon as the operations running in this Context complete.
|
|
||||||
func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) {
|
|
||||||
ctx, f := context.WithDeadline(parent, deadline)
|
|
||||||
return ctx, CancelFunc(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
|
|
||||||
//
|
|
||||||
// Canceling this context releases resources associated with it, so code should
|
|
||||||
// call cancel as soon as the operations running in this Context complete:
|
|
||||||
//
|
|
||||||
// func slowOperationWithTimeout(ctx context.Context) (Result, error) {
|
|
||||||
// ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
|
|
||||||
// defer cancel() // releases resources if slowOperation completes before timeout elapses
|
|
||||||
// return slowOperation(ctx)
|
|
||||||
// }
|
|
||||||
func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) {
|
|
||||||
return WithDeadline(parent, time.Now().Add(timeout))
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithValue returns a copy of parent in which the value associated with key is
|
|
||||||
// val.
|
|
||||||
//
|
|
||||||
// Use context Values only for request-scoped data that transits processes and
|
|
||||||
// APIs, not for passing optional parameters to functions.
|
|
||||||
func WithValue(parent Context, key interface{}, val interface{}) Context {
|
|
||||||
return context.WithValue(parent, key, val)
|
|
||||||
}
|
|
20
vendor/golang.org/x/net/context/go19.go
generated
vendored
20
vendor/golang.org/x/net/context/go19.go
generated
vendored
@ -1,20 +0,0 @@
|
|||||||
// Copyright 2017 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 go1.9
|
|
||||||
|
|
||||||
package context
|
|
||||||
|
|
||||||
import "context" // standard library's context, as of Go 1.7
|
|
||||||
|
|
||||||
// A Context carries a deadline, a cancelation signal, and other values across
|
|
||||||
// API boundaries.
|
|
||||||
//
|
|
||||||
// Context's methods may be called by multiple goroutines simultaneously.
|
|
||||||
type Context = context.Context
|
|
||||||
|
|
||||||
// A CancelFunc tells an operation to abandon its work.
|
|
||||||
// A CancelFunc does not wait for the work to stop.
|
|
||||||
// After the first call, subsequent calls to a CancelFunc do nothing.
|
|
||||||
type CancelFunc = context.CancelFunc
|
|
300
vendor/golang.org/x/net/context/pre_go17.go
generated
vendored
300
vendor/golang.org/x/net/context/pre_go17.go
generated
vendored
@ -1,300 +0,0 @@
|
|||||||
// Copyright 2014 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 !go1.7
|
|
||||||
|
|
||||||
package context
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// An emptyCtx is never canceled, has no values, and has no deadline. It is not
|
|
||||||
// struct{}, since vars of this type must have distinct addresses.
|
|
||||||
type emptyCtx int
|
|
||||||
|
|
||||||
func (*emptyCtx) Deadline() (deadline time.Time, ok bool) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*emptyCtx) Done() <-chan struct{} {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*emptyCtx) Err() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*emptyCtx) Value(key interface{}) interface{} {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *emptyCtx) String() string {
|
|
||||||
switch e {
|
|
||||||
case background:
|
|
||||||
return "context.Background"
|
|
||||||
case todo:
|
|
||||||
return "context.TODO"
|
|
||||||
}
|
|
||||||
return "unknown empty Context"
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
background = new(emptyCtx)
|
|
||||||
todo = new(emptyCtx)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Canceled is the error returned by Context.Err when the context is canceled.
|
|
||||||
var Canceled = errors.New("context canceled")
|
|
||||||
|
|
||||||
// DeadlineExceeded is the error returned by Context.Err when the context's
|
|
||||||
// deadline passes.
|
|
||||||
var DeadlineExceeded = errors.New("context deadline exceeded")
|
|
||||||
|
|
||||||
// WithCancel returns a copy of parent with a new Done channel. The returned
|
|
||||||
// context's Done channel is closed when the returned cancel function is called
|
|
||||||
// or when the parent context's Done channel is closed, whichever happens first.
|
|
||||||
//
|
|
||||||
// Canceling this context releases resources associated with it, so code should
|
|
||||||
// call cancel as soon as the operations running in this Context complete.
|
|
||||||
func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {
|
|
||||||
c := newCancelCtx(parent)
|
|
||||||
propagateCancel(parent, c)
|
|
||||||
return c, func() { c.cancel(true, Canceled) }
|
|
||||||
}
|
|
||||||
|
|
||||||
// newCancelCtx returns an initialized cancelCtx.
|
|
||||||
func newCancelCtx(parent Context) *cancelCtx {
|
|
||||||
return &cancelCtx{
|
|
||||||
Context: parent,
|
|
||||||
done: make(chan struct{}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// propagateCancel arranges for child to be canceled when parent is.
|
|
||||||
func propagateCancel(parent Context, child canceler) {
|
|
||||||
if parent.Done() == nil {
|
|
||||||
return // parent is never canceled
|
|
||||||
}
|
|
||||||
if p, ok := parentCancelCtx(parent); ok {
|
|
||||||
p.mu.Lock()
|
|
||||||
if p.err != nil {
|
|
||||||
// parent has already been canceled
|
|
||||||
child.cancel(false, p.err)
|
|
||||||
} else {
|
|
||||||
if p.children == nil {
|
|
||||||
p.children = make(map[canceler]bool)
|
|
||||||
}
|
|
||||||
p.children[child] = true
|
|
||||||
}
|
|
||||||
p.mu.Unlock()
|
|
||||||
} else {
|
|
||||||
go func() {
|
|
||||||
select {
|
|
||||||
case <-parent.Done():
|
|
||||||
child.cancel(false, parent.Err())
|
|
||||||
case <-child.Done():
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parentCancelCtx follows a chain of parent references until it finds a
|
|
||||||
// *cancelCtx. This function understands how each of the concrete types in this
|
|
||||||
// package represents its parent.
|
|
||||||
func parentCancelCtx(parent Context) (*cancelCtx, bool) {
|
|
||||||
for {
|
|
||||||
switch c := parent.(type) {
|
|
||||||
case *cancelCtx:
|
|
||||||
return c, true
|
|
||||||
case *timerCtx:
|
|
||||||
return c.cancelCtx, true
|
|
||||||
case *valueCtx:
|
|
||||||
parent = c.Context
|
|
||||||
default:
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// removeChild removes a context from its parent.
|
|
||||||
func removeChild(parent Context, child canceler) {
|
|
||||||
p, ok := parentCancelCtx(parent)
|
|
||||||
if !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
p.mu.Lock()
|
|
||||||
if p.children != nil {
|
|
||||||
delete(p.children, child)
|
|
||||||
}
|
|
||||||
p.mu.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
// A canceler is a context type that can be canceled directly. The
|
|
||||||
// implementations are *cancelCtx and *timerCtx.
|
|
||||||
type canceler interface {
|
|
||||||
cancel(removeFromParent bool, err error)
|
|
||||||
Done() <-chan struct{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A cancelCtx can be canceled. When canceled, it also cancels any children
|
|
||||||
// that implement canceler.
|
|
||||||
type cancelCtx struct {
|
|
||||||
Context
|
|
||||||
|
|
||||||
done chan struct{} // closed by the first cancel call.
|
|
||||||
|
|
||||||
mu sync.Mutex
|
|
||||||
children map[canceler]bool // set to nil by the first cancel call
|
|
||||||
err error // set to non-nil by the first cancel call
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cancelCtx) Done() <-chan struct{} {
|
|
||||||
return c.done
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cancelCtx) Err() error {
|
|
||||||
c.mu.Lock()
|
|
||||||
defer c.mu.Unlock()
|
|
||||||
return c.err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cancelCtx) String() string {
|
|
||||||
return fmt.Sprintf("%v.WithCancel", c.Context)
|
|
||||||
}
|
|
||||||
|
|
||||||
// cancel closes c.done, cancels each of c's children, and, if
|
|
||||||
// removeFromParent is true, removes c from its parent's children.
|
|
||||||
func (c *cancelCtx) cancel(removeFromParent bool, err error) {
|
|
||||||
if err == nil {
|
|
||||||
panic("context: internal error: missing cancel error")
|
|
||||||
}
|
|
||||||
c.mu.Lock()
|
|
||||||
if c.err != nil {
|
|
||||||
c.mu.Unlock()
|
|
||||||
return // already canceled
|
|
||||||
}
|
|
||||||
c.err = err
|
|
||||||
close(c.done)
|
|
||||||
for child := range c.children {
|
|
||||||
// NOTE: acquiring the child's lock while holding parent's lock.
|
|
||||||
child.cancel(false, err)
|
|
||||||
}
|
|
||||||
c.children = nil
|
|
||||||
c.mu.Unlock()
|
|
||||||
|
|
||||||
if removeFromParent {
|
|
||||||
removeChild(c.Context, c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDeadline returns a copy of the parent context with the deadline adjusted
|
|
||||||
// to be no later than d. If the parent's deadline is already earlier than d,
|
|
||||||
// WithDeadline(parent, d) is semantically equivalent to parent. The returned
|
|
||||||
// context's Done channel is closed when the deadline expires, when the returned
|
|
||||||
// cancel function is called, or when the parent context's Done channel is
|
|
||||||
// closed, whichever happens first.
|
|
||||||
//
|
|
||||||
// Canceling this context releases resources associated with it, so code should
|
|
||||||
// call cancel as soon as the operations running in this Context complete.
|
|
||||||
func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) {
|
|
||||||
if cur, ok := parent.Deadline(); ok && cur.Before(deadline) {
|
|
||||||
// The current deadline is already sooner than the new one.
|
|
||||||
return WithCancel(parent)
|
|
||||||
}
|
|
||||||
c := &timerCtx{
|
|
||||||
cancelCtx: newCancelCtx(parent),
|
|
||||||
deadline: deadline,
|
|
||||||
}
|
|
||||||
propagateCancel(parent, c)
|
|
||||||
d := deadline.Sub(time.Now())
|
|
||||||
if d <= 0 {
|
|
||||||
c.cancel(true, DeadlineExceeded) // deadline has already passed
|
|
||||||
return c, func() { c.cancel(true, Canceled) }
|
|
||||||
}
|
|
||||||
c.mu.Lock()
|
|
||||||
defer c.mu.Unlock()
|
|
||||||
if c.err == nil {
|
|
||||||
c.timer = time.AfterFunc(d, func() {
|
|
||||||
c.cancel(true, DeadlineExceeded)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return c, func() { c.cancel(true, Canceled) }
|
|
||||||
}
|
|
||||||
|
|
||||||
// A timerCtx carries a timer and a deadline. It embeds a cancelCtx to
|
|
||||||
// implement Done and Err. It implements cancel by stopping its timer then
|
|
||||||
// delegating to cancelCtx.cancel.
|
|
||||||
type timerCtx struct {
|
|
||||||
*cancelCtx
|
|
||||||
timer *time.Timer // Under cancelCtx.mu.
|
|
||||||
|
|
||||||
deadline time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *timerCtx) Deadline() (deadline time.Time, ok bool) {
|
|
||||||
return c.deadline, true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *timerCtx) String() string {
|
|
||||||
return fmt.Sprintf("%v.WithDeadline(%s [%s])", c.cancelCtx.Context, c.deadline, c.deadline.Sub(time.Now()))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *timerCtx) cancel(removeFromParent bool, err error) {
|
|
||||||
c.cancelCtx.cancel(false, err)
|
|
||||||
if removeFromParent {
|
|
||||||
// Remove this timerCtx from its parent cancelCtx's children.
|
|
||||||
removeChild(c.cancelCtx.Context, c)
|
|
||||||
}
|
|
||||||
c.mu.Lock()
|
|
||||||
if c.timer != nil {
|
|
||||||
c.timer.Stop()
|
|
||||||
c.timer = nil
|
|
||||||
}
|
|
||||||
c.mu.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
|
|
||||||
//
|
|
||||||
// Canceling this context releases resources associated with it, so code should
|
|
||||||
// call cancel as soon as the operations running in this Context complete:
|
|
||||||
//
|
|
||||||
// func slowOperationWithTimeout(ctx context.Context) (Result, error) {
|
|
||||||
// ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
|
|
||||||
// defer cancel() // releases resources if slowOperation completes before timeout elapses
|
|
||||||
// return slowOperation(ctx)
|
|
||||||
// }
|
|
||||||
func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) {
|
|
||||||
return WithDeadline(parent, time.Now().Add(timeout))
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithValue returns a copy of parent in which the value associated with key is
|
|
||||||
// val.
|
|
||||||
//
|
|
||||||
// Use context Values only for request-scoped data that transits processes and
|
|
||||||
// APIs, not for passing optional parameters to functions.
|
|
||||||
func WithValue(parent Context, key interface{}, val interface{}) Context {
|
|
||||||
return &valueCtx{parent, key, val}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A valueCtx carries a key-value pair. It implements Value for that key and
|
|
||||||
// delegates all other calls to the embedded Context.
|
|
||||||
type valueCtx struct {
|
|
||||||
Context
|
|
||||||
key, val interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *valueCtx) String() string {
|
|
||||||
return fmt.Sprintf("%v.WithValue(%#v, %#v)", c.Context, c.key, c.val)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *valueCtx) Value(key interface{}) interface{} {
|
|
||||||
if c.key == key {
|
|
||||||
return c.val
|
|
||||||
}
|
|
||||||
return c.Context.Value(key)
|
|
||||||
}
|
|
109
vendor/golang.org/x/net/context/pre_go19.go
generated
vendored
109
vendor/golang.org/x/net/context/pre_go19.go
generated
vendored
@ -1,109 +0,0 @@
|
|||||||
// Copyright 2014 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 !go1.9
|
|
||||||
|
|
||||||
package context
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
// A Context carries a deadline, a cancelation signal, and other values across
|
|
||||||
// API boundaries.
|
|
||||||
//
|
|
||||||
// Context's methods may be called by multiple goroutines simultaneously.
|
|
||||||
type Context interface {
|
|
||||||
// Deadline returns the time when work done on behalf of this context
|
|
||||||
// should be canceled. Deadline returns ok==false when no deadline is
|
|
||||||
// set. Successive calls to Deadline return the same results.
|
|
||||||
Deadline() (deadline time.Time, ok bool)
|
|
||||||
|
|
||||||
// Done returns a channel that's closed when work done on behalf of this
|
|
||||||
// context should be canceled. Done may return nil if this context can
|
|
||||||
// never be canceled. Successive calls to Done return the same value.
|
|
||||||
//
|
|
||||||
// WithCancel arranges for Done to be closed when cancel is called;
|
|
||||||
// WithDeadline arranges for Done to be closed when the deadline
|
|
||||||
// expires; WithTimeout arranges for Done to be closed when the timeout
|
|
||||||
// elapses.
|
|
||||||
//
|
|
||||||
// Done is provided for use in select statements:
|
|
||||||
//
|
|
||||||
// // Stream generates values with DoSomething and sends them to out
|
|
||||||
// // until DoSomething returns an error or ctx.Done is closed.
|
|
||||||
// func Stream(ctx context.Context, out chan<- Value) error {
|
|
||||||
// for {
|
|
||||||
// v, err := DoSomething(ctx)
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// select {
|
|
||||||
// case <-ctx.Done():
|
|
||||||
// return ctx.Err()
|
|
||||||
// case out <- v:
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// See http://blog.golang.org/pipelines for more examples of how to use
|
|
||||||
// a Done channel for cancelation.
|
|
||||||
Done() <-chan struct{}
|
|
||||||
|
|
||||||
// Err returns a non-nil error value after Done is closed. Err returns
|
|
||||||
// Canceled if the context was canceled or DeadlineExceeded if the
|
|
||||||
// context's deadline passed. No other values for Err are defined.
|
|
||||||
// After Done is closed, successive calls to Err return the same value.
|
|
||||||
Err() error
|
|
||||||
|
|
||||||
// Value returns the value associated with this context for key, or nil
|
|
||||||
// if no value is associated with key. Successive calls to Value with
|
|
||||||
// the same key returns the same result.
|
|
||||||
//
|
|
||||||
// Use context values only for request-scoped data that transits
|
|
||||||
// processes and API boundaries, not for passing optional parameters to
|
|
||||||
// functions.
|
|
||||||
//
|
|
||||||
// A key identifies a specific value in a Context. Functions that wish
|
|
||||||
// to store values in Context typically allocate a key in a global
|
|
||||||
// variable then use that key as the argument to context.WithValue and
|
|
||||||
// Context.Value. A key can be any type that supports equality;
|
|
||||||
// packages should define keys as an unexported type to avoid
|
|
||||||
// collisions.
|
|
||||||
//
|
|
||||||
// Packages that define a Context key should provide type-safe accessors
|
|
||||||
// for the values stores using that key:
|
|
||||||
//
|
|
||||||
// // Package user defines a User type that's stored in Contexts.
|
|
||||||
// package user
|
|
||||||
//
|
|
||||||
// import "golang.org/x/net/context"
|
|
||||||
//
|
|
||||||
// // User is the type of value stored in the Contexts.
|
|
||||||
// type User struct {...}
|
|
||||||
//
|
|
||||||
// // key is an unexported type for keys defined in this package.
|
|
||||||
// // This prevents collisions with keys defined in other packages.
|
|
||||||
// type key int
|
|
||||||
//
|
|
||||||
// // userKey is the key for user.User values in Contexts. It is
|
|
||||||
// // unexported; clients use user.NewContext and user.FromContext
|
|
||||||
// // instead of using this key directly.
|
|
||||||
// var userKey key = 0
|
|
||||||
//
|
|
||||||
// // NewContext returns a new Context that carries value u.
|
|
||||||
// func NewContext(ctx context.Context, u *User) context.Context {
|
|
||||||
// return context.WithValue(ctx, userKey, u)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // FromContext returns the User value stored in ctx, if any.
|
|
||||||
// func FromContext(ctx context.Context) (*User, bool) {
|
|
||||||
// u, ok := ctx.Value(userKey).(*User)
|
|
||||||
// return u, ok
|
|
||||||
// }
|
|
||||||
Value(key interface{}) interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A CancelFunc tells an operation to abandon its work.
|
|
||||||
// A CancelFunc does not wait for the work to stop.
|
|
||||||
// After the first call, subsequent calls to a CancelFunc do nothing.
|
|
||||||
type CancelFunc func()
|
|
4
vendor/modules.txt
vendored
4
vendor/modules.txt
vendored
@ -44,7 +44,7 @@ github.com/gobwas/glob/syntax/lexer
|
|||||||
github.com/gobwas/glob/util/strings
|
github.com/gobwas/glob/util/strings
|
||||||
# github.com/gogo/protobuf v1.1.1
|
# github.com/gogo/protobuf v1.1.1
|
||||||
github.com/gogo/protobuf/proto
|
github.com/gogo/protobuf/proto
|
||||||
# github.com/golang/mock v1.1.1
|
# github.com/golang/mock v1.0.0
|
||||||
github.com/golang/mock/gomock
|
github.com/golang/mock/gomock
|
||||||
# github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2
|
# github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2
|
||||||
github.com/golangci/check/cmd/structcheck
|
github.com/golangci/check/cmd/structcheck
|
||||||
@ -185,8 +185,6 @@ github.com/valyala/bytebufferpool
|
|||||||
github.com/valyala/quicktemplate
|
github.com/valyala/quicktemplate
|
||||||
# golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a
|
# golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a
|
||||||
golang.org/x/crypto/ssh/terminal
|
golang.org/x/crypto/ssh/terminal
|
||||||
# golang.org/x/net v0.0.0-20190313220215-9f648a60d977
|
|
||||||
golang.org/x/net/context
|
|
||||||
# golang.org/x/sys v0.0.0-20190312061237-fead79001313
|
# golang.org/x/sys v0.0.0-20190312061237-fead79001313
|
||||||
golang.org/x/sys/unix
|
golang.org/x/sys/unix
|
||||||
golang.org/x/sys/windows
|
golang.org/x/sys/windows
|
||||||
|
Loading…
x
Reference in New Issue
Block a user