-
Notifications
You must be signed in to change notification settings - Fork 0
/
id.go
33 lines (27 loc) · 837 Bytes
/
id.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
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package payload
import (
"strings"
)
// TODO(ericsnow) Add ValidateID()?
// TODO(ericsnow) Add a "composite" ID type?
// BuildID composes an ID from a class and an ID.
func BuildID(class, id string) string {
if id == "" {
// TODO(natefinch) remove this special case when we can be sure the ID
// is never empty (and fix the tests).
return class
}
return class + "/" + id
}
// ParseID extracts the payload name and details ID from the provided string.
// The format is expected to be name/pluginID. If no separator is found, the
// whole string is assumed to be the name.
func ParseID(id string) (name, pluginID string) {
parts := strings.SplitN(id, "/", 2)
if len(parts) == 2 {
return parts[0], parts[1]
}
return id, ""
}