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


Golang log.Error函數代碼示例

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


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

示例1: main

func main() {
	version()
	fmt.Printf("built on %s\n", BuildTime())
	flag.Parse()
	cfg := NewMonitorConfig(*InputConfFile)
	err := cfg.LoadConfig()
	if err != nil {
		log.Error(err.Error())
		return
	}

	server, err := libnet.Listen(cfg.TransportProtocols, cfg.Listen)
	if err != nil {
		log.Error(err.Error())
		return
	}
	log.Info("server start: ", server.Listener().Addr().String())

	m := NewMonitor(cfg)
	//TODO not use go
	m.subscribeChannels()
	go server.Serve(func(session *libnet.Session) {

	})

	beego.Router("api/v1/monitor", &controllers.MonitorController{})
	//beego.SetStaticPath("/views", "/mh/mygo/src/github.com/oikomi/FishChatServer/monitor/views")
	beego.SetStaticPath("/views", "views")
	beego.Run()
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:30,代碼來源:monitor.go

示例2: main

func main() {
	version()
	fmt.Printf("built on %s\n", BuildTime())
	flag.Parse()
	cfg := NewGatewayConfig(*InputConfFile)
	err := cfg.LoadConfig()
	if err != nil {
		log.Error(err.Error())
		return
	}

	gw := NewGateway(cfg)

	gw.server, err = libnet.Listen(cfg.TransportProtocols, cfg.Listen)
	if err != nil {
		log.Error(err.Error())
		return
	}
	log.Info("gateway server running at ", gw.server.Listener().Addr().String())

	gw.server.Serve(func(session *libnet.Session) {
		log.Info("client ", session.Conn().RemoteAddr().String(), " | come in")

		go handleSession(gw, session)
	})
}
開發者ID:ZhangTingkuo,項目名稱:FishChatServer,代碼行數:26,代碼來源:gateway.go

示例3: procOnline

func (self *MsgServer) procOnline(ID string) {
	// load all the topic list of this user
	sessionCacheData, err := self.sessionCache.Get(ID)
	if err != nil {
		log.Errorf("ID(%s) no session cache", ID)
		return
	}
	sessionCacheData.Alive = true
	self.sessionCache.Set(sessionCacheData)
	for _, topicName := range sessionCacheData.TopicList {
		topicCacheData, err := self.topicCache.Get(topicName)
		if err != nil {
			log.Error(err.Error())
			return
		}
		if topicCacheData == nil {
			topicStoreData, err := self.mongoStore.GetTopicFromCid(topicName)
			if err != nil {
				log.Error(err.Error())
				return
			}
			topicCacheData = redis_store.NewTopicCacheData(topicStoreData)
		}
		// update AliveMemberNumMap[server]
		if v, ok := topicCacheData.AliveMemberNumMap[self.cfg.LocalIP]; ok {
			topicCacheData.AliveMemberNumMap[self.cfg.LocalIP] = v + 1
		} else {
			topicCacheData.AliveMemberNumMap[self.cfg.LocalIP] = 1
		}
		self.topicCache.Set(topicCacheData)
	}
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:32,代碼來源:server.go

示例4: Update

func (self *MongoStore) Update(db string, c string, data interface{}) error {
	log.Info("MongoStore Update")
	var err error
	self.rwMutex.Lock()
	defer self.rwMutex.Unlock()

	op := self.session.DB(db).C(c)

	switch data.(type) {
	case *SessionStoreData:
		cid := data.(*SessionStoreData).ClientID
		log.Info("cid : ", cid)
		_, err = op.Upsert(bson.M{"ClientID": cid}, data.(*SessionStoreData))
		if err != nil {
			log.Error(err.Error())
			return err
		}

	case *TopicStoreData:
		topicName := data.(*TopicStoreData).TopicName
		log.Info("topicName : ", topicName)
		_, err = op.Upsert(bson.M{"TopicName": topicName}, data.(*TopicStoreData))
		if err != nil {
			log.Error(err.Error())
			return err
		}
	}

	return err
}
開發者ID:ZhangTingkuo,項目名稱:FishChatServer,代碼行數:30,代碼來源:mongo_store.go

示例5: main

func main() {
	version()
	fmt.Printf("built on %s\n", BuildTime())
	flag.Parse()
	cfg := NewRouterConfig(*InputConfFile)
	err := cfg.LoadConfig()
	if err != nil {
		log.Error(err.Error())
		return
	}

	server, err := libnet.Listen(cfg.TransportProtocols, cfg.Listen)
	if err != nil {
		log.Error(err.Error())
		return
	}
	log.Info("server start: ", server.Listener().Addr().String())

	r := NewRouter(cfg)
	//TODO not use go
	go r.subscribeChannels()
	server.Serve(func(session *libnet.Session) {

	})
}
開發者ID:ZhangTingkuo,項目名稱:FishChatServer,代碼行數:25,代碼來源:router.go

示例6: subscribeChannels

func (self *Monitor) subscribeChannels() error {
	log.Info("monitor start to subscribeChannels")
	for _, ms := range self.cfg.MsgServerList {
		msgServerClient, err := self.connectMsgServer(ms)
		if err != nil {
			log.Error(err.Error())
			return err
		}
		cmd := protocol.NewCmdSimple(protocol.SUBSCRIBE_CHANNEL_CMD)
		cmd.AddArg(protocol.SYSCTRL_MONITOR)
		cmd.AddArg(self.cfg.UUID)

		err = msgServerClient.Send(libnet.Json(cmd))
		if err != nil {
			log.Error(err.Error())
			return err
		}

		self.msgServerClientMap[ms] = msgServerClient
	}

	for _, msc := range self.msgServerClientMap {
		go self.handleMsgServerClient(msc)
	}
	return nil
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:26,代碼來源:server.go

示例7: main

func main() {
	version()
	fmt.Printf("built on %s\n", BuildTime())
	flag.Parse()
	cfg := NewRouterConfig(*InputConfFile)
	err := cfg.LoadConfig()
	if err != nil {
		log.Error(err.Error())
		return
	}

	server, err := libnet.Listen(cfg.TransportProtocols, cfg.Listen)
	if err != nil {
		log.Error(err.Error())
		return
	}
	log.Info("server start: ", server.Listener().Addr().String())

	rs := redis_store.NewRedisStore(&redis_store.RedisStoreOptions{
		Network:        "tcp",
		Address:        cfg.Redis.Addr + cfg.Redis.Port,
		ConnectTimeout: time.Duration(cfg.Redis.ConnectTimeout) * time.Millisecond,
		ReadTimeout:    time.Duration(cfg.Redis.ReadTimeout) * time.Millisecond,
		WriteTimeout:   time.Duration(cfg.Redis.WriteTimeout) * time.Millisecond,
		Database:       1,
		KeyPrefix:      base.COMM_PREFIX,
	})
	r := NewRouter(cfg, rs)
	//TODO not use go
	go r.subscribeChannels()
	server.Serve(func(session *libnet.Session) {

	})
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:34,代碼來源:router.go

示例8: Set

func (self *MongoStore) Set(data interface{}) error {
	log.Info("MongoStore Update")
	var err error
	self.rwMutex.Lock()
	defer self.rwMutex.Unlock()

	switch data.(type) {
	case *SessionStoreData:
		op := self.session.DB(DATA_BASE_NAME).C(CLIENT_INFO_COLLECTION)
		cid := data.(*SessionStoreData).ClientID
		log.Info("cid : ", cid)
		_, err = op.Upsert(bson.M{"ClientID": cid}, data.(*SessionStoreData))
		if err != nil {
			log.Error(err.Error())
			return err
		}

	case *TopicStoreData:
		op := self.session.DB(DATA_BASE_NAME).C(TOPIC_INFO_COLLECTION)
		topicName := data.(*TopicStoreData).TopicName
		log.Info("topicName : ", topicName)
		_, err = op.Upsert(bson.M{"TopicName": topicName}, data.(*TopicStoreData))
		if err != nil {
			log.Error(err.Error())
			return err
		}
	}

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

示例9: procOfflineMsg

func (self *ProtoProc) procOfflineMsg(session *libnet.Session, ID string) error {
	var err error
	exist, err := self.msgServer.offlineMsgCache.IsKeyExist(ID)
	if exist.(int64) == 0 {
		return err
	} else {
		omrd, err := common.GetOfflineMsgFromOwnerName(self.msgServer.offlineMsgCache, ID)
		if err != nil {
			log.Error(err.Error())
			return err
		}
		for _, v := range omrd.MsgList {
			resp := protocol.NewCmdSimple(protocol.RESP_MESSAGE_P2P_CMD)
			resp.AddArg(v.Msg)
			resp.AddArg(v.FromID)
			resp.AddArg(v.Uuid)

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

		omrd.ClearMsg()
		self.msgServer.offlineMsgCache.Set(omrd)
	}

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

示例10: procCreateTopic

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

	if len(cmd.GetArgs()) != 1 {
		return CMD_NOT_CORRECT
	}
	topicName := cmd.GetArgs()[0]

	topicCacheData := redis_store.NewTopicCacheData(topicName, session.State.(*base.SessionState).ClientID,
		self.msgServer.cfg.LocalIP)

	t := protocol.NewTopic(topicName, self.msgServer.cfg.LocalIP, session.State.(*base.SessionState).ClientID, session)
	t.ClientIDList = append(t.ClientIDList, session.State.(*base.SessionState).ClientID)
	t.TSD = topicCacheData
	self.msgServer.topics[topicName] = t
	self.msgServer.topics[topicName].Channel = libnet.NewChannel(self.msgServer.server.Protocol())

	self.msgServer.topics[topicName].Channel.Join(session, nil)

	log.Info(topicCacheData)
	args := make([]string, 0)
	args = append(args, topicName)
	CCmd := protocol.NewCmdInternal(protocol.CACHE_TOPIC_CMD, args, topicCacheData)
	m := redis_store.NewMember(session.State.(*base.SessionState).ClientID)
	CCmd.AnyData.(*redis_store.TopicCacheData).MemberList = append(CCmd.AnyData.(*redis_store.TopicCacheData).MemberList, m)

	log.Info(CCmd)

	if self.msgServer.channels[protocol.SYSCTRL_TOPIC_STATUS] != nil {
		_, err = self.msgServer.channels[protocol.SYSCTRL_TOPIC_STATUS].Channel.Broadcast(libnet.Json(CCmd))
		if err != nil {
			log.Error(err.Error())
			return err
		}
	}

	// store topic
	topicStoreData := mongo_store.NewTopicStoreData(topicName, session.State.(*base.SessionState).ClientID,
		self.msgServer.cfg.LocalIP)

	args = make([]string, 0)
	args = append(args, topicName)
	CCmd = protocol.NewCmdInternal(protocol.STORE_TOPIC_CMD, args, topicStoreData)
	member := mongo_store.NewMember(session.State.(*base.SessionState).ClientID)
	CCmd.AnyData.(*mongo_store.TopicStoreData).MemberList = append(CCmd.AnyData.(*mongo_store.TopicStoreData).MemberList, member)

	log.Info(CCmd)

	if self.msgServer.channels[protocol.STORE_TOPIC_INFO] != nil {
		_, err = self.msgServer.channels[protocol.STORE_TOPIC_INFO].Channel.Broadcast(libnet.Json(CCmd))
		if err != nil {
			log.Error(err.Error())
			return err
		}
	}

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

示例11: subscribeChannels

func (self *Manager) subscribeChannels() error {
	log.Info("subscribeChannels")
	var msgServerClientList []*libnet.Session
	for _, ms := range self.cfg.MsgServerList {
		msgServerClient, err := self.connectMsgServer(ms)
		if err != nil {
			log.Error(err.Error())
			return err
		}
		cmd := protocol.NewCmdSimple(protocol.SUBSCRIBE_CHANNEL_CMD)
		cmd.AddArg(protocol.SYSCTRL_CLIENT_STATUS)
		cmd.AddArg(self.cfg.UUID)

		err = msgServerClient.Send(libnet.Json(cmd))
		if err != nil {
			log.Error(err.Error())
			return err
		}

		cmd = protocol.NewCmdSimple(protocol.SUBSCRIBE_CHANNEL_CMD)
		cmd.AddArg(protocol.SYSCTRL_TOPIC_STATUS)
		cmd.AddArg(self.cfg.UUID)

		err = msgServerClient.Send(libnet.Json(cmd))
		if err != nil {
			log.Error(err.Error())
			return err
		}

		cmd = protocol.NewCmdSimple(protocol.SUBSCRIBE_CHANNEL_CMD)
		cmd.AddArg(protocol.STORE_CLIENT_INFO)
		cmd.AddArg(self.cfg.UUID)

		err = msgServerClient.Send(libnet.Json(cmd))
		if err != nil {
			log.Error(err.Error())
			return err
		}

		cmd = protocol.NewCmdSimple(protocol.SUBSCRIBE_CHANNEL_CMD)
		cmd.AddArg(protocol.STORE_TOPIC_INFO)
		cmd.AddArg(self.cfg.UUID)

		err = msgServerClient.Send(libnet.Json(cmd))
		if err != nil {
			log.Error(err.Error())
			return err
		}

		msgServerClientList = append(msgServerClientList, msgServerClient)
	}

	for _, msc := range msgServerClientList {
		go self.handleMsgServerClient(msc)
	}
	return nil
}
開發者ID:ZhangTingkuo,項目名稱:FishChatServer,代碼行數:57,代碼來源:server.go

示例12: procClientID

func (self *ProtoProc) procClientID(cmd protocol.Cmd, session *libnet.Session) error {
	log.Info("procClientID")
	var err error
	ID := cmd.GetArgs()[0]
	// for cache data
	sessionCacheData := redis_store.NewSessionCacheData(cmd.GetArgs()[0], session.Conn().RemoteAddr().String(),
		self.msgServer.cfg.LocalIP, strconv.FormatUint(session.Id(), 10))

	log.Info(sessionCacheData)
	args := make([]string, 0)
	args = append(args, cmd.GetArgs()[0])
	CCmd := protocol.NewCmdInternal(protocol.CACHE_SESSION_CMD, args, sessionCacheData)

	log.Info(CCmd)

	if self.msgServer.channels[protocol.SYSCTRL_CLIENT_STATUS] != nil {
		_, err = self.msgServer.channels[protocol.SYSCTRL_CLIENT_STATUS].Channel.Broadcast(libnet.Json(CCmd))
		if err != nil {
			log.Error(err.Error())
			return err
		}
	}

	// for store data
	sessionStoreData := mongo_store.SessionStoreData{ID, session.Conn().RemoteAddr().String(),
		self.msgServer.cfg.LocalIP, true}

	log.Info(sessionStoreData)
	args = make([]string, 0)
	args = append(args, cmd.GetArgs()[0])
	CCmd = protocol.NewCmdInternal(protocol.STORE_SESSION_CMD, args, sessionStoreData)

	log.Info(CCmd)

	if self.msgServer.channels[protocol.STORE_CLIENT_INFO] != nil {
		_, err = self.msgServer.channels[protocol.STORE_CLIENT_INFO].Channel.Broadcast(libnet.Json(CCmd))
		if err != nil {
			log.Error(err.Error())
			return err
		}
	}

	self.msgServer.sessions[cmd.GetArgs()[0]] = session
	self.msgServer.sessions[cmd.GetArgs()[0]].State = base.NewSessionState(true, cmd.GetArgs()[0])

	err = self.procOfflineMsg(session, ID)
	if err != nil {
		log.Error(err.Error())
		return err
	}
	return nil
}
開發者ID:ZhangTingkuo,項目名稱:FishChatServer,代碼行數:52,代碼來源:proto_proc.go

示例13: 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

示例14: cmd_topic_rsp

func cmd_topic_rsp(self *Client, c *protocol.CmdSimple) error {
	var num int
	var err error

	fmt.Println(c.GetCmdName() + " returns: " + c.GetArgs()[0])
	if c.GetArgs()[0] != protocol.RSP_SUCCESS {
		return errors.New(c.GetArgs()[0])
	}
	if num, err = strconv.Atoi(c.GetArgs()[1]); err != nil {
		fmt.Println(err.Error())
		log.Error(err.Error())
		return err
	}
	fmt.Println("GET_TOPIC_LIST returns (" + c.GetArgs()[1] + "): ")
	index := 0
	for {
		if index == num {
			break
		} else {
			fmt.Println(c.GetArgs()[2+index])
			index++
		}
	}

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

示例15: procQuitTopic

/*
   client -> MsgServer
       REQ_QUIT_TOPIC_CMD
       arg0: TopicName     //群組名

   MsgServer -> client
       RSP_QUIT_TOPIC_CMD
       arg0: SUCCESS/ERROR
*/
func (self *ProtoProc) procQuitTopic(cmd protocol.Cmd, session *libnet.Session) error {
	log.Info("procQuitTopic")
	var err error

	if len(cmd.GetArgs()) != 1 {
		err = common.SYNTAX_ERROR
	} else {
		topicName := cmd.GetArgs()[0]

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

		err = self.msgServer.procQuitTopic(clientID, topicName)
	}

	resp := protocol.NewCmdSimple(protocol.RSP_QUIT_TOPIC_CMD)

	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,代碼行數:37,代碼來源:proto_proc.go


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