X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=bindings%2Fgo%2Fpkg%2Fnotmuch.go;h=e065b547ab8bbca0c27de968cac48b28d3ef9fc9;hb=0af7295faf56d5c469a9b47ad253ea5b146b0975;hp=de9de23c0e8cad21f4c587a574aac50ce696b451;hpb=ce53850290e81ace34af5a1d418cc8941d0d3b8f;p=notmuch diff --git a/bindings/go/pkg/notmuch.go b/bindings/go/pkg/notmuch.go index de9de23c..e065b547 100644 --- a/bindings/go/pkg/notmuch.go +++ b/bindings/go/pkg/notmuch.go @@ -14,7 +14,7 @@ import "unsafe" // Status codes used for the return values of most functions type Status C.notmuch_status_t const ( - STATUS_SUCCESS Status = 0 + STATUS_SUCCESS Status = iota STATUS_OUT_OF_MEMORY STATUS_READ_ONLY_DATABASE STATUS_XAPIAN_EXCEPTION @@ -86,21 +86,21 @@ const ( ) // Create a new, empty notmuch database located at 'path' -func NewDatabase(path string) *Database { +func NewDatabase(path string) (*Database, Status) { var c_path *C.char = C.CString(path) defer C.free(unsafe.Pointer(c_path)) if c_path == nil { - return nil + return nil, STATUS_OUT_OF_MEMORY } self := &Database{db:nil} - self.db = C.notmuch_database_create(c_path) - if self.db == nil { - return nil + st := Status(C.notmuch_database_create(c_path, &self.db)) + if st != STATUS_SUCCESS { + return nil, st } - return self + return self, st } /* Open an existing notmuch database located at 'path'. @@ -120,21 +120,21 @@ func NewDatabase(path string) *Database { * In case of any failure, this function returns NULL, (after printing * an error message on stderr). */ -func OpenDatabase(path string, mode DatabaseMode) *Database { +func OpenDatabase(path string, mode DatabaseMode) (*Database, Status) { var c_path *C.char = C.CString(path) defer C.free(unsafe.Pointer(c_path)) if c_path == nil { - return nil + return nil, STATUS_OUT_OF_MEMORY } self := &Database{db:nil} - self.db = C.notmuch_database_open(c_path, C.notmuch_database_mode_t(mode)) - if self.db == nil { - return nil + st := Status(C.notmuch_database_open(c_path, C.notmuch_database_mode_t(mode), &self.db)) + if st != STATUS_SUCCESS { + return nil, st } - return self + return self, st } /* Close the given notmuch database, freeing all associated