Найдено статическим анализом (dupl/jscpd) + проверено вручную:
Go:
- appstate/path.go: ResolveDBPath/ResolveConfigPath → общий resolvePath()
- handlers/respond.go: дженерик BindJSON[T] для bind+422-ошибки
- article/generator.go: buildNetSegment/buildPSUSegment → buildProfileSegment()
- cmd/qfs/main.go (+respond.go): 8 повторяющихся switch{case errors.Is(...)}
→ respondByErrCase(c, err, errCase{...}, ...)
Frontend (index.html):
- 5 идентичных обработчиков клавиатурной навигации автокомплита
→ handleAutocompleteKeyGeneric(event, onSelect)
- 4 функции сборки нового элемента корзины из автокомплита
→ buildNewCartItem()/commitCartChange()
Также: PricingMarkup — единая точка правды для аплифт-коэффициента
в JS (render + export), с cross-reference комментариями к Go-константам
в export.go (defaultSaleMarkup/stockCompetitorMarkupFactor).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
32 lines
886 B
Go
32 lines
886 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"git.mchus.pro/mchus/quoteforge/internal/handlers"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// errCase maps a sentinel error to the HTTP status/message respondByErrCase
|
|
// should use when errors.Is matches it.
|
|
type errCase struct {
|
|
err error
|
|
status int
|
|
message string
|
|
}
|
|
|
|
// respondByErrCase responds with the status/message of the first matching
|
|
// case (checked in order), or a 500 "internal server error" fallback when
|
|
// none match. Centralizes the switch-on-sentinel-error pattern repeated
|
|
// across the config/project HTTP handlers in this file.
|
|
func respondByErrCase(c *gin.Context, err error, cases ...errCase) {
|
|
for _, cs := range cases {
|
|
if errors.Is(err, cs.err) {
|
|
handlers.RespondError(c, cs.status, cs.message, err)
|
|
return
|
|
}
|
|
}
|
|
handlers.RespondError(c, http.StatusInternalServerError, "internal server error", err)
|
|
}
|