du

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2021 License: Unlicense Imports: 1 Imported by: 1

Documentation

Index

Examples

Constants

View Source
const KB = uint64(1024)

Variables

This section is empty.

Functions

func DiskRate

func DiskRate(volumePath string) float32

DiskRate returns the usage rate of the disk where volumePath is located

Example
package main

import (
	"fmt"

	"tcw.im/go-disk-usage/du"
)

var KB = uint64(1024)

func main() {
	// MB
	usage := du.New(".")
	fmt.Println("Free:", usage.Free()/(KB*KB))
	fmt.Println("Available:", usage.Available()/(KB*KB))
	fmt.Println("Size:", usage.Size()/(KB*KB))
	fmt.Println("Used:", usage.Used()/(KB*KB))
	fmt.Println("Usage:", usage.Usage()*100, "%")

	fmt.Println(du.DiskRate(".")) // Usage(percent)
}
Output:

Types

type DiskHumanReadable

type DiskHumanReadable struct {
	Total     uint64
	Used      uint64
	Free      uint64
	Available uint64
	Percent   float32 // Decimal places, you might have to multiply by 100
}

Human-readable disk information, in KB (uint64)

func DiskInfo

func DiskInfo(volumePath string) DiskHumanReadable

DiskInfo returns an instance of DiskHumanReadable (New it)

type DiskUsage

type DiskUsage struct {
	// contains filtered or unexported fields
}

func New

func New(volumePath string) *DiskUsage

Returns an object holding the disk usage of volumePath This function assumes volumePath is a valid path

func (*DiskUsage) Available

func (d *DiskUsage) Available() uint64

Total available bytes on file system to an unpriveleged user

func (*DiskUsage) Free

func (d *DiskUsage) Free() uint64

Total free bytes on file system

func (*DiskUsage) Size

func (d *DiskUsage) Size() uint64

Total size of the file system

func (*DiskUsage) Usage

func (d *DiskUsage) Usage() float32

Percentage of use on the file system

func (*DiskUsage) Used

func (d *DiskUsage) Used() uint64

Total bytes used in file system

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL