本文整理汇总了Golang中github.com/tsuru/tsuru/api/context.GetDelayedHandler函数的典型用法代码示例。如果您正苦于以下问题:Golang GetDelayedHandler函数的具体用法?Golang GetDelayedHandler怎么用?Golang GetDelayedHandler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetDelayedHandler函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runDelayedHandler
func runDelayedHandler(w http.ResponseWriter, r *http.Request) {
h := context.GetDelayedHandler(r)
if h != nil {
h.ServeHTTP(w, r)
}
}
示例2: ServeHTTP
func (m *appLockMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
if r.Method == "GET" {
next(w, r)
return
}
currentHandler := context.GetDelayedHandler(r)
if currentHandler != nil {
currentHandlerPtr := reflect.ValueOf(currentHandler).Pointer()
for _, h := range m.excludedHandlers {
if reflect.ValueOf(h).Pointer() == currentHandlerPtr {
next(w, r)
return
}
}
}
appName := r.URL.Query().Get(":app")
if appName == "" {
appName = r.URL.Query().Get(":appname")
}
if appName == "" {
next(w, r)
return
}
t := context.GetAuthToken(r)
var owner string
if t != nil {
if t.IsAppToken() {
owner = t.GetAppName()
} else {
owner = t.GetUserName()
}
}
_, err := app.GetByName(appName)
if err == app.ErrAppNotFound {
context.AddRequestError(r, &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()})
return
}
ok, err := app.AcquireApplicationLockWait(appName, owner, fmt.Sprintf("%s %s", r.Method, r.URL.Path), lockWaitDuration)
if err != nil {
context.AddRequestError(r, fmt.Errorf("Error trying to acquire application lock: %s", err))
return
}
if ok {
defer func() {
if !context.IsPreventUnlock(r) {
app.ReleaseApplicationLock(appName)
}
}()
next(w, r)
return
}
a, err := app.GetByName(appName)
httpErr := &errors.HTTP{Code: http.StatusInternalServerError}
if err != nil {
if err == app.ErrAppNotFound {
httpErr.Code = http.StatusNotFound
httpErr.Message = err.Error()
} else {
httpErr.Message = fmt.Sprintf("Error to get application: %s", err)
}
} else {
httpErr.Code = http.StatusConflict
if a.Lock.Locked {
httpErr.Message = fmt.Sprintf("%s", &a.Lock)
} else {
httpErr.Message = "Not locked anymore, please try again."
}
}
context.AddRequestError(r, httpErr)
}