-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
50 lines (39 loc) · 983 Bytes
/
app.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
package exporter
import (
"context"
"github.com/jinzhu/gorm"
"github.com/rafalmnich/exporter/sink"
)
// Application is the App
type Application interface {
Importer
Exporter
}
// Importer is a data importer
type Importer interface {
Import(ctx context.Context) ([]*sink.Reading, error)
}
// Exporter is a data exporter
type Exporter interface {
Export(ctx context.Context, imp []*sink.Reading) error
}
type App struct {
importer Importer
exporter Exporter
db *gorm.DB
}
func (a App) IsHealthy() error {
return a.db.DB().Ping()
}
// NewApplication creates App
func NewApplication(importer Importer, exporter Exporter, db *gorm.DB) *App {
return &App{importer: importer, exporter: exporter, db: db}
}
// Import imports data
func (a App) Import(ctx context.Context) ([]*sink.Reading, error) {
return a.importer.Import(ctx)
}
// Export exports data
func (a App) Export(ctx context.Context, imp []*sink.Reading) error {
return a.exporter.Export(ctx, imp)
}