Feat: add sse broker
This commit is contained in:
		| @@ -2,6 +2,7 @@ package handlers | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"encoding/json" | ||||
| 	"golias/models" | ||||
| ) | ||||
|  | ||||
| @@ -9,6 +10,18 @@ func createRoom(ctx context.Context, req *models.RoomReq) (*models.Room, error) | ||||
| 	return nil, nil | ||||
| } | ||||
|  | ||||
| func getRoomByID(roomID string) (*models.Room, error) { | ||||
| 	roomBytes, err := memcache.Get(models.CacheRoomPrefix + roomID) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	resp := &models.Room{} | ||||
| 	if err := json.Unmarshal(roomBytes, &resp); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return resp, nil | ||||
| } | ||||
|  | ||||
| // context | ||||
| func getRoomIDFromCtx(ctx context.Context) string { | ||||
| 	id, _ := ctx.Value(models.CtxRoomIDKey).(string) | ||||
|   | ||||
| @@ -40,6 +40,8 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { | ||||
| 		abortWithError(w, "failed to get room") | ||||
| 		return | ||||
| 	} | ||||
| 	log.Debug("got room", "room", room) | ||||
| 	// update room score | ||||
| 	color, exists := roundWords[word] | ||||
| 	log.Debug("got show-color request", "word", word, "color", color) | ||||
| 	if !exists { | ||||
|   | ||||
| @@ -6,6 +6,7 @@ import ( | ||||
| 	"crypto/sha256" | ||||
| 	"encoding/base64" | ||||
| 	"errors" | ||||
| 	"golias/models" | ||||
| 	"net/http" | ||||
| 	"time" | ||||
| ) | ||||
| @@ -91,9 +92,9 @@ func GetSession(next http.Handler) http.Handler { | ||||
| 			return | ||||
| 		} | ||||
| 		ctx := context.WithValue(r.Context(), | ||||
| 			"username", userSession.Username) | ||||
| 			models.CtxUsernameKey, userSession.Username) | ||||
| 		ctx = context.WithValue(r.Context(), | ||||
| 			"session", userSession) | ||||
| 			models.CtxSessionKey, userSession) | ||||
| 		if err := cacheSetSession(sessionToken, | ||||
| 			userSession); err != nil { | ||||
| 			msg := "failed to marshal user session" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder