Tuple parses a tuple string and returns a Tuple object
(tuple string)
| 158 | |
| 159 | // Tuple parses a tuple string and returns a Tuple object |
| 160 | func 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. |
| 185 | func EAR(ear string) (*base.EntityAndRelation, error) { |
no test coverage detected