mirror of
https://github.com/vbatts/imgsrv.git
synced 2025-07-06 00:58:30 +00:00
cleaned up the dbutil initialization
This commit is contained in:
parent
cebd3acc3c
commit
9b2c342375
4 changed files with 86 additions and 39 deletions
15
server.go
15
server.go
|
@ -36,8 +36,17 @@ Run as the file/image server
|
|||
func runServer(c *config.Config) {
|
||||
serverConfig = *c
|
||||
|
||||
initMongo()
|
||||
defer mongo_session.Close()
|
||||
du = dbutil.Util{
|
||||
Seed: serverConfig.MongoHost,
|
||||
User: serverConfig.MongoUsername,
|
||||
Pass: serverConfig.MongoPassword,
|
||||
DbName: serverConfig.MongoDbName,
|
||||
}
|
||||
err := du.Init()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer du.Close() // TODO this ought to catch a signal to cleanup
|
||||
|
||||
http.HandleFunc("/", routeRoot)
|
||||
http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -64,7 +73,7 @@ func initMongo() {
|
|||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
images_db = mongo_session.DB(serverConfig.MongoDB)
|
||||
images_db = mongo_session.DB(serverConfig.MongoDbName)
|
||||
if len(serverConfig.MongoUsername) > 0 && len(serverConfig.MongoPassword) > 0 {
|
||||
err = images_db.Login(serverConfig.MongoUsername, serverConfig.MongoPassword)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue