forked from babyname/fate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfate.go
52 lines (44 loc) · 980 Bytes
/
fate.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 fate
import (
"log/slog"
"github.com/babyname/fate/config"
"github.com/babyname/fate/database"
"github.com/babyname/fate/ent"
"github.com/babyname/fate/model"
)
// Fate ...
type Fate interface {
NewSession() Session
NewSessionWithFilter(f Filter) Session
}
type fateImpl struct {
cfg *config.Config
db *model.Model
}
func (f *fateImpl) NewSessionWithFilter(filter Filter) Session {
return &session{
db: f.db,
chars: make(map[int][]*ent.Character, 128),
filter: filter,
}
}
func (f *fateImpl) NewSession() Session {
return f.NewSessionWithFilter(DefaultFilter())
}
// New creates a new instance of Fate
// @param *config.Config
// @return Fate
// @return error
func New(cfg *config.Config) (Fate, error) {
log = slog.Default().WithGroup("fate")
c := database.New(cfg.Database)
client, err := c.Client()
if err != nil {
return nil, err
}
return &fateImpl{
cfg: cfg,
db: model.New(client),
}, nil
}
var _ Fate = (*fateImpl)(nil)