The example in this article describes how the go language acquires system disk characters. Share to everyone for your reference. Specifically as follows:
Involves the technique of Golang calling WINAPI to get the system letter. The code is as follows:
Copy Code code as follows:
CS Project Main.go
Package Main
Import (
"FMT"
. "StrConv"
"Syscall"
)
Func getlogicaldrives () []string {
KERNEL32: = Syscall. Mustloaddll ("kernel32.dll")
GetLogicalDrives: = kernel32. Mustfindproc ("GetLogicalDrives")
N, _, _: = Getlogicaldrives.call ()
S: = Formatint (Int64 (n), 2)
var drives_all = []string{"A:", "B:", "C:", "D:", "E:", "F:", "G:", "H:", "I:", "J:", "K:", "L:", "M:", "N:", "O:", "P:", "Q:", "R:", "S:", "T:", "U:", "V:", "W:", "X:", "Y:", "Z:"}
Temp: = Drives_all[0:len (s)]
var d []string
For I, V: = range S {
If v = = 49 {
L: = Len (s)-i-1
D = Append (d, temp[l])
}
}
var drives []string
For I, V: = Range D {
drives = Append (drives[i:], append ([]string{v}, Drives[:i] ...) ...)
}
return drives
}
Func Main () {
Fmt. Println (GetLogicalDrives ())
}
I hope this article will help you with your go language program.