GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
486 B

  1. package session
  2. import "context"
  3. type contextKeyType struct{ name string }
  4. func (ck *contextKeyType) String() string {
  5. return ck.name
  6. }
  7. var contextKey = &contextKeyType{name: "session context key"}
  8. // FromContext gets a session fron the context.
  9. func FromContext(ctx context.Context) *Session {
  10. return ctx.Value(contextKey).(*Session)
  11. }
  12. func contextWithSession(parent context.Context, session *Session) context.Context {
  13. return context.WithValue(parent, contextKey, session)
  14. }