39 lines
765 B
Go
39 lines
765 B
Go
package wordle
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
|
|
"gitea.konchin.com/ytshih/inp2025/game/server/middlewares"
|
|
"gitea.konchin.com/ytshih/inp2025/game/utils"
|
|
"github.com/uptrace/bunrouter"
|
|
"github.com/vmihailenco/msgpack/v5"
|
|
)
|
|
|
|
func (self *Handlers) WSPostGuess(
|
|
w http.ResponseWriter,
|
|
req bunrouter.Request,
|
|
) error {
|
|
b, err := io.ReadAll(req.Body)
|
|
if err != nil {
|
|
return middlewares.HTTPError{
|
|
StatusCode: http.StatusBadRequest,
|
|
Message: "failed to read body",
|
|
OriginError: err,
|
|
}
|
|
}
|
|
|
|
var op Operation
|
|
if err := msgpack.Unmarshal(b, &op); err != nil {
|
|
return middlewares.HTTPError{
|
|
StatusCode: http.StatusBadRequest,
|
|
Message: "failed to unmarshal msgpack",
|
|
OriginError: err,
|
|
}
|
|
}
|
|
|
|
self.opCh <- op
|
|
|
|
return utils.Success(w)
|
|
}
|