golang ---获取磁盘信息

package main

import (
	"fmt"

	"github.com/StackExchange/wmi"
)

type Storage struct {
	Name       string
	FileSystem string
	Total      uint64
	Free       uint64
}

type storageInfo struct {
	Name       string
	Size       uint64
	FreeSpace  uint64
	FileSystem string
}

func getStorageInfo() {
	var storageinfo []storageInfo
	var loaclStorages []Storage
	err := wmi.Query("Select * from Win32_LogicalDisk", &storageinfo)
	if err != nil {
		return
	}

	for _, storage := range storageinfo {
		info := Storage{
			Name:       storage.Name,
			FileSystem: storage.FileSystem,
			Total:      storage.Size,
			Free:       storage.FreeSpace,
		}
		loaclStorages = append(loaclStorages, info)
	}
	fmt.Printf("localStorages:=", loaclStorages)
}

func main() {
	getStorageInfo()
}

  

上一篇:理解JavaScript的闭包


下一篇:Bristol的第23篇密码学