Skip to content

Commit 53027b2

Browse files
committed
Simplify NewKey code
1 parent 89fd092 commit 53027b2

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

assets/key.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ func NewKey(m map[string]interface{}) (k Key, err errors.ICCError) {
5959
if index != 0 {
6060
keyExists = false
6161
}
62+
} else {
63+
// Get asset type from @key
64+
parts := strings.Split(k["@key"].(string), ":")
65+
if len(parts) < 2 {
66+
err = errors.NewCCError("cannot determine asset type from key", 400)
67+
return
68+
}
69+
k["@assetType"] = parts[0]
6270
}
6371
}
6472

@@ -72,18 +80,6 @@ func NewKey(m map[string]interface{}) (k Key, err errors.ICCError) {
7280
k["@key"] = keyStr
7381
}
7482

75-
// Validate if @assetType exists
76-
_, typeExists := k["@assetType"].(string)
77-
if !typeExists {
78-
// Get asset type from @key
79-
parts := strings.Split(k["@key"].(string), ":")
80-
if len(parts) < 2 {
81-
err = errors.NewCCError("cannot determine asset type from key", 400)
82-
return
83-
}
84-
k["@assetType"] = parts[0]
85-
}
86-
8783
for t := range k {
8884
if t != "@key" && t != "@assetType" {
8985
delete(k, t)

0 commit comments

Comments
 (0)