package util import ( "log" "github.com/jaypipes/pcidb" ) var ( pcidbInitDone = false db *pcidb.PCIDB ) const ( pcidbNOTFOUND string = `NOTFOUND` pcidbNODB string = `NODBFOUND` ) func initPCIDB() { var err error // Attempt to use local sources first, fallback to network if // local sources aren't found db, err = pcidb.New() if err != nil { log.Printf("warning: couldn't use local pcidb cache: %s", err) log.Println("falling back to downloading database") db, err = pcidb.New(pcidb.WithEnableNetworkFetch()) if err != nil { log.Println("error: couldn't get pcidb. no more fallbacks available, will not be able to query the pcidb") } } pcidbInitDone = true } func GetPCIClass(id string) string { if !pcidbInitDone { initPCIDB() } if pcidbInitDone && db == nil { log.Println("unable to access pcidb") return pcidbNODB } if class, ok := db.Classes[id]; ok { return class.Name } return pcidbNOTFOUND }