Documentation
¶
Overview ¶
Package httpserver는 HTTP server를 위한 작은 lifecycle helper를 제공합니다.
패키지 소개
이 패키지는 shared-go runtime 계층에서 재사용하는 HTTP server start/shutdown 흐름만 공통화합니다. process signal 처리, shutdown timeout 생성, runtime 별 background worker 정리는 lifecycle 패키지와 각 runtime 이 계속 담당합니다.
주요 사용 패턴
runtime 은 lifecycle.Run 의 Start hook 에서 Start(server, logger, errCh) 를 호출하고, Shutdown hook 에서 Shutdown(ctx, server, "shutdown http server") 를 호출합니다. server construction 과 router/H2C 조립은 호출부의 기존 책임으로 남깁니다.
Index ¶
- Constants
- func Run(ctx context.Context, server Server, shutdownTimeout time.Duration) error
- func Shutdown(ctx context.Context, server Server, errorText string) error
- func Start(server Server, logger *slog.Logger, errCh chan<- error)
- func StartServerWithPrefix(server Server, errorText string, logger *slog.Logger, errCh chan<- error)
- type Server
Constants ¶
const DefaultShutdownTimeout = 30 * time.Second
DefaultShutdownTimeout 은 shutdownTimeout 이 0 이하일 때 적용하는 보수적 기본 종료 예산입니다.
Variables ¶
This section is empty.
Functions ¶
func Run ¶ added in v1.32.0
Run 은 ctx 취소 시 server 를 종료합니다. shutdownTimeout 이 0 이하이면 무기한 대기 대신 DefaultShutdownTimeout 을 적용해 process 종료가 멈추지 않도록 합니다.
func Shutdown ¶
Shutdown 은 server.Shutdown(ctx) 결과를 errorText prefix 와 함께 wrap 합니다. 이미 종료된 server 가 돌려주는 http.ErrServerClosed 는 정상 종료로 흡수해 nil 을 반환합니다.