forked from blocklessnetwork/b7s
/
fstore.go
48 lines (38 loc) · 1.03 KB
/
fstore.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
package fstore
import (
"net/http"
"github.com/cavaliergopher/grab/v3"
"github.com/rs/zerolog"
)
// FStore - function store - deals with all of the function-related actions - saving/reading them from backing storage,
// downloading them, unpacking them etc.
type FStore struct {
log zerolog.Logger
store Store
http *http.Client
downloader *grab.Client
workdir string
}
// New creates a new function store.
func New(log zerolog.Logger, store Store, workdir string) *FStore {
// Create an HTTP client.
cli := http.Client{
Timeout: defaultTimeout,
}
// Create a download client.
downloader := grab.NewClient()
downloader.UserAgent = defaultUserAgent
h := FStore{
log: log.With().Str("component", "fstore").Logger(),
store: store,
http: &cli,
downloader: downloader,
workdir: workdir,
}
return &h
}
// InstalledFunctions will return the CIDs of all functions found in local storage.
func (h *FStore) InstalledFunctions() ([]string, error) {
ids := h.store.Keys()
return ids, nil
}