Skip to content

Commit 801c790

Browse files
committed
enhance: 客户端获取服务目录支持可见性
1 parent c39af45 commit 801c790

File tree

5 files changed

+1574
-1468
lines changed

5 files changed

+1574
-1468
lines changed

cache/api/tools.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Tencent is pleased to support the open source community by making Polaris available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://opensource.org/licenses/BSD-3-Clause
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed
13+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations under the License.
16+
*/
17+
18+
package api
19+
20+
import "time"
21+
22+
func NewExpireEntry[T any](t T, maxAlive time.Duration) *ExpireEntry[T] {
23+
return &ExpireEntry[T]{
24+
data: t,
25+
maxAlive: maxAlive,
26+
}
27+
}
28+
29+
func EmptyExpireEntry[T any](t T, maxAlive time.Duration) *ExpireEntry[T] {
30+
return &ExpireEntry[T]{
31+
empty: true,
32+
maxAlive: maxAlive,
33+
}
34+
}
35+
36+
type ExpireEntry[T any] struct {
37+
empty bool
38+
data T
39+
lastAccess time.Time
40+
maxAlive time.Duration
41+
}
42+
43+
func (e *ExpireEntry[T]) Get() T {
44+
if e.empty {
45+
return e.data
46+
}
47+
e.lastAccess = time.Now()
48+
return e.data
49+
}
50+
51+
func (e *ExpireEntry[T]) IsExpire() bool {
52+
return time.Since(e.lastAccess) > e.maxAlive
53+
}

cache/api/types.go

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ type (
268268
GetRevisionWorker() ServiceRevisionWorker
269269
// GetVisibleSameNameServices get same service in other namespace and it's visible
270270
GetVisibleSameNameServices(name string, namespace string) []*model.Service
271+
// GetVisibleServices get all services in other namespace and it's visible
272+
GetVisibleServices(ctx context.Context, namespace string) []*model.Service
271273
}
272274

273275
// ServiceRevisionWorker
@@ -881,36 +883,3 @@ type (
881883
HitGrayRule(name string, labels map[string]string) bool
882884
}
883885
)
884-
885-
func NewExpireEntry[T any](t T, maxAlive time.Duration) *ExpireEntry[T] {
886-
return &ExpireEntry[T]{
887-
data: t,
888-
maxAlive: maxAlive,
889-
}
890-
}
891-
892-
func EmptyExpireEntry[T any](t T, maxAlive time.Duration) *ExpireEntry[T] {
893-
return &ExpireEntry[T]{
894-
empty: true,
895-
maxAlive: maxAlive,
896-
}
897-
}
898-
899-
type ExpireEntry[T any] struct {
900-
empty bool
901-
data T
902-
lastAccess time.Time
903-
maxAlive time.Duration
904-
}
905-
906-
func (e *ExpireEntry[T]) Get() T {
907-
if e.empty {
908-
return e.data
909-
}
910-
e.lastAccess = time.Now()
911-
return e.data
912-
}
913-
914-
func (e *ExpireEntry[T]) IsExpire() bool {
915-
return time.Since(e.lastAccess) > e.maxAlive
916-
}

0 commit comments

Comments
 (0)