Documentation
¶
Index ¶
- Constants
- func AppErrorHandler(err error, c echo.Context)
- func DeployRateLimiter(cfg RateLimitConfig) echo.MiddlewareFunc
- func IPCeilingRateLimiter(cfg RateLimitConfig) echo.MiddlewareFunc
- func LoginRateLimiter(cfg RateLimitConfig) echo.MiddlewareFunc
- func OrgContextMiddleware() echo.MiddlewareFunc
- func OrgIDFromContext(ctx context.Context) (string, bool)
- func RateLimiter(cfg RateLimitConfig) echo.MiddlewareFunc
- func SlogLogger() echo.MiddlewareFunc
- func UserEmailFromEchoContext(c echo.Context) string
- func WebSocketBearerSubprotocol() echo.MiddlewareFunc
- type Actor
- type RateLimitConfig
Constants ¶
const ( // WebSocketProtocolHeader 는 핸드셰이크에서 서브프로토콜을 협상하는 헤더다. WebSocketProtocolHeader = "Sec-WebSocket-Protocol" // WebSocketBearerProtocol 은 "다음 값이 Bearer 토큰" 이라는 표식이다. // 서버는 핸드셰이크 응답에 이 값을 그대로 돌려줘야 브라우저가 연결을 받아들인다 // (gorilla Upgrader 의 Subprotocols 에 같은 값이 있어야 한다). WebSocketBearerProtocol = "bearer" )
Variables ¶
This section is empty.
Functions ¶
func AppErrorHandler ¶
AppErrorHandler converts AppError and echo.HTTPError into a standard JSON error response.
func DeployRateLimiter ¶
func DeployRateLimiter(cfg RateLimitConfig) echo.MiddlewareFunc
func IPCeilingRateLimiter ¶
func IPCeilingRateLimiter(cfg RateLimitConfig) echo.MiddlewareFunc
IPCeilingRateLimiter guards every route with a per-IP flood ceiling.
전역(`e.Use`)에 붙는 자리라 인증 미들웨어가 아직 돌지 않았고, 따라서 호출자가 누구인지 알 수 없다. 그래서 신원을 따지지 않고 오직 IP 로만 센다. 사용자별 정확한 한도는 인증 뒤에 붙는 RateLimiter 가 맡는다.
func LoginRateLimiter ¶
func LoginRateLimiter(cfg RateLimitConfig) echo.MiddlewareFunc
func OrgContextMiddleware ¶
func OrgContextMiddleware() echo.MiddlewareFunc
func RateLimiter ¶
func RateLimiter(cfg RateLimitConfig) echo.MiddlewareFunc
func SlogLogger ¶
func SlogLogger() echo.MiddlewareFunc
SlogLogger returns an Echo middleware that logs requests using slog.
func UserEmailFromEchoContext ¶
UserEmailFromEchoContext 는 인증된 사용자의 이메일을 꺼낸다.
리플렉션으로 읽는 이유는 orgIDFromUser 와 같다 — 이 패키지는 인증 모듈의 사용자 타입을 알지 못하고, 알아서도 안 된다(모듈 간 직접 import 금지).
func WebSocketBearerSubprotocol ¶
func WebSocketBearerSubprotocol() echo.MiddlewareFunc
WebSocketBearerSubprotocol lets browser WebSockets carry a bearer token.
브라우저의 WebSocket API 는 임의 헤더를 못 붙인다. 유일하게 통제할 수 있는 값이 `new WebSocket(url, protocols)` 로 보내는 Sec-WebSocket-Protocol 이라, 여기에 ["bearer", "<token>"] 을 실어 보내고 이 미들웨어가 표준 Authorization 헤더로 옮긴다. 그 뒤에 평소 쓰던 인증 미들웨어를 그대로 붙이면 HTTP 와 동일한 검증을 받는다.
쿼리 파라미터(`?token=`)를 쓰지 않는 이유는 토큰이 액세스 로그·프록시 로그·브라우저 히스토리에 남기 때문이다. 헤더로 오는 값은 그런 경로로 새지 않는다.
검증은 하지 않는다 — 자격증명을 옮기기만 하고, 거절 여부는 뒤의 인증 미들웨어가 정한다. 그래야 거절 논리가 한 곳에만 있다.
Types ¶
type Actor ¶
Actor 는 요청을 일으킨 주체다.
func ActorFromContext ¶
ActorFromContext 는 인증 컨텍스트를 먼저 보고, 없으면 헤더로 떨어진다.
type RateLimitConfig ¶
type RateLimitConfig struct {
Authenticated int
Unauthenticated int
Login int
Deploy int
IPCeiling int
}
RateLimitConfig holds the limits for each tier.
Authenticated / Unauthenticated 는 인증 미들웨어 뒤에 붙는 사용자 단위 리미터가 쓴다. IPCeiling 은 인증 앞(전역)에 붙는 폭주 방어용 IP 상한이다. 두 값을 나눠 두는 이유는 전역 지점에서는 호출자가 누구인지 알 수 없기 때문이다.
func RateLimitConfigForMode ¶
func RateLimitConfigForMode(mode string) RateLimitConfig
RateLimitConfigForMode picks limits appropriate to the server mode.
development 모드는 인증 미들웨어를 켜지 않는다(main.go 참고). 그래서 모든 요청이 미인증으로 분류되는데, 여기에 익명 한도(30/분)를 씌우면 5초마다 폴링하는 모니터링 화면 하나만 열어도 곧 429 가 난다. 로컬에서 인증이 없는 것은 설계이지 익명 트래픽이 아니므로, 개발자 본인으로 보고 인증 한도를 적용한다.