libnbd-golang(3) LIBNBD libnbd-golang(3)

# [NAME](#NAME)

libnbd-golang - how to use libnbd from Go

# [SYNOPSIS](#SYNOPSIS)

```
 import "libguestfs.org/libnbd"
 h, err := libnbd.Create()
 if err != nil {
     panic(err)
 }
 defer h.Close()
 uri := "nbd://localhost"
 err = h.ConnectUri(uri)
 if err != nil {
     panic(err)
 }
 size, err := h.GetSize()
 if err != nil {
     panic(err)
 }
 fmt.Printf("size of %s = %d\n", uri, size)
```

# [DESCRIPTION](#DESCRIPTION)

This manual page documents how to use libnbd to access Network Block [Device (NBD)](/man/os/libnbd/Device.NBD) servers from the Go programming language. The Go bindings work very similarly to the C bindings so you should start by reading [**libnbd**(3)](/man/os/libnbd/libnbd.3).

# [HANDLES](#HANDLES)

Create a libnbd handle of type "Libnbd" by calling Create().

You can either close the handle explicitly by a deferred call to "h.Close()" or it will be closed automatically when it is garbage collected.

# [ERRORS](#ERRORS)

Most calls return either a single "LibnbdError" or a pair "(ret, LibnbdError)".

# [EXAMPLES](#EXAMPLES)

This directory contains examples written in Go:

https://gitlab.com/nbdkit/libnbd/tree/master/golang/examples

# [SEE ALSO](#SEE_ALSO)

[**libnbd**(3)](/man/os/libnbd/libnbd.3).

# [AUTHORS](#AUTHORS)

Richard W.M. Jones

# [COPYRIGHT](#COPYRIGHT)

Copyright Red Hat

# [LICENSE](#LICENSE)

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

2026-10-11 libnbd-1.25.7

---

Document: libnbd-golang(3) from libnbd 1.25.7-r3 (Chainguard OS)
