add mapstructure tags to types,

improve function documentation
This commit is contained in:
2026-05-26 20:22:50 +00:00
parent 48fa4c0613
commit 52ac2c2b97
3 changed files with 83 additions and 75 deletions
+10 -2
View File
@@ -5,15 +5,21 @@ import (
"regexp"
)
// Converts input groupname object to string representation.
// Uses the format gid-realm.
func (g Groupname) ToString() string {
return fmt.Sprintf("%s-%s", g.GroupID, g.Realm)
}
// Converts input username object to string representation.
// Uses the format uid@realm.
func (u Username) ToString() string {
return fmt.Sprintf("%s-%s", u.UserID, u.Realm)
}
// returns an error if the groupname format was not correct
// Parses input groupname string to gid and realm.
// Assumes the format gid-realm or gid if realm is implicitly pve.
// Returns an error if the groupname format was not correct.
func ParseGroupname(groupname string) (Groupname, error) {
g := Groupname{}
// <groupid>-<realm>
@@ -36,7 +42,9 @@ func ParseGroupname(groupname string) (Groupname, error) {
}
}
// returns an error if the username format was not correct
// Parses input username string to uid and realm.
// Assumes the format uid@realm.
// Returns an error if the username format was not correct.
func ParseUsername(username string) (Username, error) {
u := Username{}
m := regexp.MustCompilePOSIX("([[:alnum:]]+)@([[:alnum:]]+)")