Skip to content

Commit 0c4ee47

Browse files
authored
chore: add namespaced id or key (#3677)
1 parent 12d29e7 commit 0c4ee47

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pkg/models/idorkey.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package models
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
)
7+
8+
// NamespacedIDOrKey represents a namespaced id or key (when we don't know if a specific entity is either a key or an id)
9+
// If the type of entity is known please use the ref package or the NamespacedID or the NamespacedKey types
10+
type NamespacedIDOrKey struct {
11+
Namespace string `json:"namespace"`
12+
IDOrKey string `json:"idOrKey"`
13+
}
14+
15+
func (n NamespacedIDOrKey) Validate() error {
16+
var errs []error
17+
18+
if n.Namespace == "" {
19+
errs = append(errs, fmt.Errorf("namespace is required"))
20+
}
21+
22+
if n.IDOrKey == "" {
23+
errs = append(errs, fmt.Errorf("idOrKey is required"))
24+
}
25+
26+
return errors.Join(errs...)
27+
}

0 commit comments

Comments
 (0)