accounts/internal/agentmode/source_http.go
Haitao Pan ee6e1a6363 feat: move account service to repo root
# Conflicts:
#	account/Makefile
#	account/go.mod
#	docs/account-admin-settings.md
#	docs/account-svc-plus.md
2026-01-16 16:15:23 +08:00

34 lines
875 B
Go

package agentmode
import (
"context"
"time"
"account/internal/xrayconfig"
)
// HTTPClientSource retrieves Xray clients from the controller over HTTP.
type HTTPClientSource struct {
client *Client
tracker *syncTracker
}
// NewHTTPClientSource constructs a source backed by the provided client and
// tracker.
func NewHTTPClientSource(client *Client, tracker *syncTracker) *HTTPClientSource {
return &HTTPClientSource{client: client, tracker: tracker}
}
// ListClients implements xrayconfig.ClientSource by fetching the latest client
// list via the controller API.
func (s *HTTPClientSource) ListClients(ctx context.Context) ([]xrayconfig.Client, error) {
resp, err := s.client.ListClients(ctx)
if err != nil {
return nil, err
}
if s.tracker != nil {
s.tracker.UpdateFetch(len(resp.Clients), resp.Revision, time.Now().UTC())
}
return resp.Clients, nil
}