Files
codit/backend/internal/rpm/request_log.go

38 lines
763 B
Go

package rpm
import "context"
import "net/http"
type requestLogInfoKey string
const requestLogInfoContextKey requestLogInfoKey = "rpm_request_log_info"
type RequestLogInfo struct {
OrgPath string
ProjectID string
ProjectSlug string
RepoID string
RepoName string
}
func WithRequestLogInfo(r *http.Request, info RequestLogInfo) *http.Request {
var ctx context.Context
if r == nil {
return nil
}
ctx = context.WithValue(r.Context(), requestLogInfoContextKey, info)
return r.WithContext(ctx)
}
func requestLogInfoFromContext(ctx context.Context) (RequestLogInfo, bool) {
var info RequestLogInfo
var ok bool
if ctx == nil {
return info, false
}
info, ok = ctx.Value(requestLogInfoContextKey).(RequestLogInfo)
return info, ok
}