當前位置: 首頁>>代碼示例>>Golang>>正文


Golang go-units.HumanSize函數代碼示例

本文整理匯總了Golang中github.com/docker/go-units.HumanSize函數的典型用法代碼示例。如果您正苦於以下問題:Golang HumanSize函數的具體用法?Golang HumanSize怎麽用?Golang HumanSize使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了HumanSize函數的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Reclaimable

func (c *diskUsageImagesContext) Reclaimable() string {
	var used int64

	c.AddHeader(reclaimableHeader)
	for _, i := range c.images {
		if i.Containers != 0 {
			used += i.Size
		}
	}

	reclaimable := c.totalSize - used
	if c.totalSize > 0 {
		return fmt.Sprintf("%s (%v%%)", units.HumanSize(float64(reclaimable)), (reclaimable*100)/c.totalSize)
	}
	return fmt.Sprintf("%s", units.HumanSize(float64(reclaimable)))
}
開發者ID:jfrazelle,項目名稱:docker,代碼行數:16,代碼來源:disk_usage.go

示例2: Size

func (c *volumeContext) Size() string {
	c.AddHeader(sizeHeader)
	if c.v.Size == -1 {
		return "N/A"
	}
	return units.HumanSize(float64(c.v.Size))
}
開發者ID:SUSE,項目名稱:docker.mirror,代碼行數:7,代碼來源:volume.go

示例3: NewPruneCommand

// NewPruneCommand returns a new cobra prune command for images
func NewPruneCommand(dockerCli *command.DockerCli) *cobra.Command {
	opts := pruneOptions{filter: opts.NewFilterOpt()}

	cmd := &cobra.Command{
		Use:   "prune [OPTIONS]",
		Short: "Remove unused images",
		Args:  cli.NoArgs,
		RunE: func(cmd *cobra.Command, args []string) error {
			spaceReclaimed, output, err := runPrune(dockerCli, opts)
			if err != nil {
				return err
			}
			if output != "" {
				fmt.Fprintln(dockerCli.Out(), output)
			}
			fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
			return nil
		},
		Tags: map[string]string{"version": "1.25"},
	}

	flags := cmd.Flags()
	flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation")
	flags.BoolVarP(&opts.all, "all", "a", false, "Remove all unused images, not just dangling ones")
	flags.Var(&opts.filter, "filter", "Provide filter values (e.g. 'until=<timestamp>')")

	return cmd
}
開發者ID:docker,項目名稱:docker,代碼行數:29,代碼來源:prune.go

示例4: UniqueSize

func (c *imageContext) UniqueSize() string {
	c.AddHeader(uniqueSizeHeader)
	if c.i.Size == -1 {
		return "N/A"
	}
	return units.HumanSize(float64(c.i.Size))
}
開發者ID:Mic92,項目名稱:docker,代碼行數:7,代碼來源:image.go

示例5: NewPruneCommand

// NewPruneCommand returns a new cobra prune command for volumes
func NewPruneCommand(dockerCli *command.DockerCli) *cobra.Command {
	var opts pruneOptions

	cmd := &cobra.Command{
		Use:   "prune [OPTIONS]",
		Short: "Remove all unused volumes",
		Args:  cli.NoArgs,
		RunE: func(cmd *cobra.Command, args []string) error {
			spaceReclaimed, output, err := runPrune(dockerCli, opts)
			if err != nil {
				return err
			}
			if output != "" {
				fmt.Fprintln(dockerCli.Out(), output)
			}
			fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
			return nil
		},
	}

	flags := cmd.Flags()
	flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation")

	return cmd
}
開發者ID:Mic92,項目名稱:docker,代碼行數:26,代碼來源:prune.go

示例6: Size

func (c *volumeContext) Size() string {
	c.AddHeader(sizeHeader)
	if c.v.UsageData == nil {
		return "N/A"
	}
	return units.HumanSize(float64(c.v.UsageData.Size))
}
開發者ID:Mic92,項目名稱:docker,代碼行數:7,代碼來源:volume.go

