本文整理匯總了Golang中zc-common-go/glog.Errorf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Errorf函數的具體用法?Golang Errorf怎麽用?Golang Errorf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Errorf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getMemberAllHomes
// get all homes created by uid or uid as a member
func (this *MemberManager) getMemberAllHomes(domain string, uid int64) ([]int64, error) {
SQL := fmt.Sprintf("SELECT hid FROM %s_home_members WHERE uid = ?", domain)
stmt, err := this.store.db.Prepare(SQL)
if err != nil {
log.Errorf("prepare query failed:domain[%s], uid[%d], err[%v]",
domain, uid, err)
return nil, err
}
defer stmt.Close()
rows, err := stmt.Query(uid)
if err != nil {
log.Errorf("query all homes failed:domain[%s], uid[%d], err[%v]",
domain, uid, err)
return nil, err
}
var hid int64
list := make([]int64, 0)
for rows.Next() {
err = rows.Scan(&hid)
if err != nil {
log.Warningf("parse the result failed:domain[%s], uid[%d], err[%v]",
domain, uid, err)
return nil, err
}
list = append(list, hid)
}
return list, nil
}
示例2: modifyDeviceInfo
// modify device info all column can be modified
func (this *DeviceManager) modifyDeviceInfo(checkStatus bool, domain string, did int64, key string, value interface{}) error {
common.CheckParam(len(key) != 0)
var SQL string
if checkStatus {
SQL = fmt.Sprintf("UPDATE %s_device_info SET %s = ? WHERE did = ? AND status = %d", domain, key, ACTIVE)
} else {
SQL = fmt.Sprintf("UPDATE %s_device_info SET %s = ? WHERE did = ?", domain, key)
}
stmt, err := this.store.db.Prepare(SQL)
if err != nil {
log.Errorf("prepare query failed:err[%v]", err)
return err
}
defer stmt.Close()
result, err := stmt.Exec(value, did)
if err != nil {
log.Errorf("execute update failed:domain[%s], key[%s], value[%v], err[%v]", domain, key, value, err)
return err
}
affect, err := result.RowsAffected()
if err != nil {
log.Warningf("get affected rows failed:err[%v]", err)
return err
}
if affect != 1 {
log.Warningf("update device info failed:domain[%s], key[%s], value[%v], err[%v]", domain, key, value, err)
return common.ErrEntryNotExist
}
return nil
}
示例3: modifyHome
////////////////////////////////////////////////////////////////////////////////////
// database related private interface
////////////////////////////////////////////////////////////////////////////////////
func (this *HomeManager) modifyHome(domain string, hid int64, key string, value interface{}) error {
SQL := fmt.Sprintf("UPDATE %s_home_info SET %s = ? WHERE hid = ?", domain, key)
stmt, err := this.store.db.Prepare(SQL)
if err != nil {
log.Errorf("prepare query failed:err[%v]", err)
return err
}
defer stmt.Close()
result, err := stmt.Exec(value, hid)
if err != nil {
log.Errorf("execute update failed:sql[%s], err[%v]", SQL, err)
return err
}
affect, err := result.RowsAffected()
if err != nil {
log.Warningf("affected rows failed:err[%v]", err)
return err
}
if affect < 1 {
log.Warningf("check affected rows failed:domain[%s], hid[%d], row[%d]", domain, hid, affect)
return common.ErrAccountNotExist
} else if affect > 1 {
log.Errorf("check affected rows failed:domain[%s], key[%s], value[%v], hid[%d], row[%d]",
domain, key, value, hid, affect)
return common.ErrUnknown
}
return nil
}
示例4: ChangeDeviceBinding
func (this *BindingProxy) ChangeDeviceBinding(did int64, domain, subDomain, deviceId string) error {
if this.cacheOn {
this.cache.Delete(domain, did)
}
SQL1 := fmt.Sprintf("UPDATE %s_device_mapping SET sub_domain = ?, device_id = ?, bind_token = NULL WHERE did = ?", domain)
stmt, err := this.store.db.Prepare(SQL1)
if err != nil {
log.Errorf("prepare update mapping failed:domain[%s], device[%s:%s], err[%v]", domain, subDomain, deviceId, err)
return err
}
defer stmt.Close()
result, err := stmt.Exec(subDomain, deviceId, did)
if err != nil {
log.Errorf("execute update failed:domain[%s], device[%s:%s], err[%v]", domain, subDomain, deviceId, err)
return err
}
affect, err := result.RowsAffected()
if err != nil {
log.Warningf("get affected rows failed:err[%v]", err)
return err
}
if affect != 1 {
log.Errorf("check affected rows failed:domain[%s], device[%s:%s], err[%v]", domain, subDomain, deviceId, err)
return common.ErrEntryNotExist
}
return nil
}
示例5: Start
// the device point gateway start listen
func (this *DeviceGatewayServer) Start(host string) error {
common.Assert((this.connManager != nil) && (this.devManager != nil), "check param nil")
addr, err := net.ResolveTCPAddr("tcp4", host)
if err != nil {
log.Errorf("resolve tcp addr error:err[%v]", err)
return err
}
ln, err := net.ListenTCP("tcp", addr)
if err != nil {
log.Errorf("listen error:err[%v]", err)
return err
}
var waitGroup sync.WaitGroup
for {
socket, err := ln.AcceptTCP()
if err != nil {
log.Errorf("accept error:err[%v]", err)
continue
}
log.Infof("device connect start:addr[%s]", socket.RemoteAddr())
waitGroup.Add(1)
go this.deviceRoutine(&waitGroup, socket, QueueLen)
}
waitGroup.Wait()
return err
}
示例6: getAllMembers
func (this *MemberManager) getAllMembers(domain string, hid int64) ([]Member, error) {
SQL := fmt.Sprintf("SELECT uid, hid, name, type, status FROM %s_home_members WHERE hid = ?", domain)
stmt, err := this.store.db.Prepare(SQL)
if err != nil {
log.Errorf("prepare query failed:domain[%s], hid[%d], err[%v]", domain, hid, err)
return nil, err
}
defer stmt.Close()
rows, err := stmt.Query(hid)
if err != nil {
log.Errorf("query all members failed:domain[%s], hid[%d], err[%v]",
domain, hid, err)
return nil, err
}
defer rows.Close()
var member Member
list := make([]Member, 0)
for rows.Next() {
err := rows.Scan(&member.uid, &member.hid, &member.memberName, &member.memberType, &member.status)
if err != nil {
log.Errorf("parse the uid failed:domain[%s], hid[%d], err[%v]",
domain, hid, err)
return nil, err
}
list = append(list, member)
}
return list, nil
}
示例7: modifyMemberInfo
// modify member info all column can be modified
func (this *MemberManager) modifyMemberInfo(domain string, hid, uid int64, key string, value interface{}) error {
common.CheckParam(len(key) != 0)
SQL := fmt.Sprintf("UPDATE %s_home_members SET %s = ? WHERE uid = ? AND hid = ?", domain, key)
stmt, err := this.store.db.Prepare(SQL)
if err != nil {
log.Errorf("prepare query failed:err[%v]", err)
return err
}
defer stmt.Close()
result, err := stmt.Exec(value, uid, hid)
if err != nil {
log.Errorf("execute update failed:sql[%s], err[%v]", SQL, err)
return err
}
affect, err := result.RowsAffected()
if err != nil {
log.Warningf("get affected rows failed:err[%v]", err)
return err
}
if affect < 1 {
log.Warningf("check affected rows failed:domain[%s], hid[%d], uid[%d], row[%d]", domain, hid, uid, affect)
return common.ErrEntryNotExist
} else if affect > 1 {
log.Errorf("check affected rows failed:domain[%s], hid[%d], uid[%d], row[%d]", domain, hid, uid, affect)
return common.ErrUnknown
}
return nil
}
示例8: handleDevResponse
// handle device response message forward to the result channel
func (this *Connection) handleDevResponse(packet *common.Message) {
request, find := this.requestMap.Find(packet.Header.MsgId)
if find {
// reset to the old message id
packet.Header.MsgId = request.(*DeviceCtrlRequest).oldMessageId
defer func() {
info := recover()
if info != nil {
log.Warningf("the response queue is closed:err[%v]", info)
}
_, exist := this.requestMap.Delete(packet.Header.MsgId)
if !exist {
log.Errorf("delete request failed:mid[%d], code[%d], dest[%s], gid[%s]",
packet.Header.MsgId, packet.Header.MsgCode, this.socket.RemoteAddr(), this.gid.String())
}
log.Infof("delete the request mapping succ:mid[%d], code[%d], dest[%s], gid[%s]",
packet.Header.MsgId, packet.Header.MsgCode, this.socket.RemoteAddr(), this.gid.String())
}()
// if closed will panic
*(request.(*DeviceCtrlRequest).responseQueue) <- *packet
} else {
log.Errorf("check the dev response not find request:mid[%d], code[%d], dest[%s], gid[%s]",
packet.Header.MsgId, packet.Header.MsgCode, this.socket.RemoteAddr(), this.gid.String())
}
}
示例9: GetDeviceInfo
// if not find in database return nil + nil
func (this *WarehouseProxy) GetDeviceInfo(domain, subDomain, deviceId string) (*BasicInfo, error) {
if this.cacheOn {
basic, find := this.cache.Get(domain, subDomain, deviceId)
if find {
log.Infof("get device basic info from cache:domain[%s], device[%s:%s]", domain, subDomain, deviceId)
return basic, nil
}
}
SQL := fmt.Sprintf("SELECT device_type, public_key, status FROM %s_device_warehouse WHERE sub_domain = ? AND device_id = ?", domain)
stmt, err := this.store.db.Prepare(SQL)
if err != nil {
log.Errorf("prepare query failed:err[%v]", err)
return nil, err
}
defer stmt.Close()
basic := NewBasicInfo()
err = stmt.QueryRow(subDomain, deviceId).Scan(&basic.deviceType, &basic.publicKey, &basic.status)
if err != nil {
if err == sql.ErrNoRows {
log.Warningf("no find the device:domain[%s], device[%s:%s]", domain, subDomain, deviceId)
return nil, nil
}
log.Errorf("query failed:domain[%s], device[%s:%s]", domain, subDomain, deviceId)
return nil, err
}
basic.subDomain = subDomain
basic.deviceId = deviceId
if this.cacheOn {
this.cache.Set(domain, basic)
}
return basic, nil
}
示例10: NewBindingManager
func NewBindingManager(store *DeviceStorage) *BindingManager {
warehouse := NewDeviceWarehouse(store)
if warehouse == nil {
log.Errorf("new device warehouse failed")
return nil
}
proxy := newBindingProxy(store)
if proxy == nil {
log.Errorf("new binding proxy failed")
return nil
}
return &BindingManager{store: store, warehouse: warehouse, proxy: proxy}
}
示例11: deleteHome
func (this *HomeManager) deleteHome(domain string, hid int64) error {
SQL := fmt.Sprintf("DELETE FROM %s_home_info WHERE hid = ?", domain)
stmt, err := this.store.db.Prepare(SQL)
if err != nil {
log.Errorf("prepare query failed:err[%v]", err)
return err
}
defer stmt.Close()
_, err = stmt.Exec(hid)
if err != nil {
log.Errorf("insert a new home failed:domain[%s], hid[%d], err[%v]", domain, hid, err)
return err
}
return nil
}
示例12: InsertDeviceInfo
func (this *WarehouseProxy) InsertDeviceInfo(domain, subDomain, deviceId, publicKey string, master bool) error {
var SQL string
if master {
SQL = fmt.Sprintf("INSERT INTO %s_device_warehouse(sub_domain, device_id, device_type, public_key, status) VALUES(?,?,?,?,?)", domain)
} else {
SQL = fmt.Sprintf("INSERT INTO %s_device_warehouse(sub_domain, device_id, device_type, status) VALUES(?,?,?,?)", domain)
}
stmt, err := this.store.db.Prepare(SQL)
if err != nil {
log.Errorf("prepare query failed:err[%v]", err)
return err
}
defer stmt.Close()
if master {
_, err = stmt.Exec(subDomain, deviceId, MASTER, publicKey, ACTIVE)
} else {
_, err = stmt.Exec(subDomain, deviceId, NORMAL, ACTIVE)
}
if err != nil {
log.Warningf("execute insert device[%s:%s] failed:domain[%s], err[%v]", subDomain, deviceId, domain, err)
return err
}
if this.cacheOn {
this.cache.Delete(domain, subDomain, deviceId)
}
return nil
}
示例13: IsBindingExist
func (this *BindingProxy) IsBindingExist(domain string, did int64, exist *bool) error {
if this.cacheOn {
_, find := this.cache.Get(domain, did)
if find {
*exist = true
return nil
}
}
SQL := fmt.Sprintf("SELECT did FROM %s_device_mapping WHERE did = ?", domain)
stmt, err := this.store.db.Prepare(SQL)
if err != nil {
log.Errorf("prepare query failed:domain[%s], did[%d], err[%v]", domain, did, err)
return err
}
defer stmt.Close()
var value int64
err = stmt.QueryRow(did).Scan(&value)
if err != nil {
if err == sql.ErrNoRows {
*exist = false
} else {
log.Warningf("get binding info failed:domain[%s], did[%d], err[%v]", domain, did, err)
return err
}
}
*exist = true
return nil
}
示例14: GetBindingInfo
// get by device global key, if not exist return nil + nil
func (this *BindingProxy) GetBindingInfo(domain, subDomain, deviceId string) (*BindingInfo, error) {
SQL := fmt.Sprintf("SELECT did, bind_token, expire_time FROM %s_device_mapping WHERE sub_domain = ? AND device_id = ?", domain)
stmt, err := this.store.db.Prepare(SQL)
if err != nil {
log.Errorf("prepare query failed:domain[%s], device[%s:%s], err[%v]",
domain, subDomain, deviceId, err)
return nil, err
}
defer stmt.Close()
bind := NewBindingInfo()
err = stmt.QueryRow(subDomain, deviceId).Scan(&bind.did, &bind.grantToken, &bind.grantTime)
if err != nil {
if err != sql.ErrNoRows {
log.Warningf("query binding info failed:domain[%s], device[%s:%s], err[%v]",
domain, subDomain, deviceId, err)
} else {
err = common.ErrEntryNotExist
}
return nil, err
}
bind.subDomain = subDomain
bind.deviceId = deviceId
if this.cacheOn {
this.cache.Set(domain, bind)
}
return bind, nil
}
示例15: rollback
//////////////////////////////////////////////////////////////////////////////
/// private interface related to database
//////////////////////////////////////////////////////////////////////////////
// transaction rollback according to the error status
func rollback(err *error, tx *sql.Tx) {
if *err != nil {
log.Infof("error occured rollback:err[%v]", *err)
newErr := tx.Rollback()
if newErr != nil {
log.Errorf("rollback failed:err[%v]", newErr)
}
}
}