aboutsummaryrefslogtreecommitdiffstats
path: root/cache/resolvers.go
blob: 9ed2fa4c9d7155e2433a9d354658ade09492d279 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package cache

import (
	"github.com/MichaelMure/git-bug/entity"
)

func makeResolvers(cache *RepoCache) entity.Resolvers {
	return entity.Resolvers{
		&IdentityCache{}: newIdentityCacheResolver(cache),
		&BugCache{}:      newBugCacheResolver(cache),
	}
}

var _ entity.Resolver = &identityCacheResolver{}

// identityCacheResolver is an identity Resolver that retrieve identities from
// the cache
type identityCacheResolver struct {
	cache *RepoCache
}

func newIdentityCacheResolver(cache *RepoCache) *identityCacheResolver {
	return &identityCacheResolver{cache: cache}
}

func (i *identityCacheResolver) Resolve(id entity.Id) (entity.Interface, error) {
	return i.cache.ResolveIdentity(id)
}

var _ entity.Resolver = &bugCacheResolver{}

type bugCacheResolver struct {
	cache *RepoCache
}

func newBugCacheResolver(cache *RepoCache) *bugCacheResolver {
	return &bugCacheResolver{cache: cache}
}

func (b *bugCacheResolver) Resolve(id entity.Id) (entity.Interface, error) {
	return b.cache.ResolveBug(id)
}