当前位置: 首页>>代码示例>>Golang>>正文


Golang idresolver.IDResolver类代码示例

本文整理汇总了Golang中github.com/docker/docker/cli/command/idresolver.IDResolver的典型用法代码示例。如果您正苦于以下问题:Golang IDResolver类的具体用法?Golang IDResolver怎么用?Golang IDResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IDResolver类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: print

func print(out io.Writer, ctx context.Context, tasks []swarm.Task, resolver *idresolver.IDResolver, noTrunc bool) error {
	prevServiceName := ""
	prevSlot := 0
	for _, task := range tasks {
		serviceName, err := resolver.Resolve(ctx, swarm.Service{}, task.ServiceID)
		if err != nil {
			return err
		}
		nodeValue, err := resolver.Resolve(ctx, swarm.Node{}, task.NodeID)
		if err != nil {
			return err
		}

		name := task.Annotations.Name
		// TODO: This is the fallback <ServiceName>.<Slot>.<taskID> in case task name is not present in
		// Annotations (upgraded from 1.12).
		// We may be able to remove the following in the future.
		if name == "" {
			if task.Slot != 0 {
				name = fmt.Sprintf("%v.%v.%v", serviceName, task.Slot, task.ID)
			} else {
				name = fmt.Sprintf("%v.%v.%v", serviceName, task.NodeID, task.ID)
			}
		}

		// Indent the name if necessary
		indentedName := name
		// Since the new format of the task name is <ServiceName>.<Slot>.<taskID>, we should only compare
		// <ServiceName> and <Slot> here.
		if prevServiceName == serviceName && prevSlot == task.Slot {
			indentedName = fmt.Sprintf(" \\_ %s", indentedName)
		}
		prevServiceName = serviceName
		prevSlot = task.Slot

		// Trim and quote the error message.
		taskErr := task.Status.Err
		if !noTrunc && len(taskErr) > maxErrLength {
			taskErr = fmt.Sprintf("%s…", taskErr[:maxErrLength-1])
		}
		if len(taskErr) > 0 {
			taskErr = fmt.Sprintf("\"%s\"", taskErr)
		}

		fmt.Fprintf(
			out,
			psTaskItemFmt,
			indentedName,
			task.Spec.ContainerSpec.Image,
			nodeValue,
			command.PrettyPrint(task.DesiredState),
			command.PrettyPrint(task.Status.State),
			strings.ToLower(units.HumanDuration(time.Since(task.Status.Timestamp))),
			taskErr,
		)
	}
	return nil
}
开发者ID:Mic92,项目名称:docker,代码行数:58,代码来源:print.go

示例2: Print

// Print task information in a table format
func Print(dockerCli *command.DockerCli, ctx context.Context, tasks []swarm.Task, resolver *idresolver.IDResolver, noTrunc bool) error {
	sort.Stable(tasksBySlot(tasks))

	writer := tabwriter.NewWriter(dockerCli.Out(), 0, 4, 2, ' ', 0)

	// Ignore flushing errors
	defer writer.Flush()
	fmt.Fprintln(writer, strings.Join([]string{"ID", "NAME", "IMAGE", "NODE", "DESIRED STATE", "CURRENT STATE", "ERROR"}, "\t"))

	prevName := ""
	for _, task := range tasks {
		serviceValue, err := resolver.Resolve(ctx, swarm.Service{}, task.ServiceID)
		if err != nil {
			return err
		}
		nodeValue, err := resolver.Resolve(ctx, swarm.Node{}, task.NodeID)
		if err != nil {
			return err
		}

		name := serviceValue
		if task.Slot > 0 {
			name = fmt.Sprintf("%s.%d", name, task.Slot)
		}

		// Indent the name if necessary
		indentedName := name
		if prevName == name {
			indentedName = fmt.Sprintf(" \\_ %s", indentedName)
		}
		prevName = name

		// Trim and quote the error message.
		taskErr := task.Status.Err
		if !noTrunc && len(taskErr) > maxErrLength {
			taskErr = fmt.Sprintf("%s…", taskErr[:maxErrLength-1])
		}
		if len(taskErr) > 0 {
			taskErr = fmt.Sprintf("\"%s\"", taskErr)
		}

		fmt.Fprintf(
			writer,
			psTaskItemFmt,
			task.ID,
			indentedName,
			task.Spec.ContainerSpec.Image,
			nodeValue,
			command.PrettyPrint(task.DesiredState),
			command.PrettyPrint(task.Status.State),
			strings.ToLower(units.HumanDuration(time.Since(task.Status.Timestamp))),
			taskErr,
		)
	}

	return nil
}
开发者ID:CWSpear,项目名称:docker,代码行数:58,代码来源:print.go

