package objects import ( "github.com/Mindgamesnl/socketio" "sync" ) type Server struct { Socket socketio.Socket ID string Sessions map[string]socketio.Socket Attraction map[string]string mux sync.RWMutex } func (serv *Server) CanAttraction(attraction string) bool { serv.mux.RLock() defer serv.mux.RUnlock() _,b := serv.Attraction[attraction] return !b } func (serv *Server) AddSession(session, attraction string, io socketio.Socket) { serv.mux.Lock() serv.Sessions[session] = io serv.Attraction[attraction] = session serv.mux.Unlock() } func (serv *Server) HasSession(session string) (bool, socketio.Socket) { serv.mux.RLock() defer serv.mux.RUnlock() io, b := serv.Sessions[session] return b, io } func (serv *Server) RemoveSession(session, attraction string) { serv.mux.Lock() delete(serv.Sessions, session) delete(serv.Attraction, attraction) serv.mux.Unlock() }