Skip to content

Commit

Permalink
feat: quality of life string conversions for FgaObject
Browse files Browse the repository at this point in the history
  • Loading branch information
FedotCompot committed Feb 4, 2025
1 parent b22acef commit 3a2d701
Showing 1 changed file with 19 additions and 0 deletions.
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
}

0 comments on commit 3a2d701

Please sign in to comment.