/
service-condition-resolver.go
79 lines (67 loc) · 3.06 KB
/
service-condition-resolver.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Package edgecluster implements different edge cluster GraphQL query resovlers required by the GraphQL transport layer
package edgecluster
import (
"context"
"time"
"github.com/decentralized-cloud/api-gateway/services/graphql/types/edgecluster"
edgeclusterGrpcContract "github.com/decentralized-cloud/edge-cluster/contract/grpc/go"
commonErrors "github.com/micro-business/go-core/system/errors"
"go.uber.org/zap"
)
type serviceConditionResolverContract struct {
logger *zap.Logger
condition *edgeclusterGrpcContract.ServiceCondition
}
// NewServiceConditionResolver creates new instance of the serviceConditionResolverContract, setting up all dependencies and returns the instance
// ctx: Mandatory. Reference to the context
// logger: Mandatory. Reference to the logger service
// condition: Mandatory. Contains condition information for a service.
// Returns the new instance or error if something goes wrong
func NewServiceConditionResolver(
ctx context.Context,
logger *zap.Logger,
condition *edgeclusterGrpcContract.ServiceCondition) (edgecluster.ServiceConditionResolverContract, error) {
if ctx == nil {
return nil, commonErrors.NewArgumentNilError("ctx", "ctx is required")
}
if logger == nil {
return nil, commonErrors.NewArgumentNilError("logger", "logger is required")
}
if condition == nil {
return nil, commonErrors.NewArgumentNilError("condition", "condition is required")
}
return &serviceConditionResolverContract{
logger: logger,
condition: condition,
}, nil
}
// Type is the type of the condition
// ctx: Mandatory. Reference to the context
// Returns the type of the condition
func (r *serviceConditionResolverContract) Type(ctx context.Context) string {
return edgeclusterGrpcContract.ConditionStatus_name[int32(r.condition.Status)]
}
// Status returns the status of the condition
// ctx: Mandatory. Reference to the context
// Returns the status of the condition
func (r *serviceConditionResolverContract) Status(ctx context.Context) string {
return edgeclusterGrpcContract.ConditionStatus_name[int32(r.condition.Status)]
}
// LastTransitionTime returns the last time the condition transitioned from one status to another
// ctx: Mandatory. Reference to the context
// Returns the last time the condition transitioned from one status to another
func (r *serviceConditionResolverContract) LastTransitionTime(ctx context.Context) string {
return r.condition.LastTransitionTime.AsTime().Format(time.RFC3339)
}
// Reason returns the Unique, one-word, CamelCase reason for the condition's last transition
// ctx: Mandatory. Reference to the context
// Returns the Unique, one-word, CamelCase reason for the condition's last transition
func (r *serviceConditionResolverContract) Reason(ctx context.Context) string {
return r.condition.Reason
}
// Message returns the human-readable message indicating details about last transition
// ctx: Mandatory. Reference to the context
// Returns the human-readable message indicating details about last transition
func (r *serviceConditionResolverContract) Message(ctx context.Context) string {
return r.condition.Message
}