2020-10-06 20:54:56 +00:00
|
|
|
package pbservice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// UniqueID returns a unique identifier for this CheckServiceNode, which includes
|
|
|
|
// the node name, service namespace, and service ID.
|
|
|
|
//
|
|
|
|
// The returned ID uses slashes to separate the identifiers, however the node name
|
|
|
|
// may also contain a slash, so it is not possible to parse this identifier to
|
|
|
|
// retrieve its constituent parts.
|
|
|
|
//
|
|
|
|
// This function is similar to structs.UniqueID, however at this time no guarantees
|
|
|
|
// are made that it will remain the same.
|
|
|
|
func (m *CheckServiceNode) UniqueID() string {
|
|
|
|
if m == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
builder := new(strings.Builder)
|
2021-07-22 19:33:22 +00:00
|
|
|
|
|
|
|
switch {
|
|
|
|
case m.Node != nil:
|
|
|
|
builder.WriteString(m.Node.Partition + "/")
|
|
|
|
case m.Service != nil:
|
2022-03-23 16:10:03 +00:00
|
|
|
partition := ""
|
|
|
|
if m.Service.EnterpriseMeta != nil {
|
|
|
|
partition = m.Service.EnterpriseMeta.Partition
|
|
|
|
}
|
|
|
|
builder.WriteString(partition + "/")
|
2021-07-22 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2020-10-06 20:54:56 +00:00
|
|
|
if m.Node != nil {
|
|
|
|
builder.WriteString(m.Node.Node + "/")
|
|
|
|
}
|
|
|
|
if m.Service != nil {
|
2022-03-23 16:10:03 +00:00
|
|
|
namespace := ""
|
|
|
|
if m.Service.EnterpriseMeta != nil {
|
|
|
|
namespace = m.Service.EnterpriseMeta.Namespace
|
|
|
|
}
|
|
|
|
builder.WriteString(namespace + "/")
|
2020-10-06 20:54:56 +00:00
|
|
|
builder.WriteString(m.Service.ID)
|
|
|
|
}
|
|
|
|
return builder.String()
|
|
|
|
}
|