示例3: print

func print(out io.Writer, ctx context.Context, tasks []swarm.Task, resolver *idresolver.IDResolver, noTrunc bool) error {
	prevService := ""
	prevSlot := 0
	for _, task := range tasks {
		name, err := resolver.Resolve(ctx, task, task.ID)

		nodeValue, err := resolver.Resolve(ctx, swarm.Node{}, task.NodeID)
		if err != nil {
			return err
		}

		// Indent the name if necessary
		indentedName := name
		// Since the new format of the task name is <ServiceName>.<Slot>.<taskID>, we should only compare
		// <ServiceName> and <Slot> here.
		if prevService == task.ServiceID && prevSlot == task.Slot {
			indentedName = fmt.Sprintf(" \\_ %s", indentedName)
		}
		prevService = task.ServiceID
		prevSlot = task.Slot

		// Trim and quote the error message.
		taskErr := task.Status.Err
		if !noTrunc && len(taskErr) > maxErrLength {
			taskErr = fmt.Sprintf("%s…", taskErr[:maxErrLength-1])
		}
		if len(taskErr) > 0 {
			taskErr = fmt.Sprintf("\"%s\"", taskErr)
		}

		image := task.Spec.ContainerSpec.Image
		if !noTrunc {
			ref, err := distreference.ParseNamed(image)
			if err == nil {
				// update image string for display
				namedTagged, ok := ref.(distreference.NamedTagged)
				if ok {
					image = namedTagged.Name() + ":" + namedTagged.Tag()
				}
			}
		}

		fmt.Fprintf(
			out,
			psTaskItemFmt,
			indentedName,
			image,
			nodeValue,
			command.PrettyPrint(task.DesiredState),
			command.PrettyPrint(task.Status.State),
			strings.ToLower(units.HumanDuration(time.Since(task.Status.Timestamp))),
			taskErr,
			portStatus(task.Status.PortStatus),
		)
	}
	return nil
}
开发者ID:haoshuwei,项目名称:docker,代码行数:57,代码来源:print.go

示例4: Print

