-
Notifications
You must be signed in to change notification settings - Fork 12
/
runtime.go
52 lines (44 loc) · 1.28 KB
/
runtime.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
package kvstore
import (
app "github.com/casualjim/go-app"
"github.com/casualjim/go-app/tracing"
"github.com/go-openapi/kvstore/persist"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
// NewRuntime creates a new application level runtime that encapsulates the shared services for this application
func NewRuntime(app app.Application) (*Runtime, error) {
db, err := persist.NewGoLevelDBStore(app.Config())
if err != nil {
return nil, err
}
return &Runtime{
db: db,
app: app,
}, nil
}
// Runtime encapsulates the shared services for this application
type Runtime struct {
db persist.Store
app app.Application
}
// DB returns the persistent store
func (r *Runtime) DB() persist.Store {
return r.db
}
// Tracer returns the root tracer, this is typically the only one you need
func (r *Runtime) Tracer() tracing.Tracer {
return r.app.Tracer()
}
// Logger gets the root logger for this application
func (r *Runtime) Logger() logrus.FieldLogger {
return r.app.Logger()
}
// NewLogger creates a new named logger for this application
func (r *Runtime) NewLogger(name string, fields logrus.Fields) logrus.FieldLogger {
return r.app.NewLogger(name, fields)
}
// Config returns the viper config for this application
func (r *Runtime) Config() *viper.Viper {
return r.app.Config()
}