Post · 1 min read· pp. 32–33

Simple extended attribute support for Go

This afternoon I sat down and polished up the extended attribute library I have been working on for a while. You can find the code and readme on Github.

https://github.com/davecheney/xattr

This has been tested on linux (should work under 5g, 6g and 8g) and darwin (tested under Snow Leopard).

Installation

text
goinstall github.com/davecheney/xattr

Documentation

text
godoc github.com/davecheney/xattr

Usage

A example program is provided with the source. The simplest way to compile and install it is

text
make -C $GOROOT/src/pkg/github.com/davecheney/xattr/example clean install

This will install it to your $GOBIN directory. If you have trouble running this example, make sure there isn’t another xattr somewhere higher in your $PATH.

Before you start

All extended attributes need a file to be associated with. In this example I’m going to create an empty file in my home directory.

text
touch ~/testfile

Setting an attribute

text
% $GOBIN/xattr -w username dave ~/testfile

Listing known attributes

text
% $GOBIN/xattr ~/testfile
username

Printing attribute values

text
% $GOBIN/xattr -p username ~/testfile
dave

Listing names and values

text
% $GOBIN/xattr -l ~/testfile
 username: dave