{"modulePath":"github.com/phcp-tech/common-library-golang","version":"v0.2.7","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package httpserver\n\n## Constants\n\n```go\nconst (\n\n\t// recommended graceful shutdown timeout for Runner.shutdown ctx; not enforced internally\n\tDefaultShutdownTimeout = 10 * time.Second\n\n\t// NoWriteTimeout, passed as Config.WriteTimeout, disables the write\n\t// timeout entirely (e.g. for a large file download endpoint). The Go\n\t// zero value can't be used for this — resolve() already treats a zero\n\t// WriteTimeout as \"not set\", replacing it with defaultWriteTimeout — so\n\t// this uses a negative duration instead. net/http.Server treats any\n\t// zero-or-negative WriteTimeout identically (it only ever calls\n\t// SetWriteDeadline when WriteTimeout \u003e 0), so this is exactly as\n\t// unlimited as a literal 0 would be if net/http saw it directly.\n\tNoWriteTimeout = -1 * time.Nanosecond\n)\n```\nDefault HTTP server timeout values. NOTE on WriteTimeout: net/http.Server treats a zero-or-negative WriteTimeout as \"no limit\" (required for large file downloads — a non-zero WriteTimeout applies to the entire response write duration and will kill long-running file transfers server-side regardless of the client's own timeout settings). But Config's own zero value already means \"not set, apply the default\" for every duration field via resolve() below, so a literal 0 can't reach net/http as \"no limit\" — passing it just gets overwritten by defaultWriteTimeout. Use NoWriteTimeout instead to request no limit explicitly; see its doc comment.\n\n## Types\n\n```go\ntype Config struct {\n\tHost    string // Address to bind, e.g. \"127.0.0.1\" for local-only access; empty binds all interfaces\n\tPort    string // TCP port to listen on, e.g. \"8080\"\n\tCrtFile string // TLS certificate file path; empty disables TLS\n\tKeyFile string // TLS private key file path; empty disables TLS\n\n\tReadTimeout       time.Duration // default: 30s\n\tWriteTimeout      time.Duration // default: 60s; pass NoWriteTimeout for unlimited (e.g. file downloads)\n\tIdleTimeout       time.Duration // default: 120s\n\tReadHeaderTimeout time.Duration // default: 10s\n}\n```\nConfig holds all configuration for the HTTP server runner. Zero values for duration fields fall back to the package defaults above, except WriteTimeout — see NoWriteTimeout to explicitly request no limit. CrtFile and KeyFile must both be non-empty to enable TLS.\n\n```go\ntype IRunner interface {\n\t// Start starts the server and blocks until it is stopped.\n\t// Returns nil after a graceful shutdown; returns a non-nil error on failure.\n\tStart(handler http.Handler) error\n\n\t// Shutdown gracefully stops the server, waiting for in-flight requests to complete until ctx is cancelled or times out.\n\tShutdown(ctx context.Context) error\n}\n```\nIRunner abstracts a server that can be started and gracefully stopped. The two concrete implementations are:\n\n  - httpRunner (this package) — plain HTTP/HTTPS server\n  - httpserver/lambda.NewHttpServer() — AWS Lambda adapter (unexported lambdaRunner)\n\nImport httpserver/lambda only when Lambda support is required; it carries the AWS SDK dependencies and does not affect callers that only need HTTP.\n\n```go\nfunc NewHttpServer(cfg Config) IRunner\n```\nNewHttpServer returns a plain HTTP/HTTPS IRunner configured by cfg. Zero-value duration fields in cfg fall back to the package defaults. For AWS Lambda mode import and use the httpserver/lambda subpackage instead.\n\n","path":"github.com/phcp-tech/common-library-golang/httpserver","name":"httpserver","synopsis":"","isRedistributable":true}