示例7: serveTemplate

func (h *handler) serveTemplate(w http.ResponseWriter, r *http.Request) {
	templateDir := path.Join("/src", "templates")
	lp := path.Join(templateDir, "layout.html")

	// set up custom functions
	funcMap := template.FuncMap{
		"ext": func(name string) string {
			return strings.TrimPrefix(filepath.Ext(name), ".")
		},
		"base": func(name string) string {
			parts := strings.Split(name, "/")
			return parts[len(parts)-1]
		},
		"size": func(s int64) string {
			return units.HumanSize(float64(s))
		},
	}

	// parse & execute the template
	tmpl := template.Must(template.New("").Funcs(funcMap).ParseFiles(lp))
	if err := tmpl.ExecuteTemplate(w, "layout", h.Files); err != nil {
		writeError(w, fmt.Sprintf("Execute template failed: %v", err))
		return
	}
}
開發者ID:jfrazelle,項目名稱:s3server,代碼行數:25,代碼來源:main.go

示例8: convertBasesize

func convertBasesize(basesizeBytes int64) (int64, error) {
	basesize := units.HumanSize(float64(basesizeBytes))
	basesize = strings.Trim(basesize, " ")[:len(basesize)-3]
	basesizeFloat, err := strconv.ParseFloat(strings.Trim(basesize, " "), 64)
	if err != nil {
		return 0, err
	}
	return int64(basesizeFloat) * 1024 * 1024 * 1024, nil
}
開發者ID:shakamunyi,項目名稱:docker,代碼行數:9,代碼來源:docker_utils.go

示例9: Size

func (c *diskUsageContainersContext) Size() string {
	var size int64

	c.AddHeader(sizeHeader)
	for _, container := range c.containers {
		size += container.SizeRw
	}

	return units.HumanSize(float64(size))
}
開發者ID:jfrazelle,項目名稱:docker,代碼行數:10,代碼來源:disk_usage.go

示例10: createIndexFile

// create the index.html file
func createIndexFile(bucket *s3.Bucket, bucketpath string) error {
	// list all the files
	files, err := listFiles(bucketpath, bucketpath, "", 2000, bucket)
	if err != nil {
		return fmt.Errorf("Listing all files in bucket failed: %v", err)
	}

	// create a temp file for the index
	tmp, err := ioutil.TempFile("", "index.html")
	if err != nil {
		return fmt.Errorf("Creating temp file failed: %v", err)
	}
	defer os.RemoveAll(tmp.Name())

	// set up custom functions
	funcMap := template.FuncMap{
		"ext": func(name string) string {
			if strings.HasSuffix(name, ".sha256") || strings.HasSuffix(name, ".md5") {
				return "text"
			}
			return "default"
		},
		"size": func(s int64) string {
			return units.HumanSize(float64(s))
		},
	}

	// parse & execute the template
	tmpl, err := template.New("").Funcs(funcMap).Parse(index)
	if err != nil {
		return fmt.Errorf("Parsing template failed: %v", err)
	}

	if err := tmpl.Execute(tmp, files); err != nil {
		return fmt.Errorf("Execute template failed: %v", err)
	}

	// push the file to s3
	if err = uploadFileToS3(bucket, tmp.Name(), path.Join(bucketpath, "index.html"), "text/html"); err != nil {
		return fmt.Errorf("Uploading %s to s3 failed: %v", tmp.Name(), err)
	}

	return nil
}
開發者ID:carriercomm,項目名稱:docker-bb,代碼行數:45,代碼來源:static.go

示例11: runPrune

