/
status.go
46 lines (35 loc) · 829 Bytes
/
status.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
package status
import (
"errors"
"github.com/eiladin/go-simple-startpage/pkg/config"
"github.com/eiladin/go-simple-startpage/pkg/models"
)
var (
ErrNotFound = errors.New("Status not found")
)
type IStatus interface {
Get(string) (*models.Status, error)
}
type repository interface {
GetSite(*models.Site) error
}
// Compile-time proof of interface implementation.
var _ IStatus = (*service)(nil)
type service struct {
repo repository
config *config.Config
}
func New(repo repository, cfg *config.Config) IStatus {
return &service{
repo: repo,
config: cfg,
}
}
func (c *service) Get(name string) (*models.Status, error) {
site := models.Site{Name: name}
if err := c.repo.GetSite(&site); err != nil {
return nil, ErrNotFound
}
res := models.NewStatus(c.config.Timeout, &site)
return &res, nil
}