aicra/api/context.go

45 lines
816 B
Go
Raw Normal View History

2021-04-18 16:14:30 +00:00
package api
import (
"context"
2021-04-18 16:14:30 +00:00
"net/http"
"git.xdrm.io/go/aicra/internal/ctx"
)
// GetRequest extracts the current request from a context.Context
func GetRequest(c context.Context) *http.Request {
var (
raw = c.Value(ctx.Request)
cast, ok = raw.(*http.Request)
)
if !ok {
return nil
}
return cast
}
// GetResponseWriter extracts the response writer from a context.Context
func GetResponseWriter(c context.Context) http.ResponseWriter {
var (
raw = c.Value(ctx.Response)
cast, ok = raw.(http.ResponseWriter)
)
if !ok {
return nil
}
return cast
}
// GetAuth returns the api.Auth associated with this request from a context.Context
func GetAuth(c context.Context) *Auth {
var (
raw = c.Value(ctx.Auth)
cast, ok = raw.(*Auth)
)
if !ok {
return nil
}
return cast
2021-04-18 16:14:30 +00:00
}