func runPrune(dockerCli *command.DockerCli, opts pruneOptions) error {
	var message string

	if opts.all {
		message = fmt.Sprintf(warning, allImageDesc)
	} else {
		message = fmt.Sprintf(warning, danglingImageDesc)
	}

	if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), message) {
		return nil
	}

	var spaceReclaimed uint64

	for _, pruneFn := range []func(dockerCli *command.DockerCli) (uint64, string, error){
		prune.RunContainerPrune,
		prune.RunVolumePrune,
		prune.RunNetworkPrune,
	} {
		spc, output, err := pruneFn(dockerCli)
		if err != nil {
			return err
		}
		spaceReclaimed += spc
		if output != "" {
			fmt.Fprintln(dockerCli.Out(), output)
		}
	}

	spc, output, err := prune.RunImagePrune(dockerCli, opts.all)
	if err != nil {
		return err
	}
	if spc > 0 {
		spaceReclaimed += spc
		fmt.Fprintln(dockerCli.Out(), output)
	}

	fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))

	return nil
}
開發者ID:harche,項目名稱:docker,代碼行數:43,代碼來源:prune.go

示例12: housekeeping

// TODO(vmarmol): Implement stats collecting as a custom collector.
func (c *containerData) housekeeping() {
	// Start any background goroutines - must be cleaned up in c.handler.Cleanup().
	c.handler.Start()

	// Long housekeeping is either 100ms or half of the housekeeping interval.
	longHousekeeping := 100 * time.Millisecond
	if *HousekeepingInterval/2 < longHousekeeping {
		longHousekeeping = *HousekeepingInterval / 2
	}

	// Housekeep every second.
	glog.V(3).Infof("Start housekeeping for container %q\n", c.info.Name)
	lastHousekeeping := time.Now()
	for {
		select {
		case <-c.stop:
			// Cleanup container resources before stopping housekeeping.
			c.handler.Cleanup()
			// Stop housekeeping when signaled.
			return
		default:
			// Perform housekeeping.
			start := time.Now()
			c.housekeepingTick()

			// Log if housekeeping took too long.
			duration := time.Since(start)
			if duration >= longHousekeeping {
				glog.V(3).Infof("[%s] Housekeeping took %s", c.info.Name, duration)
			}
		}

		// Log usage if asked to do so.
		if c.logUsage {
			const numSamples = 60
			var empty time.Time
			stats, err := c.memoryCache.RecentStats(c.info.Name, empty, empty, numSamples)
			if err != nil {
				if c.allowErrorLogging() {
					glog.Infof("[%s] Failed to get recent stats for logging usage: %v", c.info.Name, err)
				}
			} else if len(stats) < numSamples {
				// Ignore, not enough stats yet.
			} else {
				usageCpuNs := uint64(0)
				for i := range stats {
					if i > 0 {
						usageCpuNs += (stats[i].Cpu.Usage.Total - stats[i-1].Cpu.Usage.Total)
					}
				}
				usageMemory := stats[numSamples-1].Memory.Usage

				instantUsageInCores := float64(stats[numSamples-1].Cpu.Usage.Total-stats[numSamples-2].Cpu.Usage.Total) / float64(stats[numSamples-1].Timestamp.Sub(stats[numSamples-2].Timestamp).Nanoseconds())
				usageInCores := float64(usageCpuNs) / float64(stats[numSamples-1].Timestamp.Sub(stats[0].Timestamp).Nanoseconds())
				usageInHuman := units.HumanSize(float64(usageMemory))
				glog.Infof("[%s] %.3f cores (average: %.3f cores), %s of memory", c.info.Name, instantUsageInCores, usageInCores, usageInHuman)
			}
		}

		next := c.nextHousekeeping(lastHousekeeping)

		// Schedule the next housekeeping. Sleep until that time.
		if time.Now().Before(next) {
			time.Sleep(next.Sub(time.Now()))
		} else {
			next = time.Now()
		}
		lastHousekeeping = next
	}
}
開發者ID:Clarifai,項目名稱:kubernetes,代碼行數:71,代碼來源:container.go

示例13: VirtualSize

func (c *imageContext) VirtualSize() string {
	c.AddHeader(sizeHeader)
	return units.HumanSize(float64(c.i.VirtualSize))
}
開發者ID:Mic92,項目名稱:docker,代碼行數:4,代碼來源:image.go


注:本文中的github.com/docker/go-units.HumanSize函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。