Files
godoxy/internal/config/query.go
yusing 35a3e3fef6 refactor(api): restructured API for type safety, maintainability and docs generation
- These changes makes the API incombatible with previous versions
- Added new types for error handling, success responses, and health checks.
- Updated health check logic to utilize the new types for better clarity and structure.
- Refactored existing handlers to improve response consistency and error handling.
- Updated Makefile to include a new target for generating API types from Swagger.
- Updated "new agent" API to respond an encrypted cert pair
2025-08-16 13:04:05 +08:00

48 lines
1.2 KiB
Go

package config
import (
config "github.com/yusing/go-proxy/internal/config/types"
"github.com/yusing/go-proxy/internal/route/provider"
"github.com/yusing/go-proxy/internal/types"
)
func (cfg *Config) DumpRouteProviders() map[string]*provider.Provider {
entries := make(map[string]*provider.Provider, cfg.providers.Size())
for _, p := range cfg.providers.Range {
entries[p.ShortName()] = p
}
return entries
}
func (cfg *Config) RouteProviderList() []config.RouteProviderListResponse {
list := make([]config.RouteProviderListResponse, 0, cfg.providers.Size())
for _, p := range cfg.providers.Range {
list = append(list, config.RouteProviderListResponse{
ShortName: p.ShortName(),
FullName: p.String(),
})
}
return list
}
func (cfg *Config) Statistics() map[string]any {
var rps, streams types.RouteStats
var total uint16
providerStats := make(map[string]types.ProviderStats)
for _, p := range cfg.providers.Range {
stats := p.Statistics()
providerStats[p.ShortName()] = stats
rps.AddOther(stats.RPs)
streams.AddOther(stats.Streams)
total += stats.RPs.Total + stats.Streams.Total
}
return map[string]any{
"total": total,
"reverse_proxies": rps,
"streams": streams,
"providers": providerStats,
}
}