diff options
author | Michael Muré <batolettre@gmail.com> | 2022-08-24 21:40:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-24 21:40:30 +0200 |
commit | 5c91174a84592b027c1b432a72ebf2974ec0e4c5 (patch) | |
tree | 1306f7f617968e13e6f28eda51417ae8cd2c6c6a /entity/resolver.go | |
parent | ccb71fea57bb17f267f135cb008470615595c5b7 (diff) | |
parent | e1b172aaf0e984791b5af4a64b144339fd4042f6 (diff) | |
download | git-bug-5c91174a84592b027c1b432a72ebf2974ec0e4c5.tar.gz |
Merge pull request #861 from MichaelMure/test-with-unmarshaler
dag: test op serialisation with the unmarshaller, to allow resolving entities
Diffstat (limited to 'entity/resolver.go')
-rw-r--r-- | entity/resolver.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/entity/resolver.go b/entity/resolver.go index d4fe5d3e..b2f831d7 100644 --- a/entity/resolver.go +++ b/entity/resolver.go @@ -72,3 +72,15 @@ type ResolverFunc func(id Id) (Interface, error) func (fn ResolverFunc) Resolve(id Id) (Interface, error) { return fn(id) } + +// MakeResolver create a resolver able to return the given entities. +func MakeResolver(entities ...Interface) Resolver { + return ResolverFunc(func(id Id) (Interface, error) { + for _, entity := range entities { + if entity.Id() == id { + return entity, nil + } + } + return nil, fmt.Errorf("entity not found") + }) +} |