fixed api, fixed ListFiles function

This commit is contained in:
yusing
2024-10-02 17:34:35 +08:00
parent ed9d8aab6f
commit ef52ccb929
8 changed files with 62 additions and 51 deletions

View File

@@ -31,8 +31,13 @@ type (
OnEvent(event W.Event, routes R.Routes) EventResult
String() string
}
ProviderType string
EventResult struct {
ProviderType string
ProviderStats struct {
NumRPs int `json:"num_reverse_proxies"`
NumStreams int `json:"num_streams"`
Type ProviderType `json:"type"`
}
EventResult struct {
nRemoved int
nAdded int
err E.NestedError
@@ -164,6 +169,24 @@ func (p *Provider) LoadRoutes() E.NestedError {
return E.FailWith("loading routes", err)
}
func (p *Provider) Statistics() ProviderStats {
numRPs := 0
numStreams := 0
p.routes.RangeAll(func(_ string, r R.Route) {
switch r.Type() {
case R.RouteTypeReverseProxy:
numRPs++
case R.RouteTypeStream:
numStreams++
}
})
return ProviderStats{
NumRPs: numRPs,
NumStreams: numStreams,
Type: p.t,
}
}
func (p *Provider) watchEvents() {
p.watcherCtx, p.watcherCancel = context.WithCancel(context.Background())
events, errs := p.watcher.Events(p.watcherCtx)