本文整理匯總了Golang中github.com/funny/link.Session.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.Close方法的具體用法?Golang Session.Close怎麽用?Golang Session.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/funny/link.Session
的用法示例。
在下文中一共展示了Session.Close方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Process
func Process(session *link.Session, req map[string]string) error {
command, ok := req["action"]
if !ok {
ULogger.Error("client", session.Conn().RemoteAddr().String(), "bad request ,not found action")
session.Close()
return nil
}
if (command == "getfile" || command == "answer") && session.State == nil {
ULogger.Error("client", session.Conn().RemoteAddr().String(), "c must login frist")
session.Close()
return nil
}
switch command {
//p
case "putfile":
return putFile(session, req)
case "reportanswer":
return reportAnswer(session, req)
//c
case "getfile":
return getFile(session, req)
case "cstart":
return cStart(session, req)
case "answer":
return answer(session, req)
default:
ULogger.Error("client", session.Conn().RemoteAddr().String(), "not support command")
session.Close()
//ULogger.Info("sssss")
}
return nil
}
示例2: cStart
///c端開始答題
func cStart(session *link.Session, req map[string]string) error {
userid := req["userid"]
password := req["password"]
seq := req["seq"]
ULogger.Infof("user %s start answer", userid)
ret := map[string]string{
"action": "res_cstart",
"seq": seq,
"result": "0",
}
if session.State != nil && session.State.(*User).UserType == "C" {
ULogger.Error("have logined ", userid)
session.Close()
}
if b := Login(userid, password); !b {
ULogger.Errorf("cstart failed ,userid is %s password is %s", userid, password)
by, _ := json.Marshal(ret)
session.Send(link.Bytes(by))
ULogger.Info("send to client", session.Conn().RemoteAddr().String(), "say:", string(by))
session.Close()
return nil
} else {
user := &User{UserType: "C", Id: userid, WorkTime: time.Now().Format("2006-01-02 15:04:05")}
session.State = user
ret["result"] = "1"
by, _ := json.Marshal(ret)
session.Send(link.Bytes(by))
ULogger.Info("send to client", session.Conn().RemoteAddr().String(), "say:", string(by))
//c端開始答題
Exec(`insert into user_activities(user_id,active_time,active_type,user_type,other_info) values(?,now(),'begin','customer',?)`, userid, session.Conn().RemoteAddr().String())
VFMapInstance.AddSession(session)
}
return nil
}