mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 00:38:33 +02:00
refactor(config): restructured with better concurrency and error handling, reduced cross referencing
This commit is contained in:
42
internal/config/query/query.go
Normal file
42
internal/config/query/query.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package statequery
|
||||
|
||||
import (
|
||||
config "github.com/yusing/godoxy/internal/config/types"
|
||||
"github.com/yusing/godoxy/internal/types"
|
||||
)
|
||||
|
||||
type RouteProviderListResponse struct {
|
||||
ShortName string `json:"short_name"`
|
||||
FullName string `json:"full_name"`
|
||||
} // @name RouteProvider
|
||||
|
||||
func DumpRouteProviders() map[string]types.RouteProvider {
|
||||
state := config.ActiveState.Load()
|
||||
entries := make(map[string]types.RouteProvider, state.NumProviders())
|
||||
for _, p := range state.IterProviders() {
|
||||
entries[p.ShortName()] = p
|
||||
}
|
||||
return entries
|
||||
}
|
||||
|
||||
func RouteProviderList() []RouteProviderListResponse {
|
||||
state := config.ActiveState.Load()
|
||||
list := make([]RouteProviderListResponse, 0, state.NumProviders())
|
||||
for _, p := range state.IterProviders() {
|
||||
list = append(list, RouteProviderListResponse{
|
||||
ShortName: p.ShortName(),
|
||||
FullName: p.String(),
|
||||
})
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func SearchRoute(alias string) types.Route {
|
||||
state := config.ActiveState.Load()
|
||||
for _, p := range state.IterProviders() {
|
||||
if r, ok := p.GetRoute(alias); ok {
|
||||
return r
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
38
internal/config/query/stats.go
Normal file
38
internal/config/query/stats.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package statequery
|
||||
|
||||
import (
|
||||
config "github.com/yusing/godoxy/internal/config/types"
|
||||
"github.com/yusing/godoxy/internal/types"
|
||||
)
|
||||
|
||||
type Statistics struct {
|
||||
Total uint16 `json:"total"`
|
||||
ReverseProxies types.RouteStats `json:"reverse_proxies"`
|
||||
Streams types.RouteStats `json:"streams"`
|
||||
Providers map[string]types.ProviderStats `json:"providers"`
|
||||
}
|
||||
|
||||
func GetStatistics() Statistics {
|
||||
state := config.ActiveState.Load()
|
||||
|
||||
var (
|
||||
rps, streams types.RouteStats
|
||||
total uint16
|
||||
providerStats = make(map[string]types.ProviderStats)
|
||||
)
|
||||
|
||||
for _, p := range state.IterProviders() {
|
||||
stats := p.Statistics()
|
||||
providerStats[p.ShortName()] = stats
|
||||
rps.AddOther(stats.RPs)
|
||||
streams.AddOther(stats.Streams)
|
||||
total += stats.RPs.Total + stats.Streams.Total
|
||||
}
|
||||
|
||||
return Statistics{
|
||||
Total: total,
|
||||
ReverseProxies: rps,
|
||||
Streams: streams,
|
||||
Providers: providerStats,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user