本文整理匯總了Golang中github.com/ngmoco/timber.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MsgHistChannel
//MsgHistChannel get message history of a channel
//It will fetch message history from the latest to oldest
func MsgHistChannel(em *EndptMsg, ws *websocket.Conn) {
channel, ok := em.GetDataString("channel")
if !ok {
log.Error("MsgHistChannel() null channel")
return
}
log.Debug("[MsgHistChannel] userId=" + em.UserID + ".channel = " + channel)
i := 0
for {
var res []MessageHist
query := bson.M{"userId": em.UserID, "target": channel}
err := DBQueryArr("ircboks", "msghist", query, "-timestamp", 50, 50*i, &res)
if err != nil {
log.Error("[MsgHistChannel]fetching channel history:" + err.Error())
return
}
m := map[string]interface{}{
"logs": res,
"channel": channel,
}
//send the result
websocket.Message.Send(ws, jsonMarshal("msghistChannel", m))
if len(res) == 0 || res[len(res)-1].ReadFlag == true {
break
}
i = i + 1
}
}
示例2: serveWeb
// serveWeb starts a webserver that can serve a page and websocket events as
// they are seen.
// It is expected to be run only once and uses the http package global request
// router. It does NOT return.
func serveWeb(port uint16, events chan *gitsync.GitChange) {
// the container for websocket clients, passed into every websocket handler
// below
var cs = clientSet{
clients: make(map[*websocket.Conn]chan gitsync.GitChange)}
// Handle any static files (JS/CSS files)
if handler, err := webcontent.NewMapHandler(webcontent.Paths); err != nil {
log.Error("Error building templates for web content: %s", err)
} else {
log.Debug("Registering / handler")
http.Handle("/", handler)
}
// Events endpoint
// Note: we wrap the handler in a closure to pass in the clientSet
http.Handle("/events", websocket.Handler(func(ws *websocket.Conn) {
handleGitChangeWebClient(&cs, ws)
}))
log.Info("Attempting to spawn webserver on %d", port)
go cs.distribute(events)
if err := http.ListenAndServe(fmt.Sprintf(":%v", port), nil); err != nil {
log.Error("Error listening on %d: %s", port, err)
}
}
示例3: UserRegister
//UserRegister handle user registration
func UserRegister(e *EndptMsg, ws *websocket.Conn) {
userID := e.UserID
password, ok := e.GetDataString("password")
if !ok {
websocket.Message.Send(ws, `{"event":"registrationResult", "data" : {"result":"failed", "reason":null password"}}`)
return
}
//check if user already exist
if isUserExist(userID) {
log.Info("[registerUser]User '" + userID + "' already registered")
websocket.Message.Send(ws, `{"event":"registrationResult", "data" : {"result":"failed", "reason":"email address already registered"}}`)
return
}
log.Info("[registerUser] registering " + userID)
hashedPass, err := authHassPassword(password)
if err != nil {
log.Error("[RegisterUser]:failed to hass password : " + err.Error())
websocket.Message.Send(ws, `{"event":"registrationResult", "data" : {"result":"failed", "reason":"internal error"}}`)
return
}
if len(hashedPass) == 0 {
log.Error("[RegisterUser]:failed to hass password : password len = 0")
websocket.Message.Send(ws, `{"event":"registrationResult", "data" : {"result":"failed", "reason":"invalid password"}}`)
return
}
log.Debug("generated password = " + hashedPass)
uri := Config.GetString("mongodb_uri")
sess, err := mgo.Dial(uri)
if err != nil {
log.Error("Can't connect to mongo, go error :" + err.Error())
websocket.Message.Send(ws, `{"event":"registrationResult", "data" : {"result":"failed", "reason":"internal DB error"}}`)
return
}
defer sess.Close()
sess.SetSafe(&mgo.Safe{})
collection := sess.DB("ircboks").C("user")
doc := AuthInfo{bson.NewObjectId(), userID, hashedPass}
err = collection.Insert(doc)
if err != nil {
log.Error("Can't insert new user:" + err.Error())
websocket.Message.Send(ws, `{"event":"registrationResult", "data" : {"result":"failed", "reason":"internal DB error"}}`)
return
}
websocket.Message.Send(ws, `{"event":"registrationResult", "data" : {"result":"ok"}}`)
}
示例4: Part
//Part or leave a channel
func (c *IRCClient) Part(em *EndptMsg) {
if len(em.Args) == 0 {
log.Error("part() invalid args len = 0")
return
}
c.client.Part(em.Args[0], "")
}
示例5: dispatchBoksHandler
//handle IRCBoks message
func dispatchBoksHandler(wsCtx *wsContext, em *EndptMsg) {
resp := "{}"
if em.Event == "login" {
resp, isLoginOK, _ := UserLogin(em, wsCtx.Ws)
wsCtx.LoggedIn = isLoginOK
websocket.Message.Send(wsCtx.Ws, resp)
return
} else if em.Event == "userRegister" {
UserRegister(em, wsCtx.Ws)
return
}
if !wsCtx.LoggedIn {
em := EndptMsg{
Event: "illegalAccess",
Data: map[string]interface{}{
"reason": "needLogin",
},
}
websocket.Message.Send(wsCtx.Ws, em.Marshal())
}
if fn, ok := boksHandlers[em.Event]; ok {
go fn(em, wsCtx.Ws)
} else {
log.Error("dispatchBoksHandler() unhandled event:" + em.Event)
}
}
示例6: processIrcMsg
//processIrcMsg will unmarshal irc command json string and dispatch it to respective handler
func (c *IRCClient) processIrcMsg(em *EndptMsg) {
//handler for IRC Command
handlers := map[string]func(*EndptMsg){
"join": c.Join,
"privmsg": c.PrivMsg,
"part": c.Part,
"names": c.Names,
"nick": c.Nick,
"topic": c.Topic,
}
if fn, ok := handlers[em.Event]; ok {
fn(em)
return
}
switch em.Event {
case "ircBoxInfo":
info := c.dumpInfo()
EndpointPublishID(em.UserID, info)
case "killMe":
c.client.Stop()
go func() {
c.stopChan <- true
}()
default:
log.Error("processIrcMessage() unknown command :" + em.Event)
}
}
示例7: DBUpdateOne
//DBUpdateOne update a doc
func DBUpdateOne(dbName, colName, oid string, updateQuery bson.M) error {
sess, err := getSession()
if err != nil {
log.Error("[DBUpdateOne]failed to connect to server :" + err.Error())
return nil
}
defer sess.Close()
sess.SetSafe(&mgo.Safe{})
err = sess.DB(dbName).C(colName).Update(bson.M{"_id": bson.ObjectIdHex(oid)}, updateQuery)
if err != nil {
log.Error("[DBUpdateOne]dbName = " + dbName + ".collection = " + colName + ".oid = " + oid + ". err = " + err.Error())
}
return err
}
示例8: Nick
//Nick change nick of this client
func (c *IRCClient) Nick(em *EndptMsg) {
if newNick, ok := em.GetDataString("new_nick"); ok {
c.client.SetNick(newNick)
} else {
log.Error("SetNick() empty nick")
}
}
示例9: msgHistNick
func msgHistNick(userID, nick string, ws *websocket.Conn) {
i := 0
query1 := bson.M{"userId": userID, "nick": nick, "to_channel": false} //message from this nick, not in channel
query2 := bson.M{"userId": userID, "target": nick} //message to this nick
query := bson.M{"$or": []bson.M{query1, query2}}
for {
var hists []MessageHist
err := DBQueryArr("ircboks", "msghist", query, "-timestamp", 50, 50*i, &hists)
if err != nil {
log.Error("[MsgHistNick]fetching channel nick:" + err.Error())
return
}
m := map[string]interface{}{
"logs": hists,
"nick": nick,
}
//send it back
websocket.Message.Send(ws, jsonMarshal("msghistNickResp", m))
if len(hists) == 0 || hists[len(hists)-1].ReadFlag == true {
break
}
i++
}
}
示例10: wsMain
//websocket main handler
func wsMain(ws *websocket.Conn) {
defer ws.Close()
wsCtx := newWSContext(ws)
var msg string
for {
//read message
err := websocket.Message.Receive(ws, &msg)
if err != nil {
break
}
log.Debug("[wsMain]endpoint's msg = " + msg)
//parse message
wsMsg, err := NewEndptMsgFromStr(msg)
if err != nil {
log.Error("[wsMain]failed to unmarshal json :" + err.Error())
continue
}
wsCtx.UserID = wsMsg.UserID
if wsMsg.Domain == "irc" && wsCtx.LoggedIn {
ClientDoIRCCmd(wsMsg, ws)
} else {
dispatchBoksHandler(wsCtx, wsMsg)
}
}
if wsCtx.LoggedIn {
UserLogout(wsCtx.UserID, ws)
}
log.Debug("[wsMain]endpoint exited")
}
示例11: UserLogout
//UserLogout will log out the user
func UserLogout(userID string, ws *websocket.Conn) {
ctx, found := ContextMap.Get(userID)
if !found {
log.Error("[UserLogout]can't find = " + userID)
return
}
ctx.DelWs(ws)
}
示例12: ClientDoIRCCmd
//ClientDoIRCCmd receive IRC command and run it
func ClientDoIRCCmd(em *EndptMsg, ws *websocket.Conn) {
ctx, found := ContextMap.Get(em.UserID)
if !found {
log.Error("Can't find client ctx for userId = " + em.UserID)
return
}
ctx.InChan <- em
}
示例13: MsgHistNick
//MsgHistNick get message history of a nick
func MsgHistNick(em *EndptMsg, ws *websocket.Conn) {
nick, ok := em.GetDataString("nick")
if !ok {
log.Error("MsgHistNick() empty nick")
return
}
msgHistNick(em.UserID, nick, ws)
}
示例14: DBSelectDistinct
//DBSelectDistinct do similar operation like 'select ... distinct ...' on SQL
func DBSelectDistinct(dbName, colName string, query bson.M, distinctBy string, res interface{}) error {
sess, err := getSession()
if err != nil {
log.Error("[DBSelectDistinct]Error getSession:", err.Error())
return err
}
defer sess.Close()
return sess.DB(dbName).C(colName).Find(query).Distinct(distinctBy, res)
}
示例15: processJoined
//process JOIN event
func (c *IRCClient) processJoined(e *ogric.Event) {
if len(e.Arguments) == 0 {
log.Error("processJoined() invalid event args len = 0")
} else {
log.Debug("process join nick=" + e.Nick)
channelName := e.Arguments[0]
c.chanJoinedSet[channelName] = true
}
c.forwardEvent(e)
}