Skip to content

Commit 40ba019

Browse files
committed
regexpやめる
1 parent f2665b6 commit 40ba019

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

server/lobby/service/api.go

+4-12
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,7 @@ func (sv *LobbyService) handleCreateRoom(w http.ResponseWriter, r *http.Request)
248248
}
249249

250250
var (
251-
idRegexp = regexp.MustCompile("^[0-9a-f]+$")
252-
numRegexp = regexp.MustCompile("^[0-9]+$")
253-
grpRegexp = regexp.MustCompile("^[0-9]+$")
251+
idRegexp = regexp.MustCompile("^[0-9a-f]+$")
254252
)
255253

256254
type JoinVars struct {
@@ -263,25 +261,19 @@ func NewJoinVars(r *http.Request) JoinVars {
263261

264262
func (vars JoinVars) roomId() (string, bool) {
265263
id := vars.r.PathValue("roomId")
266-
return id, idRegexp.Match([]byte(id))
264+
return id, idRegexp.MatchString(id)
267265
}
268266

269267
func (vars JoinVars) roomNumber() (int32, bool) {
270268
v := vars.r.PathValue("roomNumber")
271-
if !numRegexp.Match([]byte(v)) {
272-
return 0, false
273-
}
274269
n, err := strconv.ParseInt(v, 10, 32)
275-
return int32(n), err == nil && n != 0
270+
return int32(n), err == nil && n > 0
276271
}
277272

278273
func (vars JoinVars) searchGroup() (uint32, bool) {
279274
v := vars.r.PathValue("searchGroup")
280-
if !grpRegexp.Match([]byte(v)) {
281-
return 0, false
282-
}
283275
n, err := strconv.ParseInt(v, 10, 32)
284-
return uint32(n), err == nil
276+
return uint32(n), err == nil && n >= 0
285277
}
286278

287279
func (sv *LobbyService) handleJoinRoom(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)