fix(handler/api): add nil guard, propagate Shutdown error, doc comments, 20 tests

- Return errHandlerNotInitialized when Handle called before Init
- Propagate s.Shutdown(ctx) error instead of silently discarding
- Add doc comments to all exported symbols
- Add 20 tests covering constructor, init, metadata parsing, HTTP
  endpoints via httptest, Handle lifecycle, singleConnListener, and
  compile-time interface assertions
This commit is contained in:
ginuerzh
2026-05-26 20:44:23 +08:00
parent 1510f841c3
commit b3424b769e
3 changed files with 418 additions and 1 deletions
+2
View File
@@ -5,11 +5,13 @@ import (
mdutil "github.com/go-gost/x/metadata/util"
)
// metadata holds parsed configuration for the api handler.
type metadata struct {
accesslog bool
pathPrefix string
}
// parseMetadata extracts api-specific configuration from the generic metadata map.
func (h *apiHandler) parseMetadata(md mdata.Metadata) (err error) {
h.md.accesslog = mdutil.GetBool(md, "api.accessLog", "accessLog")
h.md.pathPrefix = mdutil.GetString(md, "api.pathPrefix", "pathPrefix")