File tree Expand file tree Collapse file tree 5 files changed +1574
-1468
lines changed
Expand file tree Collapse file tree 5 files changed +1574
-1468
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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- }
You can’t perform that action at this time.
0 commit comments