本文整理匯總了Golang中zc-common-go/glog.Infof函數的典型用法代碼示例。如果您正苦於以下問題:Golang Infof函數的具體用法?Golang Infof怎麽用?Golang Infof使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Infof函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleCreate
func (s *ZStoreStub) handleCreate(req *zc.ZMsg, resp *zc.ZMsg) {
payload, _ := req.GetPayload()
if !req.CheckString("zc-class") ||
!req.CheckObject("zc-object") {
resp.SetErr("invalid create request")
log.Infof("invalid create request: %s", string(payload))
return
}
className := req.GetString("zc-class")
if !s.checkClass(className) {
resp.SetErr("invalid class name")
log.Infof("invalid create request: %s", string(payload))
return
}
classStore := s.store[className]
if classStore == nil {
s.store[className] = make(map[string]zc.ZObject, 10)
classStore = s.store[className]
}
zo := req.GetObject("zc-object")
primaryKey := s.getPrimaryKey(className, zo)
classStore[primaryKey] = zo
resp.SetAck()
resp.Put("zc-object", zo)
}
示例2: handleUpdate
func (s *ZStoreStub) handleUpdate(req *zc.ZMsg, resp *zc.ZMsg) {
payload, _ := req.GetPayload()
if !req.CheckExists("zc-class", "zc-object") {
resp.SetErr("invalid update request")
log.Infof("invalid delete request: %s", string(payload))
return
}
className := req.GetString("zc-class")
if !s.checkClass(className) {
resp.SetErr("invalid class name")
log.Infof("invalid update request: %s", string(payload))
return
}
classStore := s.store[className]
if classStore == nil {
s.store[className] = make(map[string]zc.ZObject, 10)
classStore = s.store[className]
}
zo := req.GetObject("zc-object")
primaryKey := s.getPrimaryKey(className, zo)
oldZO := classStore[primaryKey]
if oldZO != nil {
for _, key := range zo.GetKeys() {
oldZO.Put(key, zo.Get(key))
}
}
resp.SetAck()
return
}
示例3: handleDelete
func (s *ZStoreStub) handleDelete(req *zc.ZMsg, resp *zc.ZMsg) {
payload, _ := req.GetPayload()
if !req.CheckExists("zc-class", "zc-object") {
resp.SetErr("invalid delete request")
log.Infof("invalid delete request: %s", string(payload))
return
}
className := req.GetString("zc-class")
if !s.checkClass(className) {
resp.SetErr("invalid class name")
log.Infof("invalid create request: %s", string(payload))
return
}
classStore := s.store[className]
if classStore == nil || len(classStore) <= 0 {
resp.SetAck()
return
}
zo := req.GetObject("zc-object")
primaryKey := s.getPrimaryKey(className, zo)
delete(classStore, primaryKey)
resp.SetAck()
return
}
示例4: getMap
func getMap() map[string]int {
var test map[string]int = make(map[string]int)
test2 := test
log.Infof("%p", test)
log.Infof("%p", test2)
return test2
}
示例5: SendRequest
// async send request to device and wait the response on result
func (this *Connection) SendRequest(packet *common.Message, result *chan common.Message) (err error) {
common.Assert(packet != nil && result != nil, "check input param failed")
oldId := packet.Header.MsgId
log.Infof("receive new Request from app:msgId[%d]", oldId)
request := NewDeviceCtrlRequest(oldId, result)
// rewrite the msg id as the connection new id
packet.Header.MsgId = this.getNewRequestId()
err = this.requestMap.Insert(packet.Header.MsgId, request)
if err != nil {
log.Warningf("check request insert failed:old[%d], new[%d]", oldId, packet.Header.MsgId)
return err
}
log.Infof("insert the request mapping succ:mid[%d], code[%d], dest[%v], gid[%s]",
packet.Header.MsgId, packet.Header.MsgCode, this.socket.RemoteAddr(), this.gid.String())
// if the dev connection closed panic will occured
defer func() {
packet.Header.MsgId = oldId
info := recover()
if info != nil {
log.Warningf("the request queue is closed:err[%v]", info)
err = common.ErrDeviceConnClosed
}
}()
this.requestQueue <- *packet
return nil
}
示例6: Start
func (s *ZService) Start() error {
log.Infof("begin to listen and servie: port=%s", s.port)
err := http.ListenAndServe(":"+s.port, s)
if err != nil {
log.Infof("listenAndServe failed: %s", err.Error())
}
return err
}
示例7: Send
func (c *ZServiceClient) Send(req *ZMsg) (resp *ZMsg, err error) {
if req.hasObjectData() {
err = req.encodeObject()
if err != nil {
return nil, err
}
}
url := "http://" + c.serviceAddr + "/" + c.serviceName + "/" + req.GetName()
payload, payloadFormat := req.GetPayload()
log.Infof("client send req: serive=%s; name=%s; payload=%s",
c.serviceName, req.GetName(), string(payload))
httpReq, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
if err != nil {
return nil, errors.New("failed to create http req")
}
httpReq.Header.Set("Content-Type", payloadFormat)
httpResp, err := http.DefaultClient.Do(httpReq)
if err != nil {
return nil, err
}
resp = NewZMsg()
resp.SetName(httpResp.Header.Get(ZC_MSG_NAME_HEADER))
if httpResp.ContentLength <= 0 {
return resp, nil
}
if httpResp.Header.Get("Content-Type") != ZC_MSG_PAYLOAD_OBJECT {
return nil, errors.New("wrong resp format, only support text/json")
}
respPayload := make([]byte, httpResp.ContentLength)
l, err := httpResp.Body.Read(respPayload)
if err != nil {
return nil, err
}
if l != len(respPayload) {
return nil, errors.New("failed to read http resp body")
}
log.Infof("client get resp: serive=%s; name=%s; payload=%s",
c.serviceName, resp.GetName(), string(respPayload))
resp.SetPayload(respPayload, httpResp.Header.Get("Content-Type"))
err = resp.decodeObject()
if err != nil {
return nil, err
}
return resp, err
}
示例8: Loop
func (this *Connection) Loop(waitGroup *sync.WaitGroup) {
// AFTER THIS ALL THE MESSAGE USING AES
this.contex.EncryptType = common.ZC_SEC_TYPE_AES
this.contex.SessionKey = this.sessionKey
// process write queue in the new routine
waitGroup.Add(1)
go func() {
// request packet
var requestPacket common.Message
for !this.exit {
select {
case requestPacket = <-this.requestQueue:
// write the packet to read queue
fmt.Println("[DEV] send the new Request Message to device:", requestPacket.Header.MsgId)
err := common.Send(this.socket, this.contex, &requestPacket, common.DEV_WRITE_TIMEOUT)
if err != nil {
log.Warningf("forward the packet failed:err[%v]", err)
this.exit = true
break
}
// wait the empty response for the requestPacket
// if not wait empty succ, can not send the next request
// from the requestQueue....
this.waitEmptyResponse(&requestPacket)
fmt.Println("[DEV] wait Empty Response succ:", requestPacket.Header.MsgId)
}
}
log.Infof("forward device request routine exit:dest[%v]", this.socket.RemoteAddr())
waitGroup.Done()
}()
// process the read empty or response or report message
var devMessage common.Message
for !this.exit {
// read the packet and dispatch to the processor
err := common.Receive(this.socket, this.contex, &devMessage, common.DEV_READ_TIMEOUT)
if err != nil {
log.Warningf("read the packet failed:dest[%v], err[%v]", this.socket.RemoteAddr(), err)
this.exit = true
break
}
fmt.Println("[DEV] Receive message from device succ", devMessage.Header.String())
// TODO if too long not receive dev message, close it
// Handle Dev Message three different type
// repsonse Ack + response Empty + request Report
// WARNING:can not blocked here...
this.handleDevMessage(&devMessage)
fmt.Println("[DEV] Handle dev message finish:", time.Now().UTC(), devMessage.Header, this.socket.RemoteAddr())
}
log.Infof("device routine exit succ:dest[%v], gid[%s]", this.socket.RemoteAddr(), this.gid.String())
}
示例9: handleQuery
func (s *ZStoreStub) handleQuery(req *zc.ZMsg, resp *zc.ZMsg) {
payload, _ := req.GetPayload()
if !req.CheckExists("zc-class", "zc-query") {
resp.SetErr("invalid query request")
log.Infof("invalid query request: %s", string(payload))
return
}
className := req.GetString("zc-class")
if !s.checkClass(className) {
resp.SetErr("invalid class name")
log.Infof("invalid query request: %s", string(payload))
return
}
classStore := s.store[className]
if classStore == nil {
resp.SetAck()
return
}
query := req.GetObject("zc-query")
if !query.CheckExists("zc-eq") {
resp.SetErr("no eq condition to find objects")
return
}
eq := query.GetObject("zc-eq")
selectKeys := query.GetStrings("zc-select")
primaryKey := s.getPrimaryKey(className, eq)
dataZO := classStore[primaryKey]
if dataZO == nil {
resp.SetAck()
return
}
selectZO := zc.NewObject()
if len(selectKeys) <= 0 {
selectZO = dataZO
} else {
for _, key := range selectKeys {
selectZO.Put(key, dataZO.Get(key))
}
}
resp.SetAck()
resp.AddObject("zc-objects", selectZO)
return
}
示例10: 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
}
示例11: 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())
}
}
示例12: 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
}
示例13: writeResp
func (s *ZService) writeResp(resp *ZMsg, w http.ResponseWriter) {
if resp.hasObjectData() {
err := resp.encodeObject()
if err != nil {
w.Header().Set("Content-Length", "0")
w.Header().Set(ZC_MSG_NAME_HEADER, ZC_MSG_NAME_ERR)
return
}
}
payload, payloadFormat := resp.GetPayload()
if payload == nil {
w.Header().Set("Content-Length", "0")
} else {
w.Header().Set("Content-Length", strconv.Itoa(len(payload)))
}
w.Header().Set("Content-Type", payloadFormat)
w.Header().Set(ZC_MSG_NAME_HEADER, resp.GetName())
if len(payload) > 0 {
n, err := w.Write(payload)
if n != len(payload) || err != nil {
log.Infof("write payload failed: n=%d, err=%s", n, err.Error())
}
}
}
示例14: handleFind
func (s *ZStoreStub) handleFind(req *zc.ZMsg, resp *zc.ZMsg) {
payload, _ := req.GetPayload()
if !req.CheckExists("zc-class", "zc-find") {
resp.SetErr("invalid find request")
log.Infof("invalid find request: %s", string(payload))
return
}
className := req.GetString("zc-class")
if !s.checkClass(className) {
resp.SetErr("invalid class name")
log.Infof("invalid find request: %s", string(payload))
return
}
classStore := s.store[className]
if classStore == nil {
resp.SetAck()
return
}
find := req.GetObject("zc-find")
zo := find.GetObject("zc-object")
selectKeys := find.GetStrings("zc-select")
primaryKey := s.getPrimaryKey(className, zo)
dataZO := classStore[primaryKey]
if dataZO == nil {
resp.SetAck()
return
}
if len(selectKeys) <= 0 {
resp.SetAck()
resp.Put("zc-object", dataZO)
return
}
selectZO := zc.NewObject()
for _, key := range selectKeys {
selectZO.Put(key, dataZO.Get(key))
}
resp.SetAck()
resp.Put("zc-object", selectZO)
return
}
示例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)
}
}
}