mirror of
https://github.com/yusing/godoxy.git
synced 2026-02-25 02:05:00 +01:00
- 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
48 lines
1.2 KiB
Go
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,
|
|
}
|
|
}
|