本文整理匯總了Golang中github.com/zaolab/sunnified/web.Context.RaiseAppError方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.RaiseAppError方法的具體用法?Golang Context.RaiseAppError怎麽用?Golang Context.RaiseAppError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/zaolab/sunnified/web.Context
的用法示例。
在下文中一共展示了Context.RaiseAppError方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ServeContextHTTP
func (this *WebSocketHandler) ServeContextHTTP(context *web.Context) {
var ctrlmgr *controller.ControlManager = controller.NewControlManager(context, this.ctrl, "_")
if err := context.ToWebSocket(nil, nil); err != nil {
context.RaiseAppError("Unable to upgrade to websocket: " + err.Error())
}
defer func() {
if err := recover(); err != nil {
log.Println(err)
}
}()
ctrlmgr.Prepare()
var (
ctrler = ctrlmgr.Controller()
listen = &methMeta{method: ctrler.MethodByName("Listen_")}
methods = make(map[string]*methMeta)
meth *methMeta
ok bool
t reflect.Type
)
if listen.method.IsValid() {
t = listen.method.Type()
if t.NumIn() != 2 || t.In(0) != intType || t.In(1) != retbType {
listen.method = reflect.Value{}
}
}
listen.rettype = getRetType(listen.method, t)
listen.isvalid = listen.method.IsValid()
for {
msgT, p, err := context.WebSocket.ReadMessage()
if err != nil {
if m := ctrler.MethodByName("Error_"); m.IsValid() && m.Type().NumIn() == 1 &&
m.Type().In(0) == errType {
m.Call([]reflect.Value{reflect.ValueOf(err)})
}
break
}
if this.allowcmd && msgT == websocket.TextMessage && len(p) > 0 && p[0] == '/' {
args := WSArgs(argSplit.Split(strings.TrimSpace(string(p[1:len(p)])), -1))
cmd := strings.Replace(strings.Title(args[0]), "-", "_", -1)
if cmd[len(cmd)-1] != '_' && validCmd.MatchString(cmd) {
args = args[1:len(args)]
if meth, ok = methods[cmd]; !ok {
m := ctrler.MethodByName(cmd)
if m.IsValid() {
t = m.Type()
if t.NumIn() != 1 || t.In(0) != argsType {
m = reflect.Value{}
}
meth = &methMeta{
method: m,
rettype: getRetType(m, t),
isvalid: m.IsValid(),
}
} else {
meth = &methMeta{
method: m,
rettype: 0,
isvalid: false,
}
}
methods[cmd] = meth
}
if meth.isvalid {
write(meth, context.WebSocket, meth.method.Call([]reflect.Value{reflect.ValueOf(args)}))
continue
}
}
}
if listen.isvalid {
write(listen, context.WebSocket,
listen.method.Call([]reflect.Value{reflect.ValueOf(msgT), reflect.ValueOf(p)}))
}
}
}