本文整理汇总了Golang中github.com/juju/errgo.MaskFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang MaskFunc函数的具体用法?Golang MaskFunc怎么用?Golang MaskFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MaskFunc函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
// Copyright (c) 2016 Pulcy.
//
// 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 docker
import (
"github.com/juju/errgo"
)
var (
maskAny = errgo.MaskFunc(errgo.Any)
)
示例2:
package s3
import (
"github.com/juju/errgo"
)
var (
mask = errgo.MaskFunc()
)
示例3: TestMaskFunc
func TestMaskFunc(t *testing.T) {
err0 := errgo.New("zero")
err1 := errgo.New("one")
allowVals := func(vals ...error) (r []func(error) bool) {
for _, val := range vals {
r = append(r, errgo.Is(val))
}
return
}
tests := []struct {
err error
allow0 []func(error) bool
allow1 []func(error) bool
cause error
}{{
err: err0,
allow0: allowVals(err0),
cause: err0,
}, {
err: err1,
allow0: allowVals(err0),
cause: nil,
}, {
err: err0,
allow1: allowVals(err0),
cause: err0,
}, {
err: err0,
allow0: allowVals(err1),
allow1: allowVals(err0),
cause: err0,
}, {
err: err0,
allow0: allowVals(err0, err1),
cause: err0,
}, {
err: err1,
allow0: allowVals(err0, err1),
cause: err1,
}, {
err: err0,
allow1: allowVals(err0, err1),
cause: err0,
}, {
err: err1,
allow1: allowVals(err0, err1),
cause: err1,
}}
for i, test := range tests {
wrap := errgo.MaskFunc(test.allow0...)
err := wrap(test.err, test.allow1...)
cause := errgo.Cause(err)
wantCause := test.cause
if wantCause == nil {
wantCause = err
}
if cause != wantCause {
t.Errorf("test %d. got %#v want %#v", i, cause, err)
}
}
}
示例4:
import (
"fmt"
"strings"
"sync"
"time"
"github.com/coreos/fleet/client"
"github.com/coreos/fleet/schema"
"github.com/coreos/fleet/unit"
"github.com/giantswarm/metrics"
"github.com/golang/glog"
"github.com/juju/errgo"
)
var maskAny = errgo.MaskFunc(errgo.Any)
var mask = errgo.MaskFunc()
type Config struct {
TickerTime time.Duration
DeleteTime time.Duration
UpdateCooldownTime time.Duration
MachineTag string
UnitPrefix string
UnitTemplate string
}
type Dependencies struct {
Fleet client.API
Operator FleetOperator
示例5: TestMaskFunc
func (*errorsSuite) TestMaskFunc(c *gc.C) {
err0 := errgo.New("zero")
err1 := errgo.New("one")
allowVals := func(vals ...error) (r []func(error) bool) {
for _, val := range vals {
r = append(r, errgo.Is(val))
}
return
}
tests := []struct {
err error
allow0 []func(error) bool
allow1 []func(error) bool
cause error
}{{
err: err0,
allow0: allowVals(err0),
cause: err0,
}, {
err: err1,
allow0: allowVals(err0),
cause: nil,
}, {
err: err0,
allow1: allowVals(err0),
cause: err0,
}, {
err: err0,
allow0: allowVals(err1),
allow1: allowVals(err0),
cause: err0,
}, {
err: err0,
allow0: allowVals(err0, err1),
cause: err0,
}, {
err: err1,
allow0: allowVals(err0, err1),
cause: err1,
}, {
err: err0,
allow1: allowVals(err0, err1),
cause: err0,
}, {
err: err1,
allow1: allowVals(err0, err1),
cause: err1,
}}
for i, test := range tests {
c.Logf("test %d", i)
wrap := errgo.MaskFunc(test.allow0...)
err := wrap(test.err, test.allow1...)
cause := errgo.Cause(err)
wantCause := test.cause
if wantCause == nil {
wantCause = err
}
c.Check(cause, gc.Equals, wantCause)
}
}