Add extra OnPlace/OnProfile/OnRelationship/OnTombstone functions

This commit is contained in:
Marius Orcsik 2020-11-28 13:39:14 +01:00
parent 7d6b9976bf
commit c64f3ce904
No known key found for this signature in database
GPG key ID: 7970BDC7D4CB2674
4 changed files with 40 additions and 0 deletions

View file

@ -228,3 +228,13 @@ func ToPlace(it Item) (*Place, error) {
}
return nil, fmt.Errorf("unable to convert %q", it.GetType())
}
type withPlaceFn func (*Place) error
func OnPlace(it Item, fn withPlaceFn) error {
ob, err := ToPlace(it)
if err != nil {
return err
}
return fn(ob)
}

View file

@ -196,3 +196,13 @@ func ToProfile(it Item) (*Profile, error) {
}
return nil, fmt.Errorf("unable to convert %q", it.GetType())
}
type withProfileFn func (*Profile) error
func OnProfile(it Item, fn withProfileFn) error {
ob, err := ToProfile(it)
if err != nil {
return err
}
return fn(ob)
}

View file

@ -211,3 +211,13 @@ func ToRelationship(it Item) (*Relationship, error) {
}
return nil, fmt.Errorf("unable to convert %q", it.GetType())
}
type withRelationshipFn func (*Relationship) error
func OnRelationship(it Item, fn withRelationshipFn) error {
ob, err := ToRelationship(it)
if err != nil {
return err
}
return fn(ob)
}

View file

@ -203,3 +203,13 @@ func ToTombstone(it Item) (*Tombstone, error) {
}
return nil, fmt.Errorf("unable to convert %q", it.GetType())
}
type withTombstoneFn func (*Tombstone) error
func OnTombstone(it Item, fn withTombstoneFn) error {
ob, err := ToTombstone(it)
if err != nil {
return err
}
return fn(ob)
}