removed explicit "end" functions and turned them into functions returned by setup
This commit is contained in:
+5
-8
@@ -15,20 +15,17 @@ import (
|
|||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// amdb is the reference to the Amsterdam database.
|
// amdb is the reference to the Amsterdam database. Returns a function to close it down.
|
||||||
var amdb *sqlx.DB
|
var amdb *sqlx.DB
|
||||||
|
|
||||||
// SetupDb sets up the database and associated items.
|
// SetupDb sets up the database and associated items.
|
||||||
func SetupDb() error {
|
func SetupDb() (func(), error) {
|
||||||
db, err := sqlx.Open(config.GlobalConfig.Database.Driver, config.GlobalConfig.Database.Dsn)
|
db, err := sqlx.Open(config.GlobalConfig.Database.Driver, config.GlobalConfig.Database.Dsn)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
amdb = db
|
amdb = db
|
||||||
// TODO: additional initialization
|
// TODO: additional initialization
|
||||||
}
|
}
|
||||||
return err
|
return func() {
|
||||||
}
|
amdb.Close()
|
||||||
|
}, err
|
||||||
// ClosedownDb closes down the database and associated items.
|
|
||||||
func ClosedownDb() {
|
|
||||||
amdb.Close()
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-7
@@ -186,7 +186,7 @@ var sendChan chan *amMessage
|
|||||||
var doneChan chan bool
|
var doneChan chan bool
|
||||||
|
|
||||||
// SetupMailSender starts the mail-sending goroutine.
|
// SetupMailSender starts the mail-sending goroutine.
|
||||||
func SetupMailSender() {
|
func SetupMailSender() func() {
|
||||||
// Initialize mail host and authentication.
|
// Initialize mail host and authentication.
|
||||||
mailHost = fmt.Sprintf("%s:%d", config.GlobalConfig.Email.Host, config.GlobalConfig.Email.Port)
|
mailHost = fmt.Sprintf("%s:%d", config.GlobalConfig.Email.Host, config.GlobalConfig.Email.Port)
|
||||||
switch config.GlobalConfig.Email.AuthType {
|
switch config.GlobalConfig.Email.AuthType {
|
||||||
@@ -211,10 +211,8 @@ func SetupMailSender() {
|
|||||||
sendChan = make(chan *amMessage, 16)
|
sendChan = make(chan *amMessage, 16)
|
||||||
doneChan = make(chan bool)
|
doneChan = make(chan bool)
|
||||||
go senderLoop(sendChan, doneChan)
|
go senderLoop(sendChan, doneChan)
|
||||||
}
|
return func() {
|
||||||
|
close(sendChan) // will break the loop in senderLoop
|
||||||
// EndMailServer shuts down the mail-sending goroutine.
|
<-doneChan // wait for routine to complete
|
||||||
func EndMailServer() {
|
}
|
||||||
close(sendChan) // will break the loop in senderLoop
|
|
||||||
<-doneChan // wait for routine to complete
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,13 +56,13 @@ func setupEcho() *echo.Echo {
|
|||||||
func main() {
|
func main() {
|
||||||
// Configure the system.
|
// Configure the system.
|
||||||
config.SetupConfig()
|
config.SetupConfig()
|
||||||
err := database.SetupDb()
|
closer, err := database.SetupDb()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("Database open failure: %v", err))
|
panic(fmt.Sprintf("Database open failure: %v", err))
|
||||||
}
|
}
|
||||||
defer database.ClosedownDb()
|
defer closer()
|
||||||
email.SetupMailSender()
|
closer = email.SetupMailSender()
|
||||||
defer email.EndMailServer()
|
defer closer()
|
||||||
ui.SetupTemplates()
|
ui.SetupTemplates()
|
||||||
ui.SetupSessionManager()
|
ui.SetupSessionManager()
|
||||||
ui.SetupLeftMenus()
|
ui.SetupLeftMenus()
|
||||||
|
|||||||
Reference in New Issue
Block a user