api/transport.go
Snider d90a5be936 refactor: AX compliance sweep — replace banned stdlib imports with core primitives
Replaced fmt, strings, sort, os, io, sync, encoding/json, path/filepath,
errors, log, reflect with core.Sprintf, core.E, core.Contains, core.Trim,
core.Split, core.Join, core.JoinPath, slices.Sort, c.Fs(), c.Lock(),
core.JSONMarshal, core.ReadAll and other CoreGO v0.8.0 primitives.

Framework boundary exceptions preserved where stdlib types are required
by external interfaces (Gin, net/http, CGo, Wails, bubbletea).

Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-13 09:32:00 +01:00

69 lines
1.9 KiB
Go

// SPDX-License-Identifier: EUPL-1.2
package api
import core "dappco.re/go/core"
// 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.
//
// Example:
//
// cfg := api.TransportConfig{SwaggerPath: "/swagger", WSPath: "/ws"}
type TransportConfig struct {
SwaggerEnabled bool
SwaggerPath string
GraphQLPath string
GraphQLEnabled bool
GraphQLPlayground bool
GraphQLPlaygroundPath string
WSEnabled bool
WSPath string
SSEEnabled bool
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.
//
// Example:
//
// cfg := engine.TransportConfig()
func (e *Engine) TransportConfig() TransportConfig {
if e == nil {
return TransportConfig{}
}
cfg := TransportConfig{
SwaggerEnabled: e.swaggerEnabled,
WSEnabled: e.wsHandler != nil,
SSEEnabled: e.sseBroker != nil,
PprofEnabled: e.pprofEnabled,
ExpvarEnabled: e.expvarEnabled,
}
gql := e.GraphQLConfig()
cfg.GraphQLEnabled = gql.Enabled
cfg.GraphQLPlayground = gql.Playground
cfg.GraphQLPlaygroundPath = gql.PlaygroundPath
if e.swaggerEnabled || core.Trim(e.swaggerPath) != "" {
cfg.SwaggerPath = resolveSwaggerPath(e.swaggerPath)
}
if gql.Path != "" {
cfg.GraphQLPath = gql.Path
}
if e.wsHandler != nil || core.Trim(e.wsPath) != "" {
cfg.WSPath = resolveWSPath(e.wsPath)
}
if e.sseBroker != nil || core.Trim(e.ssePath) != "" {
cfg.SSEPath = resolveSSEPath(e.ssePath)
}
return cfg
}