code.gitea.io/gitea@v1.19.3/modules/web/routing/context.go (about) 1 // Copyright 2021 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package routing 5 6 import ( 7 "context" 8 "net/http" 9 ) 10 11 type contextKeyType struct{} 12 13 var contextKey contextKeyType 14 15 // UpdateFuncInfo updates a context's func info 16 func UpdateFuncInfo(ctx context.Context, funcInfo *FuncInfo) { 17 record, ok := ctx.Value(contextKey).(*requestRecord) 18 if !ok { 19 return 20 } 21 22 record.lock.Lock() 23 record.funcInfo = funcInfo 24 record.lock.Unlock() 25 } 26 27 // MarkLongPolling marks the request is a long-polling request, and the logger may output different message for it 28 func MarkLongPolling(resp http.ResponseWriter, req *http.Request) { 29 record, ok := req.Context().Value(contextKey).(*requestRecord) 30 if !ok { 31 return 32 } 33 34 record.lock.Lock() 35 record.isLongPolling = true 36 record.lock.Unlock() 37 } 38 39 // UpdatePanicError updates a context's error info, a panic may be recovered by other middlewares, but we still need to know that. 40 func UpdatePanicError(ctx context.Context, err interface{}) { 41 record, ok := ctx.Value(contextKey).(*requestRecord) 42 if !ok { 43 return 44 } 45 46 record.lock.Lock() 47 record.panicError = err 48 record.lock.Unlock() 49 }