// Print task information in a table format
func Print(dockerCli *command.DockerCli, ctx context.Context, tasks []swarm.Task, resolver *idresolver.IDResolver, noTrunc bool) error {
	sort.Stable(tasksBySlot(tasks))

	writer := tabwriter.NewWriter(dockerCli.Out(), 0, 4, 2, ' ', 0)

	// Ignore flushing errors
	defer writer.Flush()
	fmt.Fprintln(writer, strings.Join([]string{"NAME", "IMAGE", "NODE", "DESIRED STATE", "CURRENT STATE", "ERROR"}, "\t"))

	prevServiceName := ""
	prevSlot := 0
	for _, task := range tasks {
		serviceName, err := resolver.Resolve(ctx, swarm.Service{}, task.ServiceID)
		if err != nil {
			return err
		}
		nodeValue, err := resolver.Resolve(ctx, swarm.Node{}, task.NodeID)
		if err != nil {
			return err
		}

		name := task.Annotations.Name
		// TODO: This is the fallback <ServiceName>.<Slot>.<taskID> in case task name is not present in
		// Annotations (upgraded from 1.12).
		// We may be able to remove the following in the future.
		if name == "" {
			if task.Slot != 0 {
				name = fmt.Sprintf("%v.%v.%v", serviceName, task.Slot, task.ID)
			} else {
				name = fmt.Sprintf("%v.%v.%v", serviceName, task.NodeID, task.ID)
			}
		}

		// Indent the name if necessary
		indentedName := name
		// Since the new format of the task name is <ServiceName>.<Slot>.<taskID>, we should only compare
		// <ServiceName> and <Slot> here.
		if prevServiceName == serviceName && prevSlot == task.Slot {
			indentedName = fmt.Sprintf(" \\_ %s", indentedName)
		}
		prevServiceName = serviceName
		prevSlot = task.Slot

		// Trim and quote the error message.
		taskErr := task.Status.Err
		if !noTrunc && len(taskErr) > maxErrLength {
			taskErr = fmt.Sprintf("%s…", taskErr[:maxErrLength-1])
		}
		if len(taskErr) > 0 {
			taskErr = fmt.Sprintf("\"%s\"", taskErr)
		}

		fmt.Fprintf(
			writer,
			psTaskItemFmt,
			indentedName,
			task.Spec.ContainerSpec.Image,
			nodeValue,
			command.PrettyPrint(task.DesiredState),
			command.PrettyPrint(task.Status.State),
			strings.ToLower(units.HumanDuration(time.Since(task.Status.Timestamp))),
			taskErr,
		)
	}

	return nil
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:68,代码来源:print.go

示例5: print

func print(out io.Writer, ctx context.Context, tasks []swarm.Task, resolver *idresolver.IDResolver, noTrunc bool) error {
	prevName := ""
	for _, task := range tasks {
		id := task.ID
		if !noTrunc {
			id = stringid.TruncateID(id)
		}

		serviceName, err := resolver.Resolve(ctx, swarm.Service{}, task.ServiceID)
		if err != nil {
			return err
		}

		nodeValue, err := resolver.Resolve(ctx, swarm.Node{}, task.NodeID)
		if err != nil {
			return err
		}

		name := ""
		if task.Slot != 0 {
			name = fmt.Sprintf("%v.%v", serviceName, task.Slot)
		} else {
			name = fmt.Sprintf("%v.%v", serviceName, task.NodeID)
		}

		// Indent the name if necessary
		indentedName := name
		if name == prevName {
			indentedName = fmt.Sprintf(" \\_ %s", indentedName)
		}
		prevName = name

		// Trim and quote the error message.
		taskErr := task.Status.Err
		if !noTrunc && len(taskErr) > maxErrLength {
			taskErr = fmt.Sprintf("%s…", taskErr[:maxErrLength-1])
		}
		if len(taskErr) > 0 {
			taskErr = fmt.Sprintf("\"%s\"", taskErr)
		}

		image := task.Spec.ContainerSpec.Image
		if !noTrunc {
			ref, err := distreference.ParseNamed(image)
			if err == nil {
				// update image string for display
				namedTagged, ok := ref.(distreference.NamedTagged)
				if ok {
					image = namedTagged.Name() + ":" + namedTagged.Tag()
				}
			}
		}

		fmt.Fprintf(
			out,
			psTaskItemFmt,
			id,
			indentedName,
			image,
			nodeValue,
			command.PrettyPrint(task.DesiredState),
			command.PrettyPrint(task.Status.State),
			strings.ToLower(units.HumanDuration(time.Since(task.Status.Timestamp))),
			taskErr,
			portStatus(task.Status.PortStatus),
		)
	}
	return nil
}
开发者ID:docker,项目名称:docker,代码行数:69,代码来源:print.go


注:本文中的github.com/docker/docker/cli/command/idresolver.IDResolver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。