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 Nov 28, 2024
1 parent 6bd5567 commit 764fbd2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions model_fga_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ package openfga

import (
"bytes"
"fmt"
"strings"

"encoding/json"
)
Expand Down Expand Up @@ -105,6 +107,23 @@ func (o FgaObject) MarshalJSON() ([]byte, error) {
return b.Bytes(), nil
}

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
}

type NullableFgaObject struct {
value *FgaObject
isSet bool
Expand Down

0 comments on commit 764fbd2

Please sign in to comment.