Beispiel #1
0
// getCachedCurrentUser returns the current cached user value or nil.
func getCachedCurrentUser(s *bitmonster.Socket) *User {
	// Obtain the user from the cache if present.
	userI := s.Value(cacheUserSocketValueKey)
	if userI == nil {
		return nil
	}

	// Assertion.
	user, ok := userI.(*User)
	if !ok {
		return nil
	}

	return user
}
Beispiel #2
0
// getAuthSocketValue obtains the authentication socket value from the socket.
// If not present, then this function creates the value.
func getAuthSocketValue(s *bitmonster.Socket) *authSocketValue {
	// Get or create the value.
	v := s.Value(authSocketValueKey, func() interface{} {
		// Not present. Create it.
		return newAuthSocketValue()
	})

	// Cast.
	av, ok := v.(*authSocketValue)
	if !ok {
		return nil
	}

	return av
}