-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapper.go
56 lines (41 loc) · 1.49 KB
/
wrapper.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package mavencentralapi
import (
"context"
"fmt"
"github.com/a-grasso/deprec/cache"
"github.com/vifraa/gopom"
)
type ClientWrapper struct {
Cache *cache.Cache
Client *Client
}
func NewClientWrapper(client *Client, cache *cache.Cache) *ClientWrapper {
return &ClientWrapper{
Cache: cache,
Client: client,
}
}
func (cw *ClientWrapper) SearchMavenCentralSHA1(sha1 string) (*MavenCentralSearch, error) {
coll := cw.Cache.Database("mavencentral_search_sha").Collection(sha1)
f := func() (*MavenCentralSearch, error) {
reports, err := cw.Client.SearchMavenCentralSHA1(sha1)
return reports, err
}
return cache.FetchSingle[MavenCentralSearch](context.TODO(), coll, f)
}
func (cw *ClientWrapper) GetArtifactPom(groupId, artifactId, version string) (*gopom.Project, error) {
coll := cw.Cache.Database("mavencentral_browse_pom").Collection(fmt.Sprintf("%s-%s-%s", groupId, artifactId, version))
f := func() (*gopom.Project, error) {
reports, err := cw.Client.GetArtifactPom(groupId, artifactId, version)
return reports, err
}
return cache.FetchSingle[gopom.Project](context.TODO(), coll, f)
}
func (cw *ClientWrapper) GetLibraryMetadata(groupId, artifactId string) (*Metadata, error) {
coll := cw.Cache.Database("mavencentral_browse_metadata").Collection(fmt.Sprintf("%s-%s", groupId, artifactId))
f := func() (*Metadata, error) {
reports, err := cw.Client.GetLibraryMetadata(groupId, artifactId)
return reports, err
}
return cache.FetchSingle[Metadata](context.TODO(), coll, f)
}