1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-24 13:43:12 +02:00
focalboard/server/api/context.go

30 lines
566 B
Go
Raw Normal View History

package api
2021-01-23 00:14:12 +02:00
import (
"context"
"net"
"net/http"
)
type contextKey int
2021-01-23 00:14:12 +02:00
const (
httpConnContextKey contextKey = iota
sessionContextKey
)
2021-01-23 00:14:12 +02:00
// SetContextConn stores the connection in the request context.
2021-01-23 00:14:12 +02:00
func SetContextConn(ctx context.Context, c net.Conn) context.Context {
return context.WithValue(ctx, httpConnContextKey, c)
2021-01-23 00:14:12 +02:00
}
// GetContextConn gets the stored connection from the request context.
2021-01-23 00:14:12 +02:00
func GetContextConn(r *http.Request) net.Conn {
value := r.Context().Value(httpConnContextKey)
2021-01-23 00:14:12 +02:00
if value == nil {
return nil
}
return value.(net.Conn)
}