Skip to content

Commit

Permalink
予約枠数を環境変数から読み込めるように
Browse files Browse the repository at this point in the history
  • Loading branch information
tukeJonny committed Nov 1, 2023
1 parent bcb0c15 commit 2488481
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 1 addition & 4 deletions webapp/go/livestream_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import (
"github.com/labstack/echo/v4"
)

// 同時配信可能予約枠数
const NumReservationSlot = 2

type ReserveLivestreamRequest struct {
Tags []int64 `json:"tags"`
Title string `json:"title"`
Expand Down Expand Up @@ -122,7 +119,7 @@ func reserveLivestreamHandler(c echo.Context) error {
if err := tx.GetContext(ctx, &founds, "SELECT COUNT(*) FROM livestreams WHERE user_id = ? AND ? >= start_at AND ? <= end_at", user, reserveStartAt, reserveEndAt); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
if founds >= NumReservationSlot {
if founds >= numReservationSlot {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ユーザ%dが予約できません", user))
}
}
Expand Down
7 changes: 7 additions & 0 deletions webapp/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ var (
powerDNSSubdomainAddress string
dbConn *sqlx.DB
secret = []byte("isucon13_session_cookiestore_defaultsecret")
numReservationSlot = 2
)

func init() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
if secretKey, ok := os.LookupEnv("ISUCON13_SESSION_SECRETKEY"); ok {
secret = []byte(secretKey)
}
if slotStr, ok := os.LookupEnv("ISUCON13_NUM_RESERVATION_SLOT"); ok {
slot, err := strconv.Atoi(slotStr)
if err == nil {
numReservationSlot = slot
}
}
}

// FIXME: ポータルと足並み揃えて修正
Expand Down

0 comments on commit 2488481

Please sign in to comment.