package gid import ( "net/url" "strings" "github.com/cedar-policy/cedar-go" ) func NewEntityUID(globalID string) cedar.EntityUID { if !strings.HasPrefix(globalID, "gid://") { return DefaultEntityUID(globalID) } url, err := url.Parse(globalID) if err != nil { return DefaultEntityUID(globalID) } items := strings.SplitN(url.Path, "/", 3) if len(items) != 3 { return DefaultEntityUID(globalID) } return cedar.NewEntityUID( cedar.EntityType(items[1]), cedar.String(items[2]), ) } func DefaultEntityUID(id string) cedar.EntityUID { return cedar.NewEntityUID("User", cedar.String(id)) } func ZeroEntityUID() cedar.EntityUID { return cedar.NewEntityUID("", "") }