MCPcopy Create free account
hub / github.com/Permify/permify / Tuple

Function Tuple

pkg/tuple/tuple.go:160–182  ·  view source on GitHub ↗

Tuple parses a tuple string and returns a Tuple object

(tuple string)

Source from the content-addressed store, hash-verified

158
159// Tuple parses a tuple string and returns a Tuple object
160func Tuple(tuple string) (*base.Tuple, error) {
161 s := strings.Split(strings.TrimSpace(tuple), "@") // split tuple string by "@"
162 if len(s) != 2 {
163 return nil, ErrInvalidTuple // return error if number of "@" is not equal to 2
164 }
165 ear, err := EAR(s[0]) // parse entity and relation from the first part of the tuple string
166 if err != nil {
167 return nil, err
168 }
169 sub, err := EAR(s[1]) // parse entity and relation from the second part of the tuple string
170 if err != nil {
171 return nil, err
172 }
173 return &base.Tuple{
174 Entity: ear.Entity,
175 Relation: ear.Relation,
176 Subject: &base.Subject{
177 Type: sub.Entity.Type,
178 Id: sub.Entity.Id,
179 Relation: sub.Relation,
180 },
181 }, nil
182}
183
184// EAR function parses a string to create a base.EntityAndRelation object.
185func EAR(ear string) (*base.EntityAndRelation, error) {

Callers 15

notion_test.goFile · 0.92
usecase_test.goFile · 0.92
RunWithShapeMethod · 0.92
ContextFunction · 0.92
validateFunction · 0.92
ContextFunction · 0.92
OperationFunction · 0.92
watch_test.goFile · 0.92

Calls 1

EARFunction · 0.85

Tested by

no test coverage detected