Skip to content

Instantly share code, notes, and snippets.

@christopherobin
Created August 19, 2013 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christopherobin/6268335 to your computer and use it in GitHub Desktop.
Save christopherobin/6268335 to your computer and use it in GitHub Desktop.
Working an ALPM (ArchLinux Package Manager) library for Go
package alpm
// #cgo LDFLAGS: -lalpm
// #include <alpm.h>
import "C"
//import "fmt"
import "errors"
type ALPM struct {
Root string
DBPath string
// private stuff
handle *C.alpm_handle_t
}
func CreateALPM(root, dbpath string) ALPM {
return ALPM{root, dbpath, nil}
}
func (alpm *ALPM) Initialize() error {
var result C.alpm_errno_t
alpm.handle = C.alpm_initialize(C.CString(alpm.Root), C.CString(alpm.DBPath), &result)
if (result != 0) {
return errors.New(C.GoString(C.alpm_strerror(result)))
}
return nil
}
func (alpm *ALPM) Release() error {
n, err := C.alpm_release(alpm.handle)
// reset handle
alpm.handle = nil;
if (n != 0) {
return errors.New("Couldn't release handle")
}
if (err != nil) {
return err
}
return nil
}
func (alpm *ALPM) GetLocalDb() DB {
db := C.alpm_get_localdb(alpm.handle)
return DB{db}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment