api/transport.go
Virgil 8a23545a67 feat(api): expose transport config snapshot
Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-02 06:38:05 +00:00

50 lines
1.4 KiB
Go

// SPDX-License-Identifier: EUPL-1.2
package api
import "strings"
// TransportConfig captures the configured transport endpoints and flags for an Engine.
//
// It is intentionally small and serialisable so callers can inspect the active HTTP
// surface without rebuilding an OpenAPI document.
type TransportConfig struct {
SwaggerPath string
GraphQLPath string
GraphQLPlayground bool
WSPath string
SSEPath string
PprofEnabled bool
ExpvarEnabled bool
}
// TransportConfig returns the currently configured transport metadata for the engine.
//
// The result snapshots the Engine state at call time and normalises any configured
// URL paths using the same rules as the runtime handlers.
func (e *Engine) TransportConfig() TransportConfig {
if e == nil {
return TransportConfig{}
}
cfg := TransportConfig{
GraphQLPlayground: e.graphql != nil && e.graphql.playground,
PprofEnabled: e.pprofEnabled,
ExpvarEnabled: e.expvarEnabled,
}
if e.swaggerEnabled || strings.TrimSpace(e.swaggerPath) != "" {
cfg.SwaggerPath = resolveSwaggerPath(e.swaggerPath)
}
if e.graphql != nil {
cfg.GraphQLPath = e.graphql.path
}
if e.wsHandler != nil || strings.TrimSpace(e.wsPath) != "" {
cfg.WSPath = resolveWSPath(e.wsPath)
}
if e.sseBroker != nil || strings.TrimSpace(e.ssePath) != "" {
cfg.SSEPath = resolveSSEPath(e.ssePath)
}
return cfg
}