From 4018d6b98553d25926d256c066b86aa0a86c4f6b Mon Sep 17 00:00:00 2001 From: Nathan Coleman Date: Tue, 21 May 2024 17:07:37 -0400 Subject: [PATCH] Update naming patterns to match non-catalog funcs --- ...ervices.go => consul_exported_services.go} | 30 +++++++++---------- template/funcs.go | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) rename dependency/{catalog_exported_services.go => consul_exported_services.go} (73%) diff --git a/dependency/catalog_exported_services.go b/dependency/consul_exported_services.go similarity index 73% rename from dependency/catalog_exported_services.go rename to dependency/consul_exported_services.go index 95bc53233..3303da542 100644 --- a/dependency/catalog_exported_services.go +++ b/dependency/consul_exported_services.go @@ -13,17 +13,17 @@ import ( const ( exportedServicesEndpointLabel = "list.exportedServices" - // CatalogExportedServicesQuerySleepTime is the amount of time to sleep between + // ListExportedServicesQuerySleepTime is the amount of time to sleep between // queries, since the endpoint does not support blocking queries. - CatalogExportedServicesQuerySleepTime = 15 * time.Second + ListExportedServicesQuerySleepTime = 15 * time.Second ) // Ensure implements -var _ Dependency = (*CatalogExportedServicesQuery)(nil) +var _ Dependency = (*ListExportedServicesQuery)(nil) -// CatalogExportedServicesQuery is the representation of a requested catalog partitions +// ListExportedServicesQuery is the representation of a requested exported services // dependency from inside a template. -type CatalogExportedServicesQuery struct { +type ListExportedServicesQuery struct { stopCh chan struct{} partition string } @@ -57,15 +57,15 @@ func fromConsulExportedService(svc capi.ResolvedExportedService) ExportedService } } -// NewCatalogExportedServicesQuery parses a string of the format @dc. -func NewCatalogExportedServicesQuery(s string) (*CatalogExportedServicesQuery, error) { - return &CatalogExportedServicesQuery{ +// NewListExportedServicesQuery parses a string of the format @dc. +func NewListExportedServicesQuery(s string) (*ListExportedServicesQuery, error) { + return &ListExportedServicesQuery{ stopCh: make(chan struct{}, 1), partition: s, }, nil } -func (c *CatalogExportedServicesQuery) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error) { +func (c *ListExportedServicesQuery) Fetch(clients *ClientSet, opts *QueryOptions) (interface{}, *ResponseMetadata, error) { opts = opts.Merge(&QueryOptions{ ConsulPartition: c.partition, }) @@ -85,12 +85,12 @@ func (c *CatalogExportedServicesQuery) Fetch(clients *ClientSet, opts *QueryOpti // This is probably okay given the frequency in which partitions actually // change, but is technically not edge-triggering. if opts.WaitIndex != 0 { - log.Printf("[TRACE] %s: long polling for %s", c, CatalogDatacentersQuerySleepTime) + log.Printf("[TRACE] %s: long polling for %s", c, ListExportedServicesQuerySleepTime) select { case <-c.stopCh: return nil, nil, ErrStopped - case <-time.After(CatalogExportedServicesQuerySleepTime): + case <-time.After(ListExportedServicesQuerySleepTime): } } @@ -126,18 +126,18 @@ func (c *CatalogExportedServicesQuery) Fetch(clients *ClientSet, opts *QueryOpti // CanShare returns if this dependency is shareable. // TODO What is this? -func (c *CatalogExportedServicesQuery) CanShare() bool { +func (c *ListExportedServicesQuery) CanShare() bool { return true } -func (c *CatalogExportedServicesQuery) String() string { +func (c *ListExportedServicesQuery) String() string { return exportedServicesEndpointLabel } -func (c *CatalogExportedServicesQuery) Stop() { +func (c *ListExportedServicesQuery) Stop() { close(c.stopCh) } -func (c *CatalogExportedServicesQuery) Type() Type { +func (c *ListExportedServicesQuery) Type() Type { return TypeConsul } diff --git a/template/funcs.go b/template/funcs.go index 6dea9cf43..005847dc1 100644 --- a/template/funcs.go +++ b/template/funcs.go @@ -106,7 +106,7 @@ func exportedServicesFunc(b *Brain, used, missing *dep.Set) func(...string) ([]d return result, errors.New("exportedServices: wrong number of arguments, expected 0 or 1") } - d, err := dep.NewCatalogExportedServicesQuery(strings.Join(s, "")) + d, err := dep.NewListExportedServicesQuery(strings.Join(s, "")) if err != nil { return result, err }