@@ -7,8 +7,10 @@ import (
7
7
"github.com/powerman/go-service-example/api/openapi/restapi"
8
8
"github.com/powerman/go-service-example/internal/app"
9
9
"github.com/powerman/go-service-example/internal/config"
10
- dal "github.com/powerman/go-service-example/internal/dal/memory"
10
+ dal "github.com/powerman/go-service-example/internal/dal/mysql"
11
+ migrations_mysql "github.com/powerman/go-service-example/internal/migrations/mysql"
11
12
"github.com/powerman/go-service-example/internal/srv/openapi"
13
+ "github.com/powerman/go-service-example/pkg/cobrax"
12
14
"github.com/powerman/go-service-example/pkg/concurrent"
13
15
"github.com/powerman/go-service-example/pkg/def"
14
16
"github.com/powerman/go-service-example/pkg/serve"
@@ -29,14 +31,19 @@ type service struct {
29
31
srv * restapi.Server
30
32
}
31
33
32
- func initService (_ , serveCmd * cobra.Command ) error {
34
+ func initService (cmd , serveCmd * cobra.Command ) error {
33
35
namespace := regexp .MustCompile (`[^a-zA-Z0-9]+` ).ReplaceAllString (def .ProgName , "_" )
34
36
initMetrics (reg , namespace )
37
+ dal .InitMetrics (reg , namespace )
35
38
app .InitMetrics (reg )
36
39
openapi .InitMetrics (reg , namespace )
37
40
41
+ gooseMySQLCmd := cobrax .NewGooseMySQLCmd (migrations_mysql .Goose (), config .GetGooseMySQL )
42
+ cmd .AddCommand (gooseMySQLCmd )
43
+
38
44
return config .Init (config.FlagSets {
39
- Serve : serveCmd .Flags (),
45
+ Serve : serveCmd .Flags (),
46
+ GooseMySQL : gooseMySQLCmd .Flags (),
40
47
})
41
48
}
42
49
@@ -78,7 +85,7 @@ func (s *service) runServe(ctxStartup, ctxShutdown Ctx, shutdown func()) (err er
78
85
}
79
86
80
87
func (s * service ) connectRepo (ctx Ctx ) (interface {}, error ) {
81
- return dal .New (ctx )
88
+ return dal .New (ctx , s . cfg . MySQLGooseDir , s . cfg . MySQL )
82
89
}
83
90
84
91
func (s * service ) serveMetrics (ctx Ctx ) error {
0 commit comments