當前位置: 首頁>>代碼示例>>Golang>>正文


Golang log.Warningf函數代碼示例

本文整理匯總了Golang中github.com/oikomi/FishChatServer/log.Warningf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Warningf函數的具體用法?Golang Warningf怎麽用?Golang Warningf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Warningf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: procRouteTopicMsg

/*
   通過Router轉發消息(對終端開發者不可見)
   Router -> MsgServer
       ROUTE_SEND_TOPIC_MSG_CMD
       arg0: Msg           //消息內容
       arg1: TopicName     //群組名
       arg2: ClientID      //發送方用戶ID
       arg3: ClientType    //發送方終端類型,是client還是device
*/
func (self *ProtoProc) procRouteTopicMsg(cmd protocol.Cmd, session *libnet.Session) error {
	log.Info("procRouteTopicMsg")
	var err error

	//send2Msg := cmd.GetArgs()[0]
	topicName := cmd.GetArgs()[1]
	//fromID := cmd.GetArgs()[2]
	//fromType := cmd.GetArgs()[3]

	// check whether the topic exist
	topicCacheData, err := self.msgServer.topicCache.Get(topicName)
	if topicCacheData == nil {
		log.Warningf("TOPIC %s not exist: %s", topicName, err.Error())
		return common.TOPIC_NOT_EXIST
	}

	cmd.ChangeCmdName(protocol.IND_SEND_TOPIC_MSG_CMD)

	// exactly in this server, just broadcasting
	log.Warningf("topic %s has %d member(s) in this server", topicName, topicCacheData.AliveMemberNumMap[self.msgServer.cfg.LocalIP])
	for _, mID := range topicCacheData.MemberList {
		if self.msgServer.sessions[mID.ID] != nil {
			self.msgServer.sessions[mID.ID].Send(libnet.Json(cmd))
			if err != nil {
				log.Fatalln(err.Error())
			}
		}
	}

	return nil
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:40,代碼來源:proto_proc.go

示例2: procAdd2Topic

/*
   client -> MsgServer
       REQ_ADD_2_TOPIC_CMD
       arg0: TopicName     //群組名
       arg1: NewClientID          //用戶ID
       arg2: NewClientName    //用戶在Topic中的Name, 對於device, 可以是兒子/女兒

   MsgServer -> client
       RSP_ADD_2_TOPIC_CMD
    	arg0: SUCCESS/FAILED
		arg1: TopicName
		arg2: ClientID
		arg3: ClientType
*/
func (self *ProtoProc) procAdd2Topic(cmd protocol.Cmd, session *libnet.Session) error {
	log.Info("procAdd2Topic")
	var err error

	topicName := cmd.GetArgs()[0]
	mID := cmd.GetArgs()[1]
	mName := cmd.GetArgs()[2]
	ClientID := session.State.(*base.SessionState).ClientID
	ClientType := session.State.(*base.SessionState).ClientType
	mType := protocol.DEV_TYPE_CLIENT

	resp := protocol.NewCmdSimple(protocol.RSP_ADD_2_TOPIC_CMD)

	if len(cmd.GetArgs()) != 3 {
		err = common.SYNTAX_ERROR
	} else
	// only DEV_TYPE_CLIENT CAN create topic
	if ClientType != protocol.DEV_TYPE_CLIENT {
		err = common.DENY_ACCESS
	} else {
		// check whether the topic exist
		topicCacheData, _ := self.msgServer.topicCache.Get(topicName)
		if topicCacheData == nil {
			log.Infof("TOPIC %s not exist in CACHE", topicName)
			err = common.TOPIC_NOT_EXIST
		} else
		// only topic creater can do this
		if topicCacheData.CreaterID != ClientID {
			log.Warningf("ClientID %s is not creater of topic %s", ClientID, topicName)
			err = common.DENY_ACCESS
		} else {
			// New Member MUST be online
			sessionCacheData, _ := self.msgServer.sessionCache.Get(mID)
			if sessionCacheData == nil {
				log.Warningf("Client %s not online", mID)
				err = common.NOT_ONLINE
			} else {
				mType = sessionCacheData.ClientType
				member := mongo_store.NewMember(mID, mName, mType)
				err = self.msgServer.procJoinTopic(member, topicName)
			}
		}
	}

	if err != nil {
		resp.AddArg(err.Error())
	} else {
		resp.AddArg(protocol.RSP_SUCCESS)
	}
	resp.AddArg(topicName)
	resp.AddArg(mID)
	resp.AddArg(mType)
	err = session.Send(libnet.Json(resp))
	if err != nil {
		log.Error(err.Error())
	}

	return err
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:73,代碼來源:proto_proc.go

示例3: procLogin

func (self *ProtoProc) procLogin(cmd protocol.Cmd, session *libnet.Session) error {
	//log.Info("procLogin")
	var err error
	var uuid string
	var msgServer string

	ClientID := cmd.GetArgs()[0]
	ClientType := cmd.GetArgs()[1]
	ClientPwd := ""
	if len(cmd.GetArgs()) == 3 {
		ClientPwd = cmd.GetArgs()[2]
	}

	// get the session cache
	sessionCacheData, err := self.gateway.sessionCache.Get(ClientID)
	if sessionCacheData != nil {
		log.Warningf("ID %s already login", ClientID)

		msgServer = sessionCacheData.MsgServerAddr
		uuid = sessionCacheData.ID
	} else {
		// choose msg server and allocate UUID
		msgServer = self.procGetMinLoadMsgServer()
		uuid = common.NewV4().String()
		// get the session store to check whether registered
		sessionStoreData, _ := self.gateway.mongoStore.GetSessionFromCid(ClientID)
		if sessionStoreData == nil {
			log.Warningf("ID %s not registered", ClientID)

			// for store data
			sessionStoreData = mongo_store.NewSessionStoreData(ClientID, ClientPwd, ClientType)
			log.Info(sessionStoreData)
			common.StoreData(self.gateway.mongoStore, sessionStoreData)
		}
		// for cache data, MsgServer MUST update local & remote addr.
		sessionCacheData = redis_store.NewSessionCacheData(sessionStoreData, session.Conn().RemoteAddr().String(), msgServer, uuid)
		log.Info(sessionCacheData)
		self.gateway.sessionCache.Set(sessionCacheData)
	}
	//
	resp := protocol.NewCmdSimple(protocol.RSP_LOGIN_CMD)
	resp.AddArg(protocol.RSP_SUCCESS)
	resp.AddArg(uuid)
	resp.AddArg(msgServer)

	log.Info("Resp | ", resp)

	if session != nil {
		err = session.Send(libnet.Json(resp))
		if err != nil {
			log.Error(err.Error())
		}
		session.Close()
		log.Info("client ", session.Conn().RemoteAddr().String(), " | close")
	}
	return nil
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:57,代碼來源:proto_proc.go

示例4: procKickTopic

/*
   client -> MsgServer
       REQ_KICK_TOPIC_CMD
       arg0: TopicName     //群組名
       arg1: NewClientID   //待移除的成員用戶ID

   MsgServer -> client
       RSP_KICK_TOPIC_CMD
       arg0: SUCCESS/FAILED
*/
func (self *ProtoProc) procKickTopic(cmd protocol.Cmd, session *libnet.Session) error {
	log.Info("procKickTopic")
	var err error
	var topicCacheData *redis_store.TopicCacheData

	topicName := cmd.GetArgs()[0]
	mID := cmd.GetArgs()[1]

	ClientID := session.State.(*base.SessionState).ClientID
	ClientType := session.State.(*base.SessionState).ClientType

	resp := protocol.NewCmdSimple(protocol.RSP_KICK_TOPIC_CMD)

	if len(cmd.GetArgs()) != 2 {
		err = common.SYNTAX_ERROR
		goto ErrOut
	}

	// only DEV_TYPE_CLIENT CAN do this
	if ClientType != protocol.DEV_TYPE_CLIENT {
		err = common.DENY_ACCESS
		goto ErrOut
	}

	// check whether the topic exist
	topicCacheData, err = self.msgServer.topicCache.Get(topicName)
	if topicCacheData == nil {
		log.Warningf("TOPIC %s not exist", topicName)
		err = common.TOPIC_NOT_EXIST
	} else
	// only topic creater can do this
	if topicCacheData.CreaterID != ClientID {
		log.Warningf("ClientID %s is not creater of topic %s", ClientID, topicName)
		err = common.DENY_ACCESS
	} else {
		err = self.msgServer.procQuitTopic(mID, topicName)
	}

ErrOut:
	if err != nil {
		resp.AddArg(err.Error())
	} else {
		resp.AddArg(protocol.RSP_SUCCESS)
	}
	err = session.Send(libnet.Json(resp))
	if err != nil {
		log.Error(err.Error())
	}

	return err
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:61,代碼來源:proto_proc.go

示例5: procRouteMessageP2P

func (self *ProtoProc) procRouteMessageP2P(cmd protocol.Cmd, session *libnet.Session) error {
	log.Info("procRouteMessageP2P")
	var err error
	send2ID := cmd.GetArgs()[0]
	send2Msg := cmd.GetArgs()[1]
	fromID := cmd.GetArgs()[2]
	uuid := cmd.GetArgs()[3]
	_, err = common.GetSessionFromCID(self.msgServer.sessionCache, send2ID)
	if err != nil {
		log.Warningf("no ID : %s", send2ID)

		return err
	}

	resp := protocol.NewCmdSimple(protocol.RESP_MESSAGE_P2P_CMD)
	resp.AddArg(send2Msg)
	resp.AddArg(fromID)
	// add uuid
	resp.AddArg(uuid)

	if self.msgServer.sessions[send2ID] != nil {
		self.msgServer.sessions[send2ID].Send(libnet.Json(resp))
		if err != nil {
			log.Fatalln(err.Error())
		}
	}

	return nil
}
開發者ID:ZhangTingkuo,項目名稱:FishChatServer,代碼行數:29,代碼來源:proto_proc.go

示例6: GetOfflineMsgFromOwnerName

func GetOfflineMsgFromOwnerName(storeOp interface{}, ownerName string) (*redis_store.OfflineMsgCacheData, error) {
	switch storeOp.(type) {
	case *redis_store.OfflineMsgCache:
		o, err := storeOp.(*redis_store.OfflineMsgCache).Get(ownerName)

		if err != nil {
			log.Warningf("no ownerName : %s", ownerName)
			return nil, err
		}
		if o != nil {
			log.Info(o)
		}

		return o, nil
	}

	return nil, NOTFOUNT

	//	o ,err := offlineMsgCache.Get(ownerName)

	//	if err != nil {
	//		log.Warningf("no ownerName : %s", ownerName)
	//		return nil, err
	//	}
	//	if o != nil {
	//		log.Info(o)
	//	}

	//	return o, nil
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:30,代碼來源:util.go

示例7: GetTopicFromTopicName

func GetTopicFromTopicName(storeOp interface{}, topicName string) (*redis_store.TopicCacheData, error) {
	switch storeOp.(type) {
	case *redis_store.TopicCache:
		topic, err := storeOp.(*redis_store.TopicCache).Get(topicName)

		if err != nil {
			log.Warningf("no topicName : %s", topicName)
			return nil, err
		}
		if topic != nil {
			log.Info(topic)
		}

		return topic, nil
	}

	return nil, NOTFOUNT

	//	topic ,err := topicCache.Get(topicName)

	//	if err != nil {
	//		log.Warningf("no topicName : %s", topicName)
	//		return nil, err
	//	}
	//	if topic != nil {
	//		log.Info(topic)
	//	}

	//	return topic, nil
}
開發者ID:ZhangTingkuo,項目名稱:FishChatServer,代碼行數:30,代碼來源:util.go

示例8: GetSessionFromCID

func GetSessionFromCID(storeOp interface{}, ID string) (*redis_store.SessionCacheData, error) {
	switch storeOp.(type) {
	case *redis_store.SessionCache:
		session, err := storeOp.(*redis_store.SessionCache).Get(ID)

		if err != nil {
			log.Warningf("no ID : %s", ID)
			return nil, err
		}
		if session != nil {
			log.Info(session)
		}

		return session, nil

	}

	return nil, NOTFOUNT

	//	session ,err := sessionCache.Get(ID)

	//	if err != nil {
	//		log.Warningf("no ID : %s", ID)
	//		return nil, err
	//	}
	//	if session != nil {
	//		log.Info(session)
	//	}

	//	return session, nil
}
開發者ID:ZhangTingkuo,項目名稱:FishChatServer,代碼行數:31,代碼來源:util.go

示例9: procGetTopicList

func (self *ProtoProc) procGetTopicList(cmd protocol.Cmd, session *libnet.Session) error {
	log.Info("procGetTopicList")
	var err error

	resp := protocol.NewCmdSimple(protocol.RSP_GET_TOPIC_LIST_CMD)

	clientID := session.State.(*base.SessionState).ClientID
	//clientType := session.State.(*base.SessionState).ClientType

	sessionCacheData, err := self.msgServer.sessionCache.Get(clientID)
	if sessionCacheData == nil {
		log.Warningf("Client %s not online", clientID)
		err = common.NOT_ONLINE
		goto ErrOut
	}
ErrOut:
	if err != nil {
		resp.AddArg(err.Error())
	} else {
		resp.AddArg(protocol.RSP_SUCCESS)
		resp.AddArg(strconv.Itoa(len(sessionCacheData.TopicList)))
		for _, topic := range sessionCacheData.TopicList {
			resp.AddArg(topic)
		}
	}
	err = session.Send(libnet.Json(resp))
	if err != nil {
		log.Error(err.Error())
	}

	return err
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:32,代碼來源:proto_proc.go

示例10: procGetTopicProfile

func (self *ProtoProc) procGetTopicProfile(cmd protocol.Cmd, session *libnet.Session) error {
	log.Info("procGetTopicProfile")
	var err error
	var topicCacheData *redis_store.TopicCacheData

	topicName := "<N/A>"
	resp := protocol.NewCmdSimple(protocol.RSP_GET_TOPIC_PROFILE_CMD)
	if len(cmd.GetArgs()) != 1 {
		err = common.SYNTAX_ERROR
	} else {
		topicName = cmd.GetArgs()[0]

		clientID := session.State.(*base.SessionState).ClientID
		//clientType := session.State.(*base.SessionState).ClientType

		// check whether the topic exist
		topicCacheData, err = self.msgServer.topicCache.Get(topicName)
		if topicCacheData == nil {
			log.Warningf("TOPIC %s not exist", topicName)
			err = common.TOPIC_NOT_EXIST
		} else if topicCacheData.MemberExist(clientID) == false {
			log.Warningf("%s not the member of topic %d", clientID, topicName)
			err = common.DENY_ACCESS
		}

	}

	if err != nil {
		resp.AddArg(err.Error())
		resp.AddArg(topicName)
	} else {
		resp.AddArg(protocol.RSP_SUCCESS)
		resp.AddArg(topicName)
		resp.AddArg(topicCacheData.CreaterID)
		for _, member := range topicCacheData.MemberList {
			resp.AddArg(member.ID)
			resp.AddArg(member.Name)
			resp.AddArg(member.Type)
		}
	}
	err = session.Send(libnet.Json(resp))
	if err != nil {
		log.Error(err.Error())
	}

	return err
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:47,代碼來源:proto_proc.go

示例11: procSendMsgP2P

/*
   MsgServer -> Router
       REQ_SEND_P2P_MSG_CMD
       arg0: Sent2ID       //接收方用戶ID
       arg1: Msg           //消息內容
       arg2: FromID        //發送方用戶ID
       arg3: uuid          //MsgServer分配的消息uuid
*/
func (self *ProtoProc) procSendMsgP2P(cmd protocol.Cmd, session *libnet.Session) error {
	log.Info("procSendMsgP2P")
	var err error
	send2ID := cmd.GetArgs()[0]
	send2Msg := cmd.GetArgs()[1]
	log.Info(send2Msg)

	self.Router.readMutex.Lock()
	defer self.Router.readMutex.Unlock()
	cacheSession, err := self.Router.sessionCache.Get(send2ID)
	if cacheSession == nil || cacheSession.Alive == false {
		storeSession, err := self.Router.mongoStore.GetSessionFromCid(send2ID)
		if err != nil {
			log.Warningf("ID %s not registered, msg dropped", send2ID)
			return err
		}
		log.Info(storeSession)
		log.Warningf("ID registered but offline: %s", send2ID)

		cmd.ChangeCmdName(protocol.ROUTE_SEND_P2P_MSG_CMD)
		//ms := self.Router.cfg.MsgServerList[0]
		ms := session.Conn().RemoteAddr().String()
		err = self.Router.msgServerClientMap[ms].Send(libnet.Json(cmd))
		if err != nil {
			log.Error("error:", err)
			return err
		}
	} else {
		log.Info(cacheSession.MsgServerAddr)

		cmd.ChangeCmdName(protocol.ROUTE_SEND_P2P_MSG_CMD)
		log.Info(cmd)
		err = self.Router.msgServerClientMap[cacheSession.MsgServerAddr].Send(libnet.Json(cmd))
		if err != nil {
			log.Error("error:", err)
			return err
		}
	}

	return nil
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:49,代碼來源:proto_proc.go

示例12: procSendMsgTopic

/*
   Router -> MsgServer
       ROUTE_SEND_TOPIC_MSG_CMD
       arg0: ClientID      //發送方用戶ID
       arg1: ClientType    //發送方終端類型,是client還是device
       arg2: Msg           //消息內容
       arg3: TopicName     //群組名, device無須提供
*/
func (self *ProtoProc) procSendMsgTopic(cmd protocol.Cmd, session *libnet.Session) error {
	log.Info("procSendMsgTopic")
	var err error
	ms := session.Conn().RemoteAddr().String()

	//send2Msg := cmd.GetArgs()[0]
	topicName := cmd.GetArgs()[1]
	//fromID := cmd.GetArgs()[2]
	//fromType := cmd.GetArgs()[3]

	// check whether the topic exist
	topicCacheData, err := self.Router.topicCache.Get(topicName)
	if topicCacheData == nil {
		log.Warningf("TOPIC %s not exist: %s", topicName, err.Error())
		return err
	}

	cmd.ChangeCmdName(protocol.ROUTE_SEND_TOPIC_MSG_CMD)
	log.Info(protocol.ROUTE_SEND_TOPIC_MSG_CMD)
	log.Info(cmd)

	for ip, num := range topicCacheData.AliveMemberNumMap {
		if num > 0 {
			log.Warningf("topic %s has %d member(s) in ip %s", topicName, num, ip)
			if ip != ms {
				// not in this server, routing it
				err = self.Router.msgServerClientMap[ip].Send(libnet.Json(cmd))
				if err != nil {
					log.Error("error:", err)
					return err
				}
			}
		}
	}

	return nil
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:45,代碼來源:proto_proc.go

示例13: DelSessionFromCID

func DelSessionFromCID(storeOp interface{}, ID string) error {
	switch storeOp.(type) {
	case *redis_store.SessionCache:
		err := storeOp.(*redis_store.SessionCache).Delete(ID)

		if err != nil {
			log.Warningf("no ID : %s", ID)
			return err
		}
	}

	//	err := sessionCache.Delete(ID)

	//	if err != nil {
	//		log.Warningf("no ID : %s", ID)
	//		return err
	//	}

	return NOTFOUNT
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:20,代碼來源:util.go

示例14: procSendMsgP2P

func (self *ProtoProc) procSendMsgP2P(cmd protocol.Cmd, session *libnet.Session) error {
	log.Info("procSendMsgP2P")
	var err error
	send2ID := cmd.GetArgs()[0]
	send2Msg := cmd.GetArgs()[1]
	log.Info(send2Msg)
	self.Router.readMutex.Lock()
	defer self.Router.readMutex.Unlock()
	cacheSession, err := common.GetSessionFromCID(self.Router.sessionCache, send2ID)
	if err != nil {
		log.Warningf("no ID in cache : %s", send2ID)
		storeSession, err := self.Router.mongoStore.GetSessionFromCid(mongo_store.DATA_BASE_NAME,
			mongo_store.TOPIC_INFO_COLLECTION, send2ID)
		if err != nil {
			return err
		}
		log.Info(storeSession.MsgServerAddr)

		cmd.ChangeCmdName(protocol.ROUTE_MESSAGE_P2P_CMD)

		err = self.Router.msgServerClientMap[storeSession.MsgServerAddr].Send(libnet.Json(cmd))
		if err != nil {
			log.Error("error:", err)
			return err
		}
	} else {
		log.Info(cacheSession.MsgServerAddr)

		cmd.ChangeCmdName(protocol.ROUTE_MESSAGE_P2P_CMD)

		err = self.Router.msgServerClientMap[cacheSession.MsgServerAddr].Send(libnet.Json(cmd))
		if err != nil {
			log.Error("error:", err)
			return err
		}
	}

	return nil
}
開發者ID:ZhangTingkuo,項目名稱:FishChatServer,代碼行數:39,代碼來源:proto_proc.go

示例15: procJoinTopic

func (self *MsgServer) procJoinTopic(member *mongo_store.Member, topicName string) error {
	log.Info("procJoinTopic")
	var err error

	// check whether the topic exist
	topicCacheData, err := self.topicCache.Get(topicName)
	if topicCacheData == nil {
		log.Warningf("TOPIC %s not exist", topicName)
		return common.TOPIC_NOT_EXIST
	}

	if topicCacheData.MemberExist(member.ID) {
		log.Warningf("ClientID %s exists in topic %s", member.ID, topicName)
		return common.MEMBER_EXIST
	}

	sessionCacheData, err := self.sessionCache.Get(member.ID)
	if sessionCacheData == nil {
		log.Warningf("Client %s not online", member.ID)
		return common.NOT_ONLINE
	}
	// Watch can only be added in ONE topic
	//fmt.Println("len of topic list of %s: %d", member.ID, len(sessionCacheData.TopicList))
	if member.Type == protocol.DEV_TYPE_WATCH && len(sessionCacheData.TopicList) >= 1 {
		log.Warningf("Watch %s is in topic %s", member.ID, sessionCacheData.TopicList[0])
		return common.DENY_ACCESS
	}

	// session cache and store
	sessionCacheData.AddTopic(topicName)
	err = self.sessionCache.Set(sessionCacheData)
	if err != nil {
		log.Error(err.Error())
		return err
	}
	err = self.mongoStore.Set(sessionCacheData.SessionStoreData)
	if err != nil {
		log.Error(err.Error())
		return err
	}

	// topic cache and store
	topicCacheData.AddMember(member)
	// update AliveMemberNumMap[server]
	if sessionCacheData.Alive {
		if v, ok := topicCacheData.AliveMemberNumMap[sessionCacheData.MsgServerAddr]; ok {
			topicCacheData.AliveMemberNumMap[sessionCacheData.MsgServerAddr] = v + 1
		} else {
			topicCacheData.AliveMemberNumMap[sessionCacheData.MsgServerAddr] = 1
		}
	}

	err = self.topicCache.Set(topicCacheData)
	if err != nil {
		log.Error(err.Error())
		return err
	}
	err = self.mongoStore.Set(topicCacheData.TopicStoreData)
	if err != nil {
		log.Error(err.Error())
		return err
	}
	return nil
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:64,代碼來源:server.go


注:本文中的github.com/oikomi/FishChatServer/log.Warningf函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。