Skip to content

Instantly share code, notes, and snippets.

@atotto
Created December 20, 2017 05:12
Show Gist options
  • Select an option

  • Save atotto/91b50bbaab569afad429619215e73c2d to your computer and use it in GitHub Desktop.

Select an option

Save atotto/91b50bbaab569afad429619215e73c2d to your computer and use it in GitHub Desktop.
lsusb (golang)
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