本文整理汇总了Golang中fmt.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: validateMounts
func validateMounts(mounts []api.Mount) error {
for _, mount := range mounts {
// Target must always be absolute
if !filepath.IsAbs(mount.Target) {
return fmt.Errorf("invalid mount target, must be an absolute path: %s", mount.Target)
}
switch mount.Type {
// The checks on abs paths are required due to the container API confusing
// volume mounts as bind mounts when the source is absolute (and vice-versa)
// See #25253
// TODO: This is probably not neccessary once #22373 is merged
case api.MountTypeBind:
if !filepath.IsAbs(mount.Source) {
return fmt.Errorf("invalid bind mount source, must be an absolute path: %s", mount.Source)
}
case api.MountTypeVolume:
if filepath.IsAbs(mount.Source) {
return fmt.Errorf("invalid volume mount source, must not be an absolute path: %s", mount.Source)
}
case api.MountTypeTmpfs:
if mount.Source != "" {
return fmt.Errorf("invalid tmpfs source, source must be empty")
}
default:
return fmt.Errorf("invalid mount type: %s", mount.Type)
}
}
return nil
}
开发者ID:ilkka,项目名称:docker,代码行数:30,代码来源:validate.go
示例2: parse
func (p *authV1JsonParser) parse(config *Config, raw []byte) error {
var auth authV1
if err := json.Unmarshal(raw, &auth); err != nil {
return err
}
if len(auth.Domains) == 0 {
return fmt.Errorf("no domains specified")
}
if len(auth.Type) == 0 {
return fmt.Errorf("no auth type specified")
}
var (
err error
headerer Headerer
)
switch auth.Type {
case "basic":
headerer, err = p.getBasicV1Headerer(auth.Credentials)
case "oauth":
headerer, err = p.getOAuthV1Headerer(auth.Credentials)
default:
err = fmt.Errorf("unknown auth type: %q", auth.Type)
}
if err != nil {
return err
}
for _, domain := range auth.Domains {
if _, ok := config.AuthPerHost[domain]; ok {
return fmt.Errorf("auth for domain %q is already specified", domain)
}
config.AuthPerHost[domain] = headerer
}
return nil
}
开发者ID:coderhaoxin,项目名称:rkt,代码行数:34,代码来源:auth.go
示例3: ExampleV_Validate
func ExampleV_Validate() {
type X struct {
A string `validate:"long"`
B string `validate:"short"`
C string `validate:"long,short"`
D string
}
vd := make(V)
vd["long"] = func(i interface{}) error {
s := i.(string)
if len(s) < 5 {
return fmt.Errorf("%q is too short", s)
}
return nil
}
vd["short"] = func(i interface{}) error {
s := i.(string)
if len(s) >= 5 {
return fmt.Errorf("%q is too long", s)
}
return nil
}
fmt.Println(vd.Validate(X{
A: "hello there",
B: "hi",
C: "help me",
D: "I am not validated",
}))
// Output: [field C is invalid: "help me" is too long]
}
开发者ID:jsidlosky,项目名称:validate,代码行数:33,代码来源:v_test.go
示例4: reserveName
func (daemon *Daemon) reserveName(id, name string) (string, error) {
if !validContainerNamePattern.MatchString(name) {
return "", fmt.Errorf("Invalid container name (%s), only %s are allowed", name, validContainerNameChars)
}
if name[0] != '/' {
name = "/" + name
}
if _, err := daemon.containerGraph.Set(name, id); err != nil {
if !graphdb.IsNonUniqueNameError(err) {
return "", err
}
conflictingContainer, err := daemon.GetByName(name)
if err != nil {
if strings.Contains(err.Error(), "Could not find entity") {
return "", err
}
// Remove name and continue starting the container
if err := daemon.containerGraph.Delete(name); err != nil {
return "", err
}
} else {
nameAsKnownByUser := strings.TrimPrefix(name, "/")
return "", fmt.Errorf(
"Conflict. The name %q is already in use by container %s. You have to remove (or rename) that container to be able to reuse that name.", nameAsKnownByUser,
stringid.TruncateID(conflictingContainer.ID))
}
}
return name, nil
}
开发者ID:newtime2014,项目名称:docker,代码行数:33,代码来源:daemon.go
示例5: deleteLocalSubnetRoute
func deleteLocalSubnetRoute(device, localSubnetCIDR string) {
backoff := utilwait.Backoff{
Duration: 100 * time.Millisecond,
Factor: 1.25,
Steps: 6,
}
err := utilwait.ExponentialBackoff(backoff, func() (bool, error) {
itx := ipcmd.NewTransaction(kexec.New(), device)
routes, err := itx.GetRoutes()
if err != nil {
return false, fmt.Errorf("could not get routes: %v", err)
}
for _, route := range routes {
if strings.Contains(route, localSubnetCIDR) {
itx.DeleteRoute(localSubnetCIDR)
err = itx.EndTransaction()
if err != nil {
return false, fmt.Errorf("could not delete route: %v", err)
}
return true, nil
}
}
return false, nil
})
if err != nil {
glog.Errorf("Error removing %s route from dev %s: %v; if the route appears later it will not be deleted.", localSubnetCIDR, device, err)
}
}
开发者ID:thrasher-redhat,项目名称:origin,代码行数:29,代码来源:controller.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng