-
Notifications
You must be signed in to change notification settings - Fork 6
/
service.go
60 lines (52 loc) · 1.52 KB
/
service.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
57
58
59
60
package api
import (
"fmt"
"github.com/dewey/feedbridge/plugin"
"github.com/dewey/feedbridge/store"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
)
// Service provides access to the functions by the public API
type Service interface {
// ServeFeed serves a feed based on the plugin and format
ServeFeed(format string, plugin string) (string, error)
// ListFeeds lists all available feed plugins
ListFeeds() []string
}
type service struct {
l log.Logger
storageRepository *store.MemRepo
pluginRepository *plugin.MemRepo
}
// NewService initializes a new API service
func NewService(l log.Logger, sr *store.MemRepo, pr *plugin.MemRepo) *service {
return &service{
l: l,
storageRepository: sr,
pluginRepository: pr,
}
}
// ServeFeed returns the generated feed from the store backend
func (s *service) ServeFeed(format string, plugin string) (string, error) {
feed, err := s.storageRepository.Get(fmt.Sprintf("%s_%s", format, plugin))
if err != nil {
level.Error(s.l).Log("msg", err)
return "", err
}
return feed, nil
}
func (s *service) ListFeeds() []plugin.PluginMetadata {
var pp []plugin.PluginMetadata
for _, p := range s.pluginRepository.All() {
pp = append(pp, plugin.PluginMetadata{
Name: p.Info().Name,
Description: p.Info().Description,
TechnicalName: p.Info().TechnicalName,
Image: p.Info().Image,
Author: p.Info().Author,
AuthorURL: p.Info().AuthorURL,
SourceURL: p.Info().SourceURL,
})
}
return pp
}