Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f681f0bb17 | |||
| 44319d03b9 | |||
| 2f57edd277 | |||
| cf0ee224f7 |
@@ -15,8 +15,6 @@ import (
|
|||||||
var (
|
var (
|
||||||
// MigrateTables holds the tables that need to be auto-migrated on database initialization
|
// MigrateTables holds the tables that need to be auto-migrated on database initialization
|
||||||
MigrateTables []any
|
MigrateTables []any
|
||||||
// Init is an optional initialization function that can be executed after database connection is established
|
|
||||||
Init *func() = nil
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewDatabase creates a new database connection based on the provided driver type
|
// NewDatabase creates a new database connection based on the provided driver type
|
||||||
@@ -36,11 +34,6 @@ func NewDatabase(driver string, dsn []string, options *types.SqlOptions) (db *go
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the Init function if it's not nil
|
|
||||||
if Init != nil {
|
|
||||||
(*Init)()
|
|
||||||
}
|
|
||||||
|
|
||||||
return db, nil
|
return db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ func (s *Service) Gateway(grpcAddr string, httpAddr string) {
|
|||||||
http.ListenAndServe(httpAddr, s.Opts.GatewayMux)
|
http.ListenAndServe(httpAddr, s.Opts.GatewayMux)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) Use(initFunc func() error) {
|
||||||
|
err := (initFunc)()
|
||||||
|
if err != nil {
|
||||||
|
print.Error(err.Error())
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Service) Stop() {
|
func (s *Service) Stop() {
|
||||||
s.GrpcSrv.GracefulStop()
|
s.GrpcSrv.GracefulStop()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user