-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.go
51 lines (42 loc) · 1.18 KB
/
dev.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
//go:build !nodev
package sql
import (
"github.com/wrmsr/bane/core/dev"
"github.com/wrmsr/bane/core/dev/docker"
inj "github.com/wrmsr/bane/core/inject"
stru "github.com/wrmsr/bane/core/strings"
bt "github.com/wrmsr/bane/core/types"
sqb "github.com/wrmsr/bane/sql/base"
)
var _ = dev.Register(func() inj.Bindings {
return inj.Bind(
inj.As(inj.KeyOf[bt.Optional[sqb.Dsn]]{"mysql"}, inj.Singleton{func(
dsl *docker.ServiceLocator,
) bt.Optional[sqb.Dsn] {
svc := dsl.Locate("bane-mysql")
if svc == nil {
return bt.None[sqb.Dsn]()
}
return bt.Just(sqb.Dsn{
Host: svc.Host,
Port: svc.Ports[3306],
User: svc.Compose.Environment["MYSQL_USER"],
Pass: stru.SecretOf(svc.Compose.Environment["MYSQL_PASSWORD"]),
})
}}),
inj.As(inj.KeyOf[bt.Optional[sqb.Dsn]]{"postgres"}, inj.Singleton{func(
dsl *docker.ServiceLocator,
) bt.Optional[sqb.Dsn] {
svc := dsl.Locate("bane-postgres")
if svc == nil {
return bt.None[sqb.Dsn]()
}
return bt.Just(sqb.Dsn{
Host: svc.Host,
Port: svc.Ports[5432],
User: svc.Compose.Environment["POSTGRES_USER"],
Pass: stru.SecretOf(svc.Compose.Environment["POSTGRES_PASSWORD"]),
})
}}),
)
})