Ai
4 Star 10 Fork 4

Gitee 极速下载/go-dqlite

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/canonical/go-dqlite
克隆/下载
errors.go 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
Free Ekanayaka 提交于 2018-07-31 22:48 +08:00 . Cleanup Go bindings for dqlite_cluster
package bindings
/*
#include <sqlite3.h>
*/
import "C"
import (
"github.com/pkg/errors"
)
// Error holds information about a SQLite error.
type Error struct {
Code int
Message string
}
func (e Error) Error() string {
if e.Message != "" {
return e.Message
}
return C.GoString(C.sqlite3_errstr(C.int(e.Code)))
}
// Error codes.
const (
ErrError = C.SQLITE_ERROR
ErrInternal = C.SQLITE_INTERNAL
ErrNoMem = C.SQLITE_NOMEM
ErrInterrupt = C.SQLITE_INTERRUPT
ErrBusy = C.SQLITE_BUSY
ErrIoErr = C.SQLITE_IOERR
ErrIoErrNotLeader = C.SQLITE_IOERR_NOT_LEADER
ErrIoErrLeadershipLost = C.SQLITE_IOERR_LEADERSHIP_LOST
)
// ErrorCode extracts a SQLite error code from a Go error.
func ErrorCode(err error) int {
if err, ok := errors.Cause(err).(Error); ok {
return err.Code
}
// Return a generic error.
return int(C.SQLITE_ERROR)
}
// Create a Go error with the code and message of the last error happened on
// the given database.
func lastError(db *C.sqlite3) Error {
return Error{
Code: int(C.sqlite3_extended_errcode(db)),
Message: C.GoString(C.sqlite3_errmsg(db)),
}
}
// codeToError converts a SQLite error code to a Go error.
func codeToError(rc C.int) error {
return Error{Code: int(rc)}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/go-dqlite.git
git@gitee.com:mirrors/go-dqlite.git
mirrors
go-dqlite
go-dqlite
v0.9.4

搜索帮助