types: add Node StringID and UserView accessors

Add StringID() on Node/NodeView and Username/Display/CreatedAt on
UserView, so the HTTP read paths render ids and read users through view
accessors instead of cloning with AsStruct().
This commit is contained in:
Kristoffer Dalby
2026-06-20 20:16:51 +00:00
parent 24dfcf178f
commit 339cb392a9
2 changed files with 48 additions and 0 deletions
+20
View File
@@ -92,6 +92,16 @@ func (id NodeID) String() string {
return strconv.FormatUint(id.Uint64(), util.Base10)
}
// StringID returns the node's id as a decimal string, the form the HTTP APIs
// render it as.
func (node *Node) StringID() string {
if node == nil {
return ""
}
return node.ID.String()
}
func ParseNodeID(s string) (NodeID, error) {
id, err := strconv.ParseUint(s, util.Base10, 64)
return NodeID(id), err
@@ -852,6 +862,16 @@ func (nv NodeView) RequestTagsSlice() views.Slice[string] {
return nv.Hostinfo().RequestTags()
}
// StringID returns the node's id as a decimal string, the form the HTTP APIs
// render it as.
func (nv NodeView) StringID() string {
if !nv.Valid() {
return ""
}
return nv.ID().String()
}
// IsTagged reports if a device is tagged
// and therefore should not be treated as a
// user owned device.