How to use the go-libvirt library
mainThe go-libvirt package provides a pure Go interface for interacting with libvirt via its RPC interface (using XDR encoding).
Mapping libvirt C functions to Go
Functions in the Go package are mapped from the libvirt C API by removing the vir prefix. For example:
virDomainShutdown()becomesDomainShutdown()virDomainShutdownFlags()becomesDomainShutdownFlags()
Best Practices
- Use generated code: Most of the library is generated. While
libvirt.gocontains some hand-written routines, it is recommended to call the generated routines inlibvirt.gen.godirectly, as the hand-written ones may be removed in future versions. - Vendoring: Because the API is not considered stable, it is highly recommended to vendor
go-libvirtinto your project. - Error Handling: Always check for errors returned by connection and API calls, as the library may return 'unimplemented' errors if the generated code does not match your local libvirt version.