本文整理匯總了Golang中github.com/go-martini/martini.Context.Invoke方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Invoke方法的具體用法?Golang Context.Invoke怎麽用?Golang Context.Invoke使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/go-martini/martini.Context
的用法示例。
在下文中一共展示了Context.Invoke方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: validateAndMap
// Performs validation and combines errors from validation
// with errors from deserialization, then maps both the
// resulting struct and the errors to the context.
func validateAndMap(obj reflect.Value, context martini.Context, errors *base.BindingErrors, ifacePtr ...interface{}) {
context.Invoke(Validate(obj.Interface()))
errors.Combine(getErrors(context))
context.Map(*errors)
context.Map(obj.Elem().Interface())
if len(ifacePtr) > 0 {
context.MapTo(obj.Elem().Interface(), ifacePtr[0])
}
}
示例2: validateAndMap
// Performs validation and combines errors from validation
// with errors from deserialization, then maps both the
// resulting struct and the errors to the context.
func validateAndMap(obj reflect.Value, context martini.Context, errors Errors, ifacePtr ...interface{}) {
context.Invoke(Validate(obj.Interface()))
errors = append(errors, getErrors(context)...)
context.Map(errors)
context.Map(obj.Elem().Interface())
if len(ifacePtr) > 0 {
context.MapTo(obj.Elem().Interface(), ifacePtr[0])
}
}
示例3: logoutHandle
func logoutHandle(f *Config, c martini.Context, s sessions.Session, w http.ResponseWriter, r *http.Request) {
s.Delete(keyToken)
path := fmt.Sprintf("%s?client_id=%s&client_secret=%s", f.Endpoint.LogoutURL, f.ClientID, f.ClientSecret)
utils.HttpGetString(path)
// fmt.Println("oauth logout result:",string(str))
f.ClientID = ""
f.ClientSecret = ""
c.Invoke(Logout)
http.Redirect(w, r, "/", 302)
}
示例4: callNormalizeBinding
func callNormalizeBinding(val reflect.Value, context martini.Context) (interface{}, error) {
obj := val.Interface()
if m := val.MethodByName("NormalizeBinding"); m.IsValid() {
results, err := context.Invoke(m.Interface())
if err != nil {
return nil, err
}
if len(results) > 0 {
obj = results[0].Interface()
}
}
return obj, nil
}
示例5: validateAndMap
// Performs validation and combines errors from validation
// with errors from deserialization, then maps both the
// resulting struct and the errors to the context.
func validateAndMap(val reflect.Value, context martini.Context, errors *Errors, ifacePtr ...interface{}) {
context.Invoke(Validate(val.Interface()))
context.Map(errors)
target, _ := normalize(val, context)
if target == nil {
panic("binding: wrong return nil value")
}
context.Map(target)
if len(ifacePtr) > 0 {
for index, _ := range ifacePtr {
context.MapTo(target, ifacePtr[index])
}
}
}
示例6: callbackhandle
func callbackhandle(f *Config, c martini.Context, s sessions.Session, w http.ResponseWriter, r *http.Request) {
rurl, _ := s.Get("_RedirectURL").(string)
rurl = extractPath(rurl)
if len(r.URL.Query().Get("code")) > 0 {
//獲取token
tk, error := f.authTokenURL(r.URL.Query().Get("code"))
if error == nil && tk.Valid() {
val, _ := json.Marshal(tk)
s.Set(keyToken, val)
fmt.Println("登陸成功")
s.AddFlash("登陸成功")
c.Invoke(oAuthUserLoginCallback)
if len(rurl) == 0 {
rurl = "/"
}
fmt.Println("rul:", rurl)
http.Redirect(w, r, rurl, 302)
return
} else {
s.AddFlash("登陸失敗")
http.Redirect(w, r, PathError, 302)
return
}
}
if len(r.URL.Query().Get("client_id")) > 0 {
f.ClientID = r.URL.Query().Get("client_id")
f.ClientSecret = r.URL.Query().Get("client_secret")
http.Redirect(w, r, f.authCodeURL(), 302)
return
}
// fmt.Println("call:",r)
// if (len(r.URL.Query().Get("code"))>0) {
// fmt.Println("callFUN:q token")
// rurl,_:= s.Get("_RedirectURL").(string)
// //獲取token
// tk, error := f.authTokenURL(r.URL.Query().Get("code"))
// if error==nil && tk.Valid() {
// val, _ := json.Marshal(tk)
// s.Set(keyToken, val)
// s.AddFlash("success","登陸成功")
// c.Invoke(oAuthUserLogin)
//
//
// http.RedirectHandler(rurl, 302)
// return
// }else{
// s.AddFlash("warning","登陸失敗")
// http.Redirect(w, r, PathError, 302)
// return
// }
// }else{
// fmt.Println("callFUN:1111")
// //獲取code
// if len(r.URL.Query().Get("client_id"))>0 {
// fmt.Println("callFUN:q code")
// f.ClientID = r.URL.Query().Get("client_id")
// f.ClientSecret = r.URL.Query().Get("client_secret")
// http.Redirect(w, r, f.authCodeURL(), 302)
// return
// }
// http.Redirect(w, r, "/", 302)
// }
// fmt.Println("callFUN:sppp")
}