Created
December 20, 2017 05:12
-
-
Save atotto/91b50bbaab569afad429619215e73c2d to your computer and use it in GitHub Desktop.
lsusb (golang)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "log" | |
| "github.com/google/gousb" | |
| "github.com/google/gousb/usbid" | |
| ) | |
| func main() { | |
| ctx := gousb.NewContext() | |
| defer ctx.Close() | |
| devs, err := ctx.OpenDevices(func(desc *gousb.DeviceDesc) bool { | |
| fmt.Printf("%03d.%03d %s:%s %s\n", desc.Bus, desc.Address, desc.Vendor, desc.Product, usbid.Describe(desc)) | |
| return false | |
| }) | |
| defer func() { | |
| for _, d := range devs { | |
| d.Close() | |
| } | |
| }() | |
| if err != nil { | |
| log.Fatalf("list: %s", err) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment