-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_connection_factory.go
43 lines (38 loc) · 1.05 KB
/
handler_connection_factory.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
package server
import (
"github.com/Sirupsen/logrus"
"github.com/julienschmidt/httprouter"
"github.com/ory-am/hydra/config"
"github.com/ory-am/hydra/connection"
"github.com/ory-am/hydra/herodot"
"golang.org/x/net/context"
r "gopkg.in/dancannon/gorethink.v2"
)
func newConnectionHandler(c *config.Config, router *httprouter.Router) *connection.Handler {
ctx := c.Context()
h := &connection.Handler{}
h.H = &herodot.JSON{}
h.W = ctx.Warden
h.SetRoutes(router)
switch con := ctx.Connection.(type) {
case *config.MemoryConnection:
h.Manager = connection.NewMemoryManager()
break
case *config.RethinkDBConnection:
con.CreateTableIfNotExists("hydra_connections")
m := &connection.RethinkManager{
Session: con.GetSession(),
Table: r.Table("hydra_connections"),
Connections: make(map[string]connection.Connection),
}
if err := m.ColdStart(); err != nil {
logrus.Fatalf("Could not fetch initial state: %s", err)
}
m.Watch(context.Background())
h.Manager = m
break
default:
panic("Unknown connection type.")
}
return h
}