Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ package openfga

import (
"encoding/json"
"fmt"
"net/url"
"strings"
"time"
)

Expand Down Expand Up @@ -341,3 +343,20 @@ func IsWellFormedUri(uriString string) bool {

return true
}

func (o FgaObject) String() string {
return fmt.Sprintf("%s:%s", o.Type, o.Id)
}

func FgaObjectFromString(objectString string) (*FgaObject, error) {
if objectString == "" {
return nil, fmt.Errorf("failed parsing FgaObject, cannot build FgaObject from empty string")
}
objectTokens := strings.Split(objectString, ":")
if len(objectTokens) != 2 {
return nil, fmt.Errorf("failed parsing FgaObject, invalid FgaObject string")
}
objectType := objectTokens[0]
objectId := objectTokens[1]
return NewFgaObject(objectType, objectId), nil
}