forked from project-safari/zebra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresource.go
45 lines (36 loc) · 856 Bytes
/
resource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package zebra
import (
"context"
)
// Resource interface is implemented by all resources and provides resource
// validation and label selection methods.
type Resource interface {
Validate(ctx context.Context) error
GetMeta() Meta
GetStatus() Status
}
type BaseResource struct {
Meta Meta `json:"meta"`
Status Status `json:"status,omitempty"`
}
func (r *BaseResource) Validate(ctx context.Context) error {
if err := r.Meta.Validate(); err != nil {
return err
}
if err := r.Status.Validate(); err != nil {
return err
}
return nil
}
func (r *BaseResource) GetMeta() Meta {
return r.Meta
}
func (r *BaseResource) GetStatus() Status {
return r.Status
}
func NewBaseResource(rType Type, name, owner, group string) *BaseResource {
return &BaseResource{
Meta: NewMeta(rType, name, group, owner),
Status: DefaultStatus(),
}
}