Skip to content

Commit 612ec67

Browse files
committed
introduce TypedName to reduce boilerplate
Signed-off-by: Etai Lev Ran <[email protected]>
1 parent 9948b29 commit 612ec67

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

pkg/epp/plugins/typedname.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package plugins
18+
19+
// TypedName is a utility struct providing a type and a name
20+
// to plugins.
21+
// It implements the Plugin interface and can be embedded in
22+
// plugins across the code to reduce boilerplate.
23+
type TypedName struct {
24+
objType string
25+
objName string
26+
}
27+
28+
// NewTypedName returns a new TypedName struct configured with
29+
// the given type and name.
30+
func NewTypedName(objtype, objname string) TypedName {
31+
return TypedName{
32+
objType: objtype,
33+
objName: objname,
34+
}
35+
}
36+
37+
// Type returns the type of the plugin.
38+
func (tn *TypedName) Type() string {
39+
return tn.objType
40+
}
41+
42+
// Name returns the name of this plugin instance.
43+
func (tn *TypedName) Name() string {
44+
return tn.objName
45+
}
46+
47+
// SetName sets the instance name.
48+
func (tn *TypedName) SetName(name string) {
49+
tn.objName = name
50+
}

0 commit comments

Comments
 